Why does the 'buy together' feature add the wrong product to the cart?

Why does the 'buy together' feature add the wrong product to the cart?

Manita112
Shopify Partner
8 0 0

Hey,

i have a issue with the Product Form -> add to Cart.

i added a "buy together" feature in my store, this feature works and add only the selected products to cart.

Now i have the issue that if this peace of code is under the variant selector from the main product, it will add the last item from the feature to cart. 

When i move it over the selector it works fine. Now i was thinking he select the wrong item because of the form request, but i have logged the event "add to cart" and in this event is the right variant and before the request is send is still the right product. I dont understand whats happen in the background to change the variation, is this a bug or do i need to create my own request like in my feature?

 

This feature is actually only in one product active

 

https://store8.de/products/galaxy-guardian?variant=44306802999593

 

 

King Regards 

Jamie 

Bildschirmfoto 2023-02-19 um 02.54.39.pngBildschirmfoto 2023-02-19 um 02.56.54.pngBildschirmfoto 2023-02-19 um 02.58.50.pngBildschirmfoto 2023-02-19 um 03.00.31.pngBildschirmfoto 2023-02-19 um 03.02.42.pngBildschirmfoto 2023-02-19 um 03.02.57.pngBildschirmfoto 2023-02-19 um 03.06.19.png

Replies 7 (7)

gr_trading
Shopify Partner
2030 148 205

@Manita112 ,

 

Your code seems to be very neat and clear, so as per my understanding movement of code block should not affect the working. Can you share a URL where I can check the same?

For any custom development WhatsApp or connect at Email ID: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
Manita112
Shopify Partner
8 0 0

Hey @gr_trading ,

 

sure here are two products, one before the main selection and one after:

before:

https://store8.de/products/galaxy-guardian

 

after:

https://store8.de/products/reliefer-2-0

 

The events are also in the console.

 

Thank you

 

gr_trading
Shopify Partner
2030 148 205

@Manita112 

 

it's working fine on my end. 

 

hari1_prasad_0-1676797333059.png

 

For any custom development WhatsApp or connect at Email ID: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
Manita112
Shopify Partner
8 0 0

@gr_trading 

 

This works without issues, you need to buy the main product and then you will see. He takes the last one of the feature when the form is after the main product selection.

gr_trading
Shopify Partner
2030 148 205

Put your frequently-bought-together section after closing the product form tag.

For any custom development WhatsApp or connect at Email ID: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
Manita112
Shopify Partner
8 0 0

You are right, there are multiple solutions, i can implement my own add to cart action and prevent this usecase, but i need to understand what happens because the right product is in the request. Something in the /add/cart endpoint must happen, a recheck or something like that. Like i said before, i was thinking the same, he get the wrong product because it is in the form, but he takes the right one and this is my problem what i dont understand.

Manita112
Shopify Partner
8 0 0

I have found the issue, sometimes we should look on all variables, in the request is the whole form sended and your "add-to-cart" route is taken the last selected product. Maybe here should be something integrated and look if its the main product or something else. I have change the request and send only the "currentVariant" and not the whole form.

Anyway its resolved, but maybe some of your devs can look over this route and prevent something like this.

 

Bildschirmfoto 2023-02-19 um 21.52.53.png

Bildschirmfoto 2023-02-19 um 21.59.53.png