I have built a page using the print on demand example but when i try to run the code I am getting the following error message
typeerror cannot read property ‘productOptions’ of undefined
can anyone please help find where i have gone wrong
the error message is coming from line 3
then further error messages are produced for where ever the “#bgColor”
appears in the code
I have included the 1st section of to code to show where the error messages are coming from
thanks in advance for any help you can provide
export function dynamicDataset_ready() {
const currentProduct = $w("#dynamicDataset").getCurrentItem().product;
const productOptions = currentProduct.productOptions;
$w('#bgColorRepeater').data = createColorRepeaterData('bgcolor', productOptions['Background Color'].choices);
$w('#textColorRepeater').data = createColorRepeaterData('textcolor', productOptions['Text Color'].choices);
}
function createColorRepeaterData(idPrefix, choices) {
return choices.map((item, index) => {
item._id = `${idPrefix}-${index}`;
return item;
});
}
export function bgColorRepeater_itemReady($w, itemData, index) {
$w('#bgColorBox').style.backgroundColor = itemData.value;
$w('#bgColorBtn').onClick(() => {
updateBackgroundColor(itemData);
});
}
export function textColorRepeater_itemReady($w, itemData, index) {
$w('#textColorBox').style.backgroundColor = itemData.value;
$w('#textColorBtn').onClick(() => {
updateTextColor(itemData);
});
}
function updateBackgroundColor(colorItem) {
$w('#colorText').text = colorItem.description;
$w("#bgColor").style.backgroundColor = colorItem.value;
}
Did you open up the Wix example in your own Wix Editor to look at it all made up with the code too?
If you did, then you will notice that the ‘CustomProducts dataset’ has two products in it, so does the dataset that you have created on your page have anything in it or is it empty?
Make sure that your repeaters have items in them too and that they are not empty as well.
Also, make sure that you have added all the functions that are mentioned in the code into the properties panel for the required elements too.
Thanks for the reply , I have dble checked all the things you suggested . The only difference I have is my dataset has only 1 product in it . I can see that this is where the error is occurring but not sure how to fix it
Iwas planning to only have the 1 product on this page but reusing the same code on other pages.
Thanks again for any further advice or help you can give
Fred
@bigfredforbes
Having had the chance to open the Corvid example myself and look into this.
Did you publish the tutorial and refresh the browser so that Wix Stores collections appear in your Site Structure?
https://www.wix.com/corvid/example/print-on-demand
Next Steps
-
Open this example in the Editor to work with the template.
-
Publish the site and refresh your browser so the Stores collections appear in the Database.
As the product options for the bg colour are stored in the Wix Stores Products collection under the field name of Product Options.
So you need to make sure that you have the Product Options field setup to match the tutorial in your own Wix Stores Products collection.
Hi there, I’m trying to use it but can’t get the colors of the background to work, how do I connect them ?
also the image upload won’t work either