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

Fix incorrect quantity when product is already in cart #421

Merged
merged 4 commits into from
May 14, 2024

Conversation

martynmjones
Copy link
Contributor

@martynmjones martynmjones commented May 13, 2024

Changes proposed in this Pull Request:

Closes #391

Adjusts the utility to retrieve a product by its ID to prioritise the product data object over the cart object. This is to prevent the existing cart quantity from being sent with an add_to_cart event.

Additionally, the function to format product data is updated to pass along the quantity on the added_to_cart event.

Detailed test instructions:

  1. Checkout fix/391-incorrect-product-quantity and build the extension
  2. Go to the shop archive
  3. Add a simple product to the cart multiple times
  4. Refresh the page
  5. Add the same product to the cart and confirm that the event sent has the correct quantity of 1
  6. Go to the single product page
  7. Set the quantity 4 and add it to cart
  8. Confirm the quantity sent in the event is 4

Changelog entry

Fix - Incorrect quantity value when adding product to the cart that exists in the cart

@martynmjones martynmjones self-assigned this May 13, 2024
@github-actions github-actions bot added changelog: fix Took care of something that wasn't working. type: bug The issue/PR is a confirmed bug. labels May 13, 2024
@martynmjones martynmjones requested a review from a team May 13, 2024 16:02
@martynmjones martynmjones marked this pull request as ready for review May 13, 2024 16:02
Copy link
Member

@ianlin ianlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing it @martynmjones. I tested both block and classic shops and it worked as expected. I'm approving this but just left a comment regarding the E2E test.

const addToCart = `.single_add_to_cart_button[value="${ simpleProductID }"]`;
const addToCartButton = await page.locator( addToCart ).first();

await addToCartButton.click();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ What do you think adding a page.reload() for the classic shop as well so it would match the testing instruction in the PR description?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @ianlin 🙌

The error with the product quantity on the single page wasn't triggered with a page reload in the same way the other one was. When the added_to_cart hook runs the quantity wasn't being added to the product object so for the test we just need to click the Add to cart button and then confirm the quantity is now present in the event. Apologies if that wasn't clear from the testing instructions.

@martynmjones martynmjones merged commit 7132db0 into trunk May 14, 2024
7 checks passed
@martynmjones martynmjones deleted the fix/391-incorrect-product-quantity branch May 14, 2024 12:55
@puntope puntope mentioned this pull request May 14, 2024
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: fix Took care of something that wasn't working. type: bug The issue/PR is a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cart quantity can be inconsistent
2 participants