I have changed “add to cart” button to “request a quote” with a relevant light box opening at that time. The form auto fills the product name, however I cant get it to auto fill the product size selected from the drop down in items that have multiple sizes.
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';
let product;$w.onReady(function () {
initProductPage();
});
wixLocation.onChange((location) => {
let newPath = location.path;
if (newPath?.[0] === 'product-page') {
initProductPage();
}
});
async function initProductPage() {
product = await $w('#productPage1').getProduct();
$w('#productPage1').setAddToCartLabel('Request a quote / Solicitar una cotización');
$w('#productPage1').onAddToCart(onAddToCartHandler);
}async function onAddToCartHandler(resume, cancel) {
const data = await getSelectedProductData();
wixWindow.openLightbox('RFQ', data)
.then(() => {
cancel();
});
}
async function getSelectedProductData() {
const productQuantity = await $w('#productPage1').getQuantity();
const productChoices = await $w('#productPage1').getSelectedChoices();
const productCustomText = await $w('#productPage1').getCustomText();
// Extract the size from the productChoices object
const productSize = productChoices.size;
return {
product: product,
quantity: productQuantity,
size: productSize, // Pass the size to the lightbox
choices: productChoices,
customTextFields: productCustomText,
}
}
and then the light box has
import wixWindow from 'wix-window';
const context = wixWindow.lightbox.getContext();
console.log('context', context);
$w.onReady(() => {
$w('#input6').value = context.product.name;
$w('#input7').value = context.product.size;
});
The option is labelled “size” in the product catalogue… does any one have any idea why this would not be working? Thank you.