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

Error in Order Calculations #191

Open
jakemumu opened this issue Mar 2, 2023 · 3 comments
Open

Error in Order Calculations #191

jakemumu opened this issue Mar 2, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@jakemumu
Copy link

jakemumu commented Mar 2, 2023

The PayPal Order Breakdown is Incorrect:

    def breakdown
      {
        item_total: price(@order.item_total),
        shipping: price(@order.shipment_total),
        tax_total: price(@order.additional_tax_total),
        discount: price(@order.all_adjustments.promotion.sum(&:amount).abs)
      }
    end

Solidus Version:
3.1.8

To Reproduce

Step 1 - create an order.
Step 2 - add promotions on the order, ensure that one of the promotions is: eligible: false -- ours looks like:

#<Spree::Adjustment:0x00007fa4d8190f58
 id: 213210,
 source_type: "Spree::PromotionAction",
 source_id: 115,
 adjustable_type: "Spree::LineItem",
 adjustable_id: 242932,
 amount: -0.5337e3,
 label: "Promotion (Bundle Upgrade)",
 eligible: false,
 created_at: Wed, 01 Mar 2023 09:38:51.503385000 CST -06:00,
 updated_at: Wed, 01 Mar 2023 18:09:07.143385000 CST -06:00,
 order_id: 208491,
 included: false,
 promotion_code_id: nil,
 adjustment_reason_id: nil,
 finalized: false>

Current behavior
The order totals will be incorrect and PayPal will reject and not process the order. This is because all non eligible promotions will also be included inside of: discount: price(@order.all_adjustments.promotion.sum(&:amount).abs)

Expected behavior
The order totals should always be perfect

Screenshots

Screenshot 2023-03-01 at 4 30 24 PM

Desktop (please complete the following information):
NA

Smartphone (please complete the following information):
NA

Additional context
NA

@jakemumu jakemumu added the bug Something isn't working label Mar 2, 2023
@jakemumu
Copy link
Author

jakemumu commented Mar 2, 2023

This patch has fixed it:

 # frozen_string_literal: true

 module Decorators
   module SolidusPaypalCommercePlatform
     module PaypalOrder
       def breakdown
         breakdown = super
         breakdown[:discount] = price(@order.promo_total.abs)
         breakdown
       end

       ::SolidusPaypalCommercePlatform::PaypalOrder.prepend(self)
     end
   end
 end

@kennyadsl
Copy link
Member

Looks legit. Can you please open a PR?

@jakemumu
Copy link
Author

Sure, should I do it against master?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants