woocommerce-gateway-paypal-express-checkout
woocommerce-gateway-paypal-express-checkout copied to clipboard
Fix the pricing issue with woo product add-ons ext
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:
- Install Woo + PPEC + Woo Product Add-Ons
- 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).
- Switch to the master / main branch
- Go to the product page (having add-ons), try purchasing the product via PPEC button with 2 checked add-ons.
- 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.
- Switch to the branch issue_606
- Try purchasing a product via PPEC with 2 checked add-ons.
- 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

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).
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.
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: