graphcommerce-org / graphcommerce

GraphCommerce® is a headless storefront replacement for Magento 2 (PWA), that delivers a faster, better user experience. Fully customizable (React, Next.js) and open-source.
https://www.graphcommerce.org
Other
306 stars 71 forks source link

Discount disappears from GetCartTotals query after updating quantity of items in cart using the UpdateItemQuantity button #2426

Open UrosJeknic opened 2 days ago

UrosJeknic commented 2 days ago

Describe the Bug

After updating quantity using the UpdateItemQuantity button it mutates the discounts property from cart.prices

Expected Behavior

It shouldn't mutate the discount unless the condition isn't being met anymore.

I'm guessing the CartItemCountChanged fragment that's being injected into in the CartTotals fragment is causing the bug because after removing the decorators from the CartTotals.graphql file the discounts only disappear after a condition isn't being met anymore (e.g 4 same items in cart)

To Reproduce

Be sure to have an item that has a [conditional] discount in your cart. Go to /cart. Click on the UpdateItemQuantity button to change the quantity of one of your items. After doing that the discount should disappear regardless if it's condition is being met or not.

paales commented 2 days ago

Is this Magento's fault? Is Magento removing te coupon or is GraphCommerce incorrectly removing the coupon?

(There is some discussion here, not sure if it is related: https://github.com/graphcommerce-org/graphcommerce/issues/2381)

UrosJeknic commented 2 days ago

It's not a coupon it's a discount that's being applied to an item if a certain quantity is added to cart if that helps.

I should mention I've tried using the same query and mutation inside Postman (without the @injectable and @inject decorators obviously) and the query returns the discount when the condition is met even after running the mutation, but in my application that has decorators it doesn't, so the problem definitely derives from the decorators.

Once i removed the CartItemCountChanged string from the @inject(into: ["CartItemCountChanged", "PaymentMethodUpdated"]) array inside the CartTotals fragment it worked.

My guess is once I run the updateCartItems mutation in the UpdateItemQuantity.graphql file it's spreading CartItemCountChanged in the results which is affecting what CartTotals returns once it runs in the CartTotals.tsx file because of the @inject decorator i mentioned in the previous paragraph.

I also forgot to mention I'm also using an earlier version of Graphcommerce (8.0.6) if that helps as well.

I created this issue because I don't know what might break if I remove the CartItemCountChanged string from the @inject into array

I checked out the issue you linked and it isn't related to mine sadly