i’m trying to create Google Shopping Feed, i have a dataset with a row for each product in store (with a related field call “prodotto”) where i add the other information required by google (such as google_product_cathegory, size, … etc).
I need to parse all products to create the XML Feed, I have an other http function accessible from link https://<domain.it>/_functions/feed_google to get the public XML feed
I try your code but not works. This is the complete code:
import {js2xml} from 'xml-js';
import wixData from 'wix-data';
export function getFeedGoogle() {
let listing = [];
let allProducts=getAllItems();
console.log("----------LOG 0");
console.log(allProducts);
if(allProducts[0] > 0) {
for(let i = 0; i < allProducts[0] ; i++) { //i have to use array with products and size because allProducts.lenght not works
let item = allProducts[1][i]
let disponibilita="out_of_stock"
if (item.prodotto.inStock)
disponibilita="in_stock"
let spedizione="";
if (item.prodotto.discountedPrice<30)
spedizione="IT:::10.00";
listing.push({
"g:id": item.prodotto.sku,
"g:availability": disponibilita,
"g:price": String(item.prodotto.price.toFixed(2)) + " EUR",
"g:title": item.prodotto.name,
"g:description":"<![CDATA["+item.prodotto.description.replace(/(<([^>]+)>)/ig, "").replace(/(’)/ig, "'").replace(/\r?\n/g,"")+"]]>",
"g:link": "https://www.comete.it"+item.prodotto.productPageUrl,
"g:condition":"new",
"g:image_link": getFullImageURL(item.prodotto.mainMedia),
"g:brand": "Comete Gioielli",
"g:sale_price": String(item.prodotto.discountedPrice.toFixed(2)) + " EUR",
"g:shipping": spedizione,
"g:google_product_category":item.categoriaProdottiGoogle,
"g:custom_label_4":"<![CDATA["+ item.etichettaPersonalizzata4+"]]>",
"g:gender":item.gender,
"g:material":"<![CDATA["+item.material+"]]>",
"g:product_type":"<![CDATA["+item.productType+"]]>"
});
console.log("----------LOG 1 "+i);
}
console.log("----------LOG 2");
}
console.log("----------PRODUCT LIST:");
console.log(listing);
return js2xml({"item": listing} , { compact: true });
}
function getAllItems(){
return wixData.query("ProdottiEspansi")
.limit(1000)
.isNotEmpty("prodotto")
.include("prodotto")
.find()
.then(async res => {
let size=res.length;
let items = res.items; //i need the total size
while (res.hasNext()) {
res = await res.next();
size+=res.length;
items = items.concat(res.items);
}
return [size, items];
})
.catch(err => err)
}
function getFullImageURL(imageSRC) {
let strReturnImage = "";
if (imageSRC.startsWith("wix:image:")) {
let wixImageURL = "";
wixImageURL = "https://static.wixstatic.com/media/";
let wixLocalURL = "";
wixLocalURL = imageSRC.replace('wix:image://v1/', '');
wixLocalURL = wixLocalURL.substr(0, wixLocalURL.lastIndexOf('/'));
strReturnImage = wixImageURL + wixLocalURL;
} else {
strReturnImage = imageSRC;
}
return strReturnImage;
}
But not works: this is the result:
Has you see your code (getAllItems) not work because return an empty array