Skip out-of-stock products in XML generation: Added logic to exclude products that are not available from the generated XML, improving the accuracy of product listings for SEO purposes.
This commit is contained in:
@@ -414,6 +414,12 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
|
|||||||
// Generate availability
|
// Generate availability
|
||||||
const availability = product.available ? "in stock" : "out of stock";
|
const availability = product.available ? "in stock" : "out of stock";
|
||||||
|
|
||||||
|
// Skip products that are out of stock
|
||||||
|
if (!product.available) {
|
||||||
|
skippedCount++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Generate price (ensure it's a valid number)
|
// Generate price (ensure it's a valid number)
|
||||||
const price = product.price && !isNaN(product.price)
|
const price = product.price && !isNaN(product.price)
|
||||||
? `${parseFloat(product.price).toFixed(2)} ${config.currency}`
|
? `${parseFloat(product.price).toFixed(2)} ${config.currency}`
|
||||||
|
|||||||
Reference in New Issue
Block a user