medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
26.25k stars 2.67k forks source link

Items in Cart is wipe out when change Sales Channel #5967

Closed khoasting closed 11 months ago

khoasting commented 11 months ago

Bug report

Describe the bug

I has 2 channels is set up like below:

Channel 1 product A product B

Channel 2 product A

Cart is set with Channel 1 with 2 line item line 1 product A x1 line 2 product B x1

Then Cart is change to Channel 2

The onSalesChannelChange in cart will remove the line 2 product B x1 because it not belong to Channel 2. I expect cart should have line item with product A x1 but it is removed also The line item in cart is empty, i see the code of cart service, return cart with no relations with "item.variants" at line below https://github.com/medusajs/medusa/blob/76332ca6c153a786acc07d3f06ff45c3b9346fd3/packages/medusa/src/services/cart.ts#L622

then the result is set to cart.items at line

https://github.com/medusajs/medusa/blob/76332ca6c153a786acc07d3f06ff45c3b9346fd3/packages/medusa/src/services/cart.ts#L1426C1-L1433C6

that is why the items of cart is wipe out when change sales channel. please help me with this thanks

System information

Medusa version (including plugins): 1.12.3 Node.js version: v18.16.0 Database: postgres Operating system: ubuntu wsl Browser (if relevant):

Expected behavior

Cart.items should be set with correct product , not wipe out all product

adrien2p commented 11 months ago

I ll have a look at this thanks for reporting

adrien2p commented 11 months ago

I ll start looking at this one now 👍

adrien2p commented 11 months ago

This should be good https://github.com/medusajs/medusa/pull/5980, I ll generate a snapshot that you can test as well if you want

khoasting commented 11 months ago

The changes is good, thanks @adrien2p for the help. Cheers.