Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
UrosJeknic opened this issue Nov 22, 2024 · 7 comments

Comments

@UrosJeknic
Copy link

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
Copy link
Member

paales commented Nov 22, 2024

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: #2381)

@UrosJeknic
Copy link
Author

UrosJeknic commented Nov 22, 2024

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

@paales
Copy link
Member

paales commented Nov 25, 2024

@UrosJeknic Do you see a console warning where Apollo Client is mentioning data loss?

@UrosJeknic
Copy link
Author

Nope. It's not logging anything to the console

@paales
Copy link
Member

paales commented Nov 25, 2024

Can we reproduce it on the demo?

  1. Go to: https://graphcommerce.vercel.app/p/fluffy-cakes-gc-1107-sock
  2. Add the '36-40' product to the cart.
  3. Increment the quantity of the item in the cart.
  4. With quantity 4 we see 'Three of a Kind' applied.
  5. With quantity 6 we see an addtional 'Work on that sixpack' applied
  6. Reducing the quantities will remove the discounts.

Am I missing something in my steps?

The demo is running 8.0.8, but those releases should not contain anything related to that: 8.0.8 and 8.0.7

@UrosJeknic
Copy link
Author

I can't reproduce it in the demo. I patched a couple of node modules files so maybe there's a line of code i changed that may be causing this issue, but I don't remember changing anything that could. I'll take a look. Thanks for the help

@paales
Copy link
Member

paales commented Nov 25, 2024

Hope you get it resolved on your side :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants