Can I mimic the Add to Cart Button?

Hi,

I’m looking to use dynamic pages to create my own product pages, rather than use the Wix Stores product pages, for better customisation. One problem I’m facing is that my products have multiple variants (e.g. [Sleeves: Blue, Red, Yellow], then [Collar: Blue, Red], then [Fabric: Cotton, Wool]).

I was able to create a button that adds the ‘current’ product to cart, but I run into the error of the product’s variants not having been selected.

export function button7_click(event) {
const productId = $w( ‘#dynamicDataset’ ).getCurrentItem()._id;
$w( ‘#shoppingCartIcon1’ ).addToCart(productId)
.then( () => {
console.log( “Product added” );
} )
. catch ( (error) => {
console.log(error);
})

Ideally, I’d like to solve this by having the usual pop-up window that allows you to select variants pop up - this usually occurs when you click on the Wix Stores Add to Cart button.

Anyone know if this is possible to mimic using code? Thanks!