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

Updated WooPayments MultiCurrency integration with Product Add-Ons #9070

Merged
merged 14 commits into from
Jul 29, 2024

Conversation

jimjasson
Copy link
Contributor

Fixes #8911

Changes proposed in this Pull Request

This PR updates the integration between WooPayments MultiCurrency and Product Add-Ons which hasn't been reviewed after the Product Add-Ons v6.x.x releases.

One of the major changes in the newer Product Add-Ons versions is that the way add-on prices show up in the cart has changed. Add-on prices are no longer added after the add-on name, but are added after the add-on's value. Moreover, Product Add-Ons has simplified how flat fee prices show up in the cart to make it more evident to shoppers how the cart total is calculated.

Therefore, this PR:

  • updates the WooPayments MultiCurrency/Product Add-Ons integration, so MultiCurrency converts and displays add-on prices in the right location and;
  • resolves an issue that made the product price in the cart change when the cart item quantity was increased.

Testing instructions

First, set up a MultiCurrency environment:

  • Use WooPayments trunk or the latest stable version.
  • Set up WooPayments for your store.
  • Under Payments > Settings, enable MultiCurrency functionality.
  • Under WooCommerce > Settings > Multi-Currency add a couple of currencies that do not have a 1:1 conversion rate, like USD and GBP.
  • In the same screen, enable "Add a currency switcher to the Storefront theme on breadcrumb section.".

Now, let's see some bugs:

  • Install Product Add-Ons v6.9.0.
  • Create a Simple Product.
  • Go to Product Data > Add-Ons.
  • Create a 'Checkboxes' add-on.
  • Add 4 options, A, B, C, D.
  • A should have a $0 Flat Fee.
  • B should have a non-$0 Flat Fee.
  • C should have a non-$0 Quantity Based Price.
  • D should have a non-$0 Percentage Based Price.
  • View the product and select A. Add it to the cart.
  • In the cart, notice that the Flat Fee is added to the name of the add-on and is displayed as $0.00.
  • Back to the single product page, select either B or D. Add the product to the cart.
  • In the cart, change the currency.
  • Then, increase the quantity -- notice that the product price, which represents the price of the single unit, changes (this doesn't happen for products without add-ons).

Finally, let's see some fixes:

  • Grab: https://github.com/woocommerce/woocommerce-product-addons/pull/1048.
  • For WooPayments, check out this branch.
  • Clear your cart and revisit the product you created.
  • Select A and add it to the cart.
  • In the cart, the $0.00 should not be visible.
  • Back to the single product page, select B. Add the product to the cart.
  • In the cart, notice that B's price shows up after the add-on value, like so (+$xx).
  • Change the currency and notice that B's price is converted.
  • Increase the product quantity and ensure that the product price doesn't change.
  • Complete the order.
  • In WooCommerce > Orders find the order you submitted -- ensure that B's price shows up correctly there.
  • By default, quantity and percentage based prices do not show up in the cart. To make them show up to confirm that they are correct use these snippets.
  • Back to the product page, add the product to the cart once with C and once with D selected.
  • Ensure that the prices in the cart are correct, even when changing the currency.
  • Ensure that both the product price and the add-on prices are correct when increasing the product quantity.
  • Complete the order.
  • In WooCommerce > Orders find the order you submitted -- ensure that C's and D's price show up correctly there.

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@jimjasson jimjasson self-assigned this Jul 9, 2024
@botwoo
Copy link
Collaborator

botwoo commented Jul 9, 2024

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 9070 or branch name issue-8911 in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: 7677ad0
  • Build time: 2024-07-17 12:18:41 UTC

Note: the build is updated when a new commit is pushed to this PR.

Copy link
Contributor

github-actions bot commented Jul 9, 2024

Size Change: +9.7 kB (+1%)

Total Size: 1.28 MB

Filename Size Change
release/woocommerce-payments/dist/blocks-checkout.js 60.9 kB +7.9 kB (+15%) ⚠️
release/woocommerce-payments/dist/express-checkout-rtl.css 219 B +65 B (+42%) 🚨
release/woocommerce-payments/dist/express-checkout.css 219 B +65 B (+42%) 🚨
release/woocommerce-payments/dist/express-checkout.js 6.31 kB +621 B (+11%) ⚠️
release/woocommerce-payments/dist/index-rtl.css 41.1 kB +69 B (0%)
release/woocommerce-payments/dist/index.css 41 kB +72 B (0%)
release/woocommerce-payments/dist/index.js 295 kB +22 B (0%)
release/woocommerce-payments/dist/multi-currency-switcher-block.js 59.9 kB +16 B (0%)
release/woocommerce-payments/dist/multi-currency.js 55 kB +15 B (0%)
release/woocommerce-payments/dist/order.js 42 kB +11 B (0%)
release/woocommerce-payments/dist/payment-gateways.js 38.9 kB +17 B (0%)
release/woocommerce-payments/dist/payment-request-rtl.css 219 B +65 B (+42%) 🚨
release/woocommerce-payments/dist/payment-request.css 219 B +65 B (+42%) 🚨
release/woocommerce-payments/dist/settings-rtl.css 11.2 kB +3 B (0%)
release/woocommerce-payments/dist/settings.css 11.1 kB +4 B (0%)
release/woocommerce-payments/dist/settings.js 215 kB +429 B (0%)
release/woocommerce-payments/dist/tokenized-payment-request-rtl.css 219 B +65 B (+42%) 🚨
release/woocommerce-payments/dist/tokenized-payment-request.css 219 B +65 B (+42%) 🚨
release/woocommerce-payments/dist/woopay-express-button-rtl.css 219 B +65 B (+42%) 🚨
release/woocommerce-payments/dist/woopay-express-button.css 219 B +65 B (+42%) 🚨
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.08 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.08 kB
release/woocommerce-payments/assets/css/success.css 173 B
release/woocommerce-payments/assets/css/success.rtl.css 173 B
release/woocommerce-payments/dist/blocks-checkout-rtl.css 2.08 kB
release/woocommerce-payments/dist/blocks-checkout.css 2.08 kB
release/woocommerce-payments/dist/bnpl-announcement-rtl.css 528 B
release/woocommerce-payments/dist/bnpl-announcement.css 529 B
release/woocommerce-payments/dist/bnpl-announcement.js 20.1 kB
release/woocommerce-payments/dist/cart-block.js 15.4 kB
release/woocommerce-payments/dist/cart.js 4.87 kB
release/woocommerce-payments/dist/checkout-rtl.css 600 B
release/woocommerce-payments/dist/checkout.css 600 B
release/woocommerce-payments/dist/checkout.js 31.7 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.05 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 3.41 kB
release/woocommerce-payments/dist/multi-currency.css 3.41 kB
release/woocommerce-payments/dist/order-rtl.css 730 B
release/woocommerce-payments/dist/order.css 730 B
release/woocommerce-payments/dist/payment-gateways-rtl.css 1.35 kB
release/woocommerce-payments/dist/payment-gateways.css 1.35 kB
release/woocommerce-payments/dist/payment-request.js 5.9 kB
release/woocommerce-payments/dist/plugins-page-rtl.css 386 B
release/woocommerce-payments/dist/plugins-page.css 386 B
release/woocommerce-payments/dist/plugins-page.js 19.4 kB
release/woocommerce-payments/dist/product-details-rtl.css 397 B
release/woocommerce-payments/dist/product-details.css 398 B
release/woocommerce-payments/dist/product-details.js 11.2 kB
release/woocommerce-payments/dist/subscription-edit-page.js 668 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 19.5 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 694 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 18.6 kB
release/woocommerce-payments/dist/tokenized-payment-request.js 6.62 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 235 B
release/woocommerce-payments/dist/tos.js 21 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 5.25 kB
release/woocommerce-payments/dist/woopay-express-button.js 15.6 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.26 kB
release/woocommerce-payments/dist/woopay.css 4.23 kB
release/woocommerce-payments/dist/woopay.js 69.6 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 625 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 814 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.46 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.02 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.js 20 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.rtl.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.css 625 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.js 20 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.rtl.css 626 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-users.js 392 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 584 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.css 215 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.css 721 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.js 412 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-users.js 520 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/babel.config.js 159 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.css 2.36 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.js 13.6 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.rtl.css 2.36 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.04 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 294 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 408 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.59 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 301 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 746 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 574 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 414 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 543 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.4 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.78 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.84 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 545 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.52 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.7 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 507 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 358 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 428 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 782 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.09 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.26 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 391 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.04 kB

compressed-size-action

@jimjasson jimjasson requested review from peterfabian and a team July 9, 2024 11:34
@reykjalin reykjalin removed the request for review from a team July 9, 2024 17:12
@bborman22 bborman22 requested review from a team and lovo-h and removed request for a team July 10, 2024 14:27
Copy link
Contributor

@lovo-h lovo-h left a comment

Choose a reason for hiding this comment

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

Thank you for addressing these issues 🙏

The code changes are looking good, but I was not able to observe some of the behavior, as described. I also left a few nit comments that we may want to apply before merging 😎

Testing

Bugs

  • ✅ In the cart, notice that the Flat Fee is added to the name of the add-on and is displayed as $0.00.
  • ❌ Then, increase the quantity -- notice that the product price, which represents the price of the single unit, changes (this doesn't happen for products without add-ons).
    • I did notice this bug, but only with the changes in this PR.

Fixes

  • ✅ In the cart, the $0.00 should not be visible.
  • ✅ In the cart, notice that B's price shows up after the add-on value, like so (+$xx).
  • ✅ Change the currency and notice that B's price is converted.
  • ❌ Increase the product quantity and ensure that the product price doesn't change.
    • The product price, which represents the price of the single unit, changes.
  • ❌ In WooCommerce > Orders find the order you submitted -- ensure that B's price shows up correctly there.
    • ❌ The product price is the total divided by the quantity.
    • The add-on doesn't display the price next to it. But I don't know if it should.
  • ❌ By default, quantity and percentage based prices do not show up in the cart.
    • They show up even without the snippets activated.
  • ❌ Ensure that the prices in the cart are correct, even when changing the currency.
    • ❌ Add-on C - The base price plus the add-on price adds up to the total price, but the displayed add-on price is incorrect.
    • ✅ Add-on D - The base price plus the add-on price add up to the total price and the displayed add-on price is correct.
  • ✅ Ensure that both the product price and the add-on prices are correct when increasing the product quantity.

Other Tests

  • ❌ Ensure that the prices in the cart are correct for Quantity add-ons with Adjust Price set to Quantity Based.

// Quantity/multiplier add on needs to be split, calculated, then multiplied by input value.
$addon_price = $this->multi_currency->get_price( $addon['price'] / $addon['value'], 'product' ) * $addon['value'];
}
// phpcs:ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can we remove this phpcs:ignore and @psalm-suppress if we make the following change, above:

if ( class_exists( 'WC_Product_Addons_Helper' ) ) {

$addon_price = wc_price( \WC_Product_Addons_Helper::get_product_addon_price_for_display( $addon['price'], $cart_item['data'], true ) );
/* translators: %1$s custom addon price in cart */
$value .= sprintf( _x( ' (%1$s)', 'custom price addon price in cart', 'woocommerce-payments' ), $addon_price );
$addon['display'] = $value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Should we add a comment indicating that if display is set, it overrides value? I'm not certain it does but from my testing, it looks like it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is also 1-1 identical to how Product Add-Ons handles the display key -- in general, the display key is not actively used, but is there for backwards compatibility.

$addon['value'] = $addon['price'];
if ( 'flat_fee' === $addon['price_type'] && $addon['price'] && $add_price_to_value ) {
/* translators: %1$s flat fee addon price in order */
$value .= sprintf( _x( ' (+ %1$s)', 'flat fee addon price in order', 'woocommerce-payments' ), $price );
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to consider handling things more gracefully when $price is not defined. Which can happen if class_exists( '\WC_Product_Addons_Helper' ) resolves to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about this, but couldn't find a case where the WC_Product_Addons_Helper wouldn't be defined -- do you have a specific case in mind?

Right now, if this class is not defined, the the add-on value will be the same as the one set by Product Add-Ons, i.e. not converted by the selected currency. Would you prefer to have a different fallback here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Although it's unlikely, this is one scenario where this may happen:

  • We remove WC_Product_Addons_Helper in a future version of woocommerce-product-addons.
  • The merchant installs the future version of woocommerce-product-addons.
  • The merchant installs this version of WooPayments.

Although this is possible, it's unlikely, so we can proceed without making modifications.

@jimjasson
Copy link
Contributor Author

Thank you @lovo-h for the thorough review! 🙏

I pushed some fixes both on this branch and on: https://github.com/woocommerce/woocommerce-product-addons/pull/1048, so feel free to pull both branches and have another look!

Then, increase the quantity -- notice that the product price, which represents the price of the single unit, changes (this doesn't happen for products without add-ons).
I did notice this bug, but only with the changes in this PR.

This bug is a bit random, but you are right that it was not completely fixed by the time you tested this PR.

With the latest stable WooPayments and Product Add-Ons versions active, I am able to replicate this issue by:

  • creating a product that costs $20 and has a $10 flat fee add-on,
  • adding the product with the add-on selected to the cart,
  • changing the currency to GBP and;
  • increasing the product quantity.
Screen.Capture.on.2024-07-15.at.12-52-05.mp4

Don't worry too much if you cannot replicate it -- let's make sure that you don't see it after the latest changes.

@jimjasson jimjasson requested a review from lovo-h July 15, 2024 11:41
Copy link
Contributor

@lovo-h lovo-h left a comment

Choose a reason for hiding this comment

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

Great work! Code changes look good and test well 👍

Fixes

  • 🟢 In the cart, the $0.00 should not be visible.
  • 🟢 In the cart, notice that B's price shows up after the add-on value, like so (+$xx).
  • 🟢 Change the currency and notice that B's price is converted.
  • ✅ Increase the product quantity and ensure that the product price doesn't change.
  • ✅ In WooCommerce > Orders find the order you submitted -- ensure that B's price shows up correctly there.
    • ❓ The add-on doesn't display the price next to it. I'm not sure if it should.
  • ✅ By default, quantity and percentage based prices do not show up in the cart. To make them show up to confirm that they are correct use these snippets.
  • ✅ Ensure that the prices in the cart are correct, even when changing the currency.
  • 🟢 Ensure that both the product price and the add-on prices are correct when increasing the product quantity.

Other Tests

  • ✅ Ensure that the prices in the cart are correct for Quantity add-ons with Adjust Price set to Quantity Based.
  • npm run test:php.

Copy link
Contributor

@peterfabian peterfabian left a comment

Choose a reason for hiding this comment

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

Hi @jimjasson

I added a couple of comments, but I'm trying to test it on the jurassic ninja site and having problems getting the numbers to add up.

Using a simple product with price 21 and the following addons:
Screenshot 2024-07-17 at 13 45 25

The calculation in the cart differs from what I see on the single product page even with the default currency ($):
Screenshot 2024-07-17 at 13 48 02
Screenshot 2024-07-17 at 13 48 22

It seems to me the total should be $57.30, with the product price being $47.30.

The calculation on the single product page is what I'd expect and it also aligns with what I see in PAO trunk locally:
Screenshot 2024-07-17 at 13 48 58

*/
$add_price_to_value = apply_filters( 'woocommerce_addons_add_cart_price_to_value', false, $cart_item );

if ( 0.0 === (float) $addon['price'] ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be good enough here, but comparing floats for equality might cause subtle problems. Perhaps 0 is a special case here, but I think price can often be filtered and calculated, so maybe not totally safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


if ( 0.0 === (float) $addon['price'] ) {
$value .= '';
} elseif ( 'percentage_based' === $addon['price_type'] && 0.0 === (float) $price ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here with comparing floats for equality.

}
} else {
} elseif ( 'percentage_based' === $addon['price_type'] && $addon['price'] && $add_price_to_value ) {
// Get the percentage cost in the currency in use, and set the meta data on the product that the value was converted.
$_product = wc_get_product( $cart_item['product_id'] );
$price = $this->multi_currency->get_price( $price, 'product' );
$_product->set_price( $price * ( $addon['price'] / 100 ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of scope for this PR, but interesting that we update the product price with percentage-based add-ons, but don't update it for quantity-based add-ons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this happens because the percentage amount needs to be calculated on top of the converted product price. Flat fees and quantity based add-ons are added on top of the product price and they don't need the product price to make any calculation about the actual add-on value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation.

@@ -110,37 +110,64 @@ public function product_addons_params( array $params ): array {
*/
public function get_item_data( $addon_data, $addon, $cart_item ): array {
Copy link
Contributor

@peterfabian peterfabian Jul 17, 2024

Choose a reason for hiding this comment

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

Since this method is very similar to \WC_Product_Addons_Cart::get_item_data, would it be worth it to add a comment to PAO to reflect changes in \WC_Product_Addons_Cart::get_item_data here in Woo Payments, too, so we can avoid things being out of sync in the future? (and similarly with other methods here that have counterparts in PAO)

Alternatively, we could refactor \WC_Product_Addons_Cart::get_item_data (or extract the calculation part out to a separate method) and call it from WooPayments, it's essentially a static method anyway, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some comments here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@peterfabian peterfabian left a comment

Choose a reason for hiding this comment

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

After the changes, the numbers now match. 🎉

I wasn't able to check out with product qty > 1 due to the rounding problem with Level 3 data, but I will create a separate issue for that, since it seems that this problem also happens with the latest stable WooPayments.

Copy link
Contributor

@peterfabian peterfabian left a comment

Choose a reason for hiding this comment

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

Tested and reviewed from different angles, seems to be working as expected now.

The remaining issue was created as #9114.

@jimjasson
Copy link
Contributor Author

Thank you Peter! Will merge this PR after: https://github.com/woocommerce/woocommerce-product-addons/pull/1048 gets released, by the end of July.

@jimjasson jimjasson added this pull request to the merge queue Jul 29, 2024
Merged via the queue into develop with commit 2101d76 Jul 29, 2024
23 checks passed
@jimjasson jimjasson deleted the issue-8911 branch July 29, 2024 10:58
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

Successfully merging this pull request may close these issues.

Update Product Add-Ons integration
4 participants