woocommerce-gateway-paypal-express-checkout icon indicating copy to clipboard operation
woocommerce-gateway-paypal-express-checkout copied to clipboard

Fix the pricing issue with woo product add-ons ext

Open wigglemuff opened this issue 5 years ago • 1 comments

Summary

Closes #606.

Before PPEC only picked up the price of the last checked add-on in the total price calculation. Now it picks up the prices of all the checked add-ons in the total price.

Steps to test:

  1. Install Woo + PPEC + Woo Product Add-Ons
  2. Set up add-ons by creating a simple product > going to product-data > add-ons > adding a checkbox field with 3 options with different flat prices. Example: https://d.pr/i/dGeblB (also available as a inline screenshot-1 below).
  3. Switch to the master / main branch
  4. Go to the product page (having add-ons), try purchasing the product via PPEC button with 2 checked add-ons.
  5. Current behavior: The total price = main product price + last add-on price. It does NOT include prices for every checked add-on in the total price. Expected behavior: The total should include prices for every checked add-on.
  6. Switch to the branch issue_606
  7. Try purchasing a product via PPEC with 2 checked add-ons.
  8. The total price = main product price + prices of ALL the checked add-ons.

Documentation

This doesn't need documentation. The customer does not see any change.

Tests for PPEC

  • [x] Checkout a single product with no add-ons
  • [x] Checkout a single product with add-ons, by selecting at least 2 or more add-ons (expected behavior: total price = main product price + price of each checked add-on).
  • [x] Checkout from cart page
  • [x] Checkout from checkout page

Screenshot

Screenshot-1 Screenshot 2020-06-25 at 4 47 58 PM

Questions

Previously the data sent to PayPal only contained one add-on item (example: c) even when the checked items were more (example: b and c).

Screenshot 2020-06-25 at 4 18 00 PM

In this PR, I have made the field name's unique, such that each checked item is included in the data sent to PayPal. Is this the correct approach?

Closes #606.

wigglemuff avatar Jun 25 '20 12:06 wigglemuff

Revisions

https://github.com/woocommerce/woocommerce-gateway-paypal-express-checkout/pull/780/commits/cb0a78ee19bbb4f9052445d7c5fc523a8f1b84e7 fixes both these issues:

Based on the bug report, there are 2 problems that needs to be fixed. (a) Multi-option check boxes uses only the last checked option value when passed to PayPal (b) File field type values not passed to PayPal

Manual Tests

  • [x] Variable Product
    • [x] Buy a variable product with no add-ons
    • [x] Buy a variable product with two checked add-ons
    • [x] Buy a variable product with following woo-add-on fields: quantity, customer defined price, file upload
  • [x] Simple Product
    • [x] Same tests as above for simple product

Debugging

To debug, insert the code below on line 118:

for (var key of formData.entries()) {
    console.log(key);
}

The Magic

This fixes all the issues because each key is unique in formData:

Screenshot 2020-06-26 at 7 14 10 PM

wigglemuff avatar Jun 26 '20 14:06 wigglemuff