Skip to content

Fix shipping discount failed to apply during place order #18098

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

Conversation

torreytsui
Copy link
Contributor

@torreytsui torreytsui commented Sep 17, 2018

Description

Caused by #13185, \Magento\Tax\Model\Sales\Total\Quote\Tax::clearValues() is called to unset the total before collecting total. null is expected (representing unset state) in below condition however 0 is set and failed the condition necessary to calculate correct shipping discount.

- expected
+ actual
// \Magento\SalesRule\Model\Validator::processShippingAmount
    public function processShippingAmount(Address $address)
    {
-        // $shippingAmount = null
+        // $shippingAmount = 0
        $shippingAmount = $address->getShippingAmountForDiscount();
        if ($shippingAmount !== null) {
            $baseShippingAmount = $address->getBaseShippingAmountForDiscount();
        } else {
            $shippingAmount = $address->getShippingAmount();
            $baseShippingAmount = $address->getBaseShippingAmount();
        }
        // ...
        $discountAmount = ($shippingAmount - $address->getShippingDiscountAmount()) * $rulePercent / 100;
        // ...
    }

Shipping discount fail to apply to an order, when:

  • order is checking out with payment method which do not collect total after savePaymentInformation() (for example, credit card methods usually meet this criteria, while paypal methods not)
  • order is applied with a promotional rule with shipping discount

Fixed Issues (if relevant)

Can't found any related issue so far

Manual testing scenarios

  1. Create coupon of 20%off discount and set it to applicable to shipping
  2. Apply the coupon
  3. Check out with Braintree
  4. After placed the order, go to account page to view the order

Expected result: Order discount contains shipping amount

Actual result: Order discount does not contain shipping amount

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

Hi @torreytsui. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me $VERSION instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@torreytsui
Copy link
Contributor Author

@magento-engcom-team give me 2.2.5 instance

@magento-engcom-team
Copy link
Contributor

Hi @torreytsui. Thank you for your request. I'm working on Magento 2.2.5 instance for you

@magento-engcom-team
Copy link
Contributor

Hi @torreytsui, here is your Magento instance.
Admin access: https://i-18098-2-2-5.engcom.dev.magento.com/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-3006 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

Hi @torreytsui. Thank you for your contribution.
We will aim to release these changes as part of 2.2.8.
Please check the release notes for final confirmation.

Please, consider to port this solution to 2.3 release line.
You may use Porting tool to port commits automatically.

@marcosdsdba
Copy link

marcosdsdba commented May 8, 2019

The called method $address->getShippingAmountForDiscount() and $address->getBaseShippingAmountForDiscount() and $address->getShippingDiscountPercent() does not exist in the class Address
https://github.com/magento/magento2/blob/2.3.1/app/code/Magento/SalesRule/Model/Validator.php#L290

Class Address :
https://github.com/magento/magento2/blob/2.3.1/app/code/Magento/Quote/Model/Quote/Address.php

Not found these methods.

It's true or I'm wrong ???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants