magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.49k stars 9.31k forks source link

Totals Information Management - setting quote shipping method when address method is null #25147

Closed joe-vortex closed 4 years ago

joe-vortex commented 4 years ago

Preconditions (*)

  1. 2.3.2(2.3-develop) Magento Commerce or Open Source
  2. Amasty Conditions module installed (cannot reproduce with vanilla m2 because this)
  3. PHP 7.2.21

Steps to reproduce (*)

  1. On the checkout, the component Amasty_Conditions/js/action/recollect-totals makes a call to /V1/guest-carts/:cartId/totals-information which passes through Magento\Checkout\Model\TotalsInformationManagement
  2. In this model the following:
    $quote->getShippingAddress()->setCollectShippingRates(true)->setShippingMethod(
     $addressInformation->getShippingCarrierCode() . '_' . $addressInformation->getShippingMethodCode()
    );

    is set, but when a shipping method has not been selected, it will return the quote shipping method with a total of 0 and a name of _, because $addressInformation->getShippingCarrierCode() and method code are null - so setShippingMethod('_') happens in effect.

  3. This then means that validation for the shipping method is bypassed.
  4. An order can then be placed without shipping information/carrier

Expected result (*)

  1. If the address info has the shipping carrier and/or method code set to null, the setShippingMethod should not be called and the quote total is returned without setting a shipping code pair

Actual result (*)

  1. When a address info instance is submitted with shipping codes set to null, a method is set with label _ and zero value, meaning an order can be placed without a valid shipping method.
m2-assistant[bot] commented 4 years ago

Hi @joe-vortex. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

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

@joe-vortex do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?


joe-vortex commented 4 years ago

can be fixed with the following patch:

--- magento/module-checkout/Model/TotalsInformationManagement.php   2019-10-18 13:17:40.275177439 +0100
+++ magento/module-checkout/Model/TotalsInformationManagement.php   2019-10-18 13:17:30.307000000 +0100
@@ -52,9 +52,11 @@
             $quote->setBillingAddress($addressInformation->getAddress());
         } else {
             $quote->setShippingAddress($addressInformation->getAddress());
-            $quote->getShippingAddress()->setCollectShippingRates(true)->setShippingMethod(
-                $addressInformation->getShippingCarrierCode() . '_' . $addressInformation->getShippingMethodCode()
-            );
+            if ($addressInformation->getShippingCarrierCode() && $addressInformation->getShippingMethodCode()) {
+                $quote->getShippingAddress()->setCollectShippingRates(true)->setShippingMethod(
+                    $addressInformation->getShippingCarrierCode().'_'.$addressInformation->getShippingMethodCode()
+                );
+            }
         }
         $quote->collectTotals();
sdzhepa commented 4 years ago

After discussion and investigation, I believe this issue is not specific only for Magento Commerce(EE) and the same problem should be in Open Source(CE) as well. It could be not possible to reproduce it by provided steps without buying the Amasty Conditions module but from a code perspective, we see the bug.

Confirmed

magento-engcom-team commented 4 years ago

:white_check_mark: Confirmed by @sdzhepa Thank you for verifying the issue. Based on the provided information internal tickets MC-22098 were created

Issue Available: @sdzhepa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

joe-vortex commented 4 years ago

thanks @sdzhepa , are you happy for me to make a PR?

m2-assistant[bot] commented 4 years ago

Hi @joe-vortex. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:


magento-engcom-team commented 4 years ago

Hi @joe-vortex. Thank you for your report. The issue has been fixed in magento/magento2#25510 by @joe-vortex in 2.4-develop branch Related commit(s):

The fix will be available with the upcoming 2.4.2 release.