wixSearch.Search for Wix Stores variants, repeater, and dynamic page Item

Hi all, we’ve built our store with Wix Stores app. We are using a the Dynamic List page and the Dynamic Item page, connected to the Products collection and to our own Custom collection. The buyer clicks on an item from the List dynamic page repeater, and is taken to the Dynamic Item page to add to cart.

Each of our products has two variants. We are using getCurrentItem on the Item page with our custom collection dataset to identify the product on the page. We see the log show the item.

We use the name from the item object to look up the product id in the Products collection, using wixSearch.Search on the “Stores/Products” document.

We use addToCart () with the product ID when the buyer clicks our custom add to cart button (we are not using Wix Stores Add to cart button) There are no errors in the browser console, and the verbose debug messages say the item is added to the cart. But when the cart opens, it is empty.

Here is the current code:

//-------------Imports-------------//

import wixWindow from ‘wix-window’ ;
import wixSearch from ‘wix-search’ ;

//-------------Global Variables-------------//

// Chosen format.
const format = ‘Digital’ ;
// Map of product data.
let productsMap = {};

$w . onReady ( function () {

$w ( "#worksDataset" ). onReady (() => { 
// Set the action that occurs when a user clicks the "Add to Cart" button for the current item. 
$w ( '#cartButton' ). onClick (() => { 
    console . log ( "clicked" ); 
    // Create a product object for the cart 
        **let**  itemObj  =  $w ( "#worksDataset" ). getCurrentItem (); 
        **let**  name  =  itemObj . title ; 
        console . log ( "work "  +  itemObj  +  " name "  +  name ); 
        // Find this object in the store 
        wixSearch . search ( name ) 
            . documentType ( "Stores/Products" ) 
            . find () 
            . then (( results ) => { 
                **if**  ( results . documents . length  >  0 ){ 
                // handle the results 
                **let**  searchRes  =  results . documents [ 0 ]; 
                **let**  productId  =  searchRes . _id ; 
                // Add the current product to the shopping cart with the selected color. 
                $w ( "#shoppingCartIcon1" ). addToCart ( productId ,  1 ) 
                    . then (() =>  console . log ( 'added!' )) 
                    . **catch** ( console . error ); 
                } 
                **else**  { 
                    console . log ( "No product found!" ) 
                } 
        }) 
        . **catch** ( ( error ) => { 
                console . log ( error ); 
        }); 
    }); 
}); 

});

Here is a screen shot after clicking Add to cart to help you understand:

You can see in the browser console the logging of the item returned from getCurrentItem. I can’t tell which variant of the product it is.
After adding to cart, the WIx Store declares it has been added without more errors indicated (we are at Verbose logging)

Any suggestions about how to debug further?
I’m not sure how to determin which variant the user has selected, since we don’t have a UI to let them choose between.