From 6438a0690031f85796e434c746cc127ad71e1f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Bordinh=C3=A3o?= Date: Mon, 21 Jun 2021 15:09:13 -0300 Subject: [PATCH 1/8] ISSUE-20004: Refactoring minimum order amount including tax value in the calculate --- .../Mftf/Section/CheckoutCartSummarySection.xml | 1 + .../view/frontend/web/js/proceed-to-checkout.js | 17 +++++++++++++++-- .../Magento/Quote/Api/Data/TotalsInterface.php | 13 +++++++++++++ .../Quote/Model/Cart/CartTotalRepository.php | 2 ++ app/code/Magento/Quote/Model/Cart/Totals.php | 16 ++++++++++++++++ app/code/Magento/Quote/Model/Quote.php | 2 ++ 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartSummarySection.xml b/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartSummarySection.xml index 8804fc33e6b31..184a71e2c1263 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartSummarySection.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartSummarySection.xml @@ -22,6 +22,7 @@ + diff --git a/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js b/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js index 836c7a8c58471..e3d405c77fcaf 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js @@ -6,8 +6,9 @@ define([ 'jquery', 'Magento_Customer/js/model/authentication-popup', - 'Magento_Customer/js/customer-data' -], function ($, authenticationPopup, customerData) { + 'Magento_Customer/js/customer-data', + 'Magento_Checkout/js/model/quote', +], function ($, authenticationPopup, customerData, quote) { 'use strict'; return function (config, element) { @@ -26,5 +27,17 @@ define([ location.href = config.checkoutUrl; }); + quote.totals.subscribe(function(totals){ + console.log(totals); + if (totals['is_minimum_order_amount']) { + $(element).prop( "disabled", false ); + $(element).removeClass( "disabled"); + return; + } + + $(element).prop( "disabled", true ); + $(element).addClass( "disabled"); + + }); }; }); diff --git a/app/code/Magento/Quote/Api/Data/TotalsInterface.php b/app/code/Magento/Quote/Api/Data/TotalsInterface.php index fb8dd659980a7..583a2ab6d684f 100644 --- a/app/code/Magento/Quote/Api/Data/TotalsInterface.php +++ b/app/code/Magento/Quote/Api/Data/TotalsInterface.php @@ -69,6 +69,8 @@ interface TotalsInterface extends \Magento\Framework\Api\ExtensibleDataInterface const KEY_ITEMS_QTY = 'items_qty'; + const KEY_IS_MINIMUM_ORDER_AMOUNT = 'is_minimum_order_amount'; + /**#@-*/ /** @@ -476,6 +478,17 @@ public function getTotalSegments(); */ public function setTotalSegments($totals = []); + /** + * @return bool + */ + public function getIsMinimumOrderAmount(); + + /** + * @param bool $isMinimumAmount + * @return mixed + */ + public function setIsMinimumOrderAmount(bool $isMinimumAmount); + /** * Retrieve existing extension attributes object or create a new one. * diff --git a/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php b/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php index 8f7e6504cb7d8..bafd37b2e7669 100644 --- a/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php +++ b/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php @@ -117,6 +117,8 @@ public function get($cartId): QuoteTotalsInterface $quoteTotals->setItemsQty($quote->getItemsQty()); $quoteTotals->setBaseCurrencyCode($quote->getBaseCurrencyCode()); $quoteTotals->setQuoteCurrencyCode($quote->getQuoteCurrencyCode()); + $isMinimumOrderAmount = $quote->validateMinimumAmount(); + $quoteTotals->setIsMinimumOrderAmount($isMinimumOrderAmount); return $quoteTotals; } } diff --git a/app/code/Magento/Quote/Model/Cart/Totals.php b/app/code/Magento/Quote/Model/Cart/Totals.php index e42b72e2eb696..3a1aa749c73bf 100644 --- a/app/code/Magento/Quote/Model/Cart/Totals.php +++ b/app/code/Magento/Quote/Model/Cart/Totals.php @@ -573,6 +573,22 @@ public function setTotalSegments($totals = []) return $this->setData(self::KEY_TOTAL_SEGMENTS, $totals); } + /** + * {@inheritdoc} + */ + public function getIsMinimumOrderAmount() + { + return $this->getData(self::KEY_IS_MINIMUM_ORDER_AMOUNT); + } + + /** + * {@inheritdoc} + */ + public function setIsMinimumOrderAmount(bool $isMinimumAmount) + { + return $this->setData(self::KEY_IS_MINIMUM_ORDER_AMOUNT, $isMinimumAmount); + } + /** * {@inheritdoc} * diff --git a/app/code/Magento/Quote/Model/Quote.php b/app/code/Magento/Quote/Model/Quote.php index 48cd4b2eb2fad..e1916f2f75dd9 100644 --- a/app/code/Magento/Quote/Model/Quote.php +++ b/app/code/Magento/Quote/Model/Quote.php @@ -2298,6 +2298,8 @@ public function validateMinimumAmount($multishipping = false) $storeId ); + $this->collectTotals()->save(); + $addresses = $this->getAllAddresses(); if (!$multishipping) { From f7a3b09d9fba99f89ac724f675331dd059a0387d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Bordinh=C3=A3o?= Date: Tue, 22 Jun 2021 11:53:27 -0300 Subject: [PATCH 2/8] ISSUE-20004: Resolving issues with static tests for B2B and Unit tests broken. --- .../frontend/web/js/proceed-to-checkout.js | 19 ++++---- .../Quote/Test/Unit/Model/QuoteTest.php | 44 +++++++++++++++++++ 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js b/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js index e3d405c77fcaf..24e11ffc0e1d3 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js @@ -7,7 +7,7 @@ define([ 'jquery', 'Magento_Customer/js/model/authentication-popup', 'Magento_Customer/js/customer-data', - 'Magento_Checkout/js/model/quote', + 'Magento_Checkout/js/model/quote' ], function ($, authenticationPopup, customerData, quote) { 'use strict'; @@ -27,17 +27,16 @@ define([ location.href = config.checkoutUrl; }); - quote.totals.subscribe(function(totals){ - console.log(totals); - if (totals['is_minimum_order_amount']) { - $(element).prop( "disabled", false ); - $(element).removeClass( "disabled"); - return; - } + quote.totals.subscribe(function (totals) { + if (totals['is_minimum_order_amount']) { + $(element).prop('disabled', false); + $(element).removeClass('disabled'); - $(element).prop( "disabled", true ); - $(element).addClass( "disabled"); + return; + } + $(element).prop('disabled', true); + $(element).addClass('disabled'); }); }; }); diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php index 422a6cbcb7bbe..0d6d100f2aa9e 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php @@ -40,6 +40,7 @@ use Magento\Quote\Model\Quote\AddressFactory; use Magento\Quote\Model\Quote\Item; use Magento\Quote\Model\Quote\Item\Processor; +use Magento\Quote\Model\Quote\TotalsCollector; use Magento\Quote\Model\Quote\Payment; use Magento\Quote\Model\Quote\PaymentFactory; use Magento\Quote\Model\ResourceModel\Quote\Address\Collection; @@ -190,6 +191,11 @@ class QuoteTest extends TestCase */ private $orderIncrementIdChecker; + /** + * @var TotalsCollector|MockObject + */ + private $totalsCollector; + /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -311,6 +317,17 @@ protected function setUp(): void CustomerInterfaceFactory::class, ['create'] ); + + /*$this->totalCollector = $this->createPartialMock( + TotalsCollector::class, + ['collect'] + );*/ + $this->totalsCollector = $this->getMockBuilder(TotalsCollector::class) + ->onlyMethods(['collect']) + ->disableOriginalConstructor() + ->getMock(); + + $this->orderIncrementIdChecker = $this->createMock(OrderIncrementIdChecker::class); $this->quote = (new ObjectManager($this)) ->getObject( @@ -337,6 +354,7 @@ protected function setUp(): void 'customerDataFactory' => $this->customerDataFactoryMock, 'itemProcessor' => $this->itemProcessor, 'orderIncrementIdChecker' => $this->orderIncrementIdChecker, + 'totalsCollector' => $this->totalsCollector, 'data' => [ 'reserved_order_id' => 1000001, ], @@ -1083,6 +1101,19 @@ public function testValidateMinimumAmount() ->method('setQuoteFilter') ->willReturn([$this->quoteAddressMock]); + $totalsMock = $this->getMockBuilder(DataObject::class) + ->onlyMethods(['getData']) + ->disableOriginalConstructor() + ->getMock(); + + $totalsMock->expects($this->once()) + ->method('getData') + ->willReturn([]); + + $this->totalsCollector->expects($this->once()) + ->method('collect') + ->willReturn($totalsMock); + $this->assertTrue($this->quote->validateMinimumAmount()); } @@ -1110,6 +1141,19 @@ public function testValidateMinimumAmountNegative() ->method('setQuoteFilter') ->willReturn([$this->quoteAddressMock]); + $totalsMock = $this->getMockBuilder(DataObject::class) + ->onlyMethods(['getData']) + ->disableOriginalConstructor() + ->getMock(); + + $totalsMock->expects($this->once()) + ->method('getData') + ->willReturn([]); + + $this->totalsCollector->expects($this->once()) + ->method('collect') + ->willReturn($totalsMock); + $this->assertFalse($this->quote->validateMinimumAmount()); } From 535a60ccb2123a36bf659944e03a036fe9e5eebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Bordinh=C3=A3o?= Date: Tue, 22 Jun 2021 20:25:01 -0300 Subject: [PATCH 3/8] ISSUE-20004: Resolving Unit and API functional tests --- .../Test/Unit/Model/Cart/CartTotalRepositoryTest.php | 12 +++++++++++- .../Magento/Quote/Api/CartTotalRepositoryTest.php | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Cart/CartTotalRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/Cart/CartTotalRepositoryTest.php index bd2a2b7a82712..55ad2b0609b03 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Cart/CartTotalRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Cart/CartTotalRepositoryTest.php @@ -108,7 +108,8 @@ protected function setUp(): void 'getBillingAddress', 'getAllVisibleItems', 'getItemsQty', - 'collectTotals' + 'collectTotals', + 'validateMinimumAmount' ] ) ->disableOriginalConstructor() @@ -138,6 +139,11 @@ protected function setUp(): void TotalsConverter::class ); + $this->totalsConverterMock = $this->createMock( + TotalsConverter::class + ); + + $this->model = new CartTotalRepository( $this->totalsFactoryMock, $this->quoteRepositoryMock, @@ -247,6 +253,10 @@ public function testGetCartTotal($isVirtual, $getAddressType): void ->with(self::STUB_CURRENCY_CODE) ->willReturnSelf(); + $this->quoteMock->expects($this->once()) + ->method('validateMinimumAmount') + ->willReturn(true); + $this->assertEquals($totalsMock, $this->model->get(self::STUB_CART_ID)); } diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php index 1b219d0e11141..31815be96c841 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php @@ -241,6 +241,7 @@ private function getData(Quote $quote, Address $shippingAddress) : array Totals::KEY_QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode(), Totals::KEY_ITEMS_QTY => $quote->getItemsQty(), Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)], + Totals::KEY_IS_MINIMUM_ORDER_AMOUNT => $quote->validateMinimumAmount() ]; } } From 1b476bede9254482ab92273c26b9ab7b3d2335d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Bordinh=C3=A3o?= Date: Wed, 23 Jun 2021 00:45:49 -0300 Subject: [PATCH 4/8] ISSUE-20004: Fixing API tests --- .../testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php index 943e34d280bf2..e9af481fa3c92 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php @@ -87,6 +87,7 @@ public function testGetTotals() Totals::KEY_QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode(), Totals::KEY_ITEMS_QTY => $quote->getItemsQty(), Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)], + Totals::KEY_IS_MINIMUM_ORDER_AMOUNT => $quote->validateMinimumAmount() ]; $requestData = ['cartId' => $cartId]; From 3529fbd8b741610f94e3fa2a385e35ebe42e40e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Bordinh=C3=A3o?= Date: Fri, 9 Jul 2021 21:55:27 -0300 Subject: [PATCH 5/8] ISSUE-20004: Moving the logic to the extension attributes instead of use change the interface --- ...efrontVerifyGuestCartMinimumAmountTest.xml | 61 +++++++++++++++++++ .../Quote/Api/Data/TotalsInterface.php | 15 +---- .../Quote/Model/Cart/CartTotalRepository.php | 4 +- app/code/Magento/Quote/Model/Cart/Totals.php | 16 ----- .../Model/Cart/CartTotalRepositoryTest.php | 21 ++++++- .../Quote/Test/Unit/Model/QuoteTest.php | 5 -- .../Quote/etc/extension_attributes.xml | 1 + .../Quote/Api/CartTotalRepositoryTest.php | 3 +- .../Api/GuestCartTotalRepositoryTest.php | 3 +- 9 files changed, 88 insertions(+), 41 deletions(-) create mode 100644 app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml new file mode 100644 index 0000000000000..d53498dce1fd2 --- /dev/null +++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml @@ -0,0 +1,61 @@ + + + + + + + + + <description value="When the minimum order amount is set it must consider the tax value"/> + <severity value="BLOCKER"/> + <testCaseId value="MC-28285"/> + <group value="checkout"/> + <group value="tax"/> + </annotations> + <before> + <createData entity="FlatRateShippingMethodConfig" stepKey="enableFlatRate"/> + <createData entity="FreeShippingMethodsSettingConfig" stepKey="freeShippingMethodsSettingConfig"/> + <createData entity="MinimumOrderAmount100" stepKey="minimumOrderAmount"/> + <createData entity="taxRate_US_NY_8_1" stepKey="createTaxRateUSNY"/> + <createData entity="DefaultTaxRuleWithCustomTaxRate" stepKey="createTaxRuleUSNY"> + <requiredEntity createDataKey="createTaxRateUSNY" /> + </createData> + <createData entity="ApiCategory" stepKey="createCategory"/> + <createData entity="defaultSimpleProduct" stepKey="simpleProduct"> + <requiredEntity createDataKey="createCategory"/> + <field key="price">95.00</field> + </createData> + </before> + <after> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <deleteData createDataKey="simpleProduct" stepKey="deleteProduct"/> + <deleteData createDataKey="createTaxRuleUSNY" stepKey="deleteTaxRuleUSNY"/> + <deleteData createDataKey="createTaxRateUSNY" stepKey="deleteTaxRateUSNY"/> + <createData entity="DefaultShippingMethodsConfig" stepKey="defaultShippingMethodsConfig"/> + <createData entity="DefaultMinimumOrderAmount" stepKey="defaultMinimumOrderAmount"/> + </after> + <actionGroup ref="AssertProductNameAndSkuInStorefrontProductPageByCustomAttributeUrlKeyActionGroup" stepKey="openProductPageAndVerifyProduct"> + <argument name="product" value="$simpleProduct$"/> + </actionGroup> + <actionGroup ref="StorefrontAddProductToCartWithQtyActionGroup" stepKey="addSimpleProductToTheCart"> + <argument name="productQty" value="1"/> + </actionGroup> + <actionGroup ref="ClickViewAndEditCartFromMiniCartActionGroup" stepKey="clickMiniCart"/> + <waitForElementVisible selector="{{CheckoutCartSummarySection.proceedToCheckoutDisabled}}" stepKey="goToCheckoutDisabled"/> + <actionGroup ref="CheckoutFillEstimateShippingAndTaxActionGroup" stepKey="fillEstimateShippingAndTaxFields"> + <argument name="address" value="US_Address_NY_Default_Shipping"/> + </actionGroup> + <click selector="{{CheckoutCartSummarySection.shippingMethodElementId('freeshipping', 'freeshipping')}}" stepKey="selectShippingMethod"/> + <see selector="{{CheckoutCartSummarySection.taxAmount}}" userInput="$7.70" stepKey="seeTaxAmount"/> + <scrollTo selector="{{CheckoutCartSummarySection.proceedToCheckout}}" stepKey="scrollToProceedToCheckout" /> + <actionGroup ref="StorefrontClickProceedToCheckoutActionGroup" stepKey="goToCheckout"/> + <comment userInput="Adding the comment to replace waitForPageToLoad action for preserving Backward Compatibility" stepKey="waitForPageToLoad"/> + <waitForElementVisible selector="{{CheckoutShippingMethodsSection.next}}" stepKey="waitForNextButton"/> + </test> +</tests> diff --git a/app/code/Magento/Quote/Api/Data/TotalsInterface.php b/app/code/Magento/Quote/Api/Data/TotalsInterface.php index 583a2ab6d684f..f7a863c1e22a2 100644 --- a/app/code/Magento/Quote/Api/Data/TotalsInterface.php +++ b/app/code/Magento/Quote/Api/Data/TotalsInterface.php @@ -69,8 +69,6 @@ interface TotalsInterface extends \Magento\Framework\Api\ExtensibleDataInterface const KEY_ITEMS_QTY = 'items_qty'; - const KEY_IS_MINIMUM_ORDER_AMOUNT = 'is_minimum_order_amount'; - /**#@-*/ /** @@ -477,18 +475,7 @@ public function getTotalSegments(); * @return $this */ public function setTotalSegments($totals = []); - - /** - * @return bool - */ - public function getIsMinimumOrderAmount(); - - /** - * @param bool $isMinimumAmount - * @return mixed - */ - public function setIsMinimumOrderAmount(bool $isMinimumAmount); - + /** * Retrieve existing extension attributes object or create a new one. * diff --git a/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php b/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php index bafd37b2e7669..24c050d906150 100644 --- a/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php +++ b/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php @@ -118,7 +118,9 @@ public function get($cartId): QuoteTotalsInterface $quoteTotals->setBaseCurrencyCode($quote->getBaseCurrencyCode()); $quoteTotals->setQuoteCurrencyCode($quote->getQuoteCurrencyCode()); $isMinimumOrderAmount = $quote->validateMinimumAmount(); - $quoteTotals->setIsMinimumOrderAmount($isMinimumOrderAmount); + $extensionAttributes = $quoteTotals->getExtensionAttributes(); + $extensionAttributes->setIsMinimumOrderAmount($isMinimumOrderAmount); + $quoteTotals->setExtensionAttributes($extensionAttributes); return $quoteTotals; } } diff --git a/app/code/Magento/Quote/Model/Cart/Totals.php b/app/code/Magento/Quote/Model/Cart/Totals.php index 3a1aa749c73bf..e42b72e2eb696 100644 --- a/app/code/Magento/Quote/Model/Cart/Totals.php +++ b/app/code/Magento/Quote/Model/Cart/Totals.php @@ -573,22 +573,6 @@ public function setTotalSegments($totals = []) return $this->setData(self::KEY_TOTAL_SEGMENTS, $totals); } - /** - * {@inheritdoc} - */ - public function getIsMinimumOrderAmount() - { - return $this->getData(self::KEY_IS_MINIMUM_ORDER_AMOUNT); - } - - /** - * {@inheritdoc} - */ - public function setIsMinimumOrderAmount(bool $isMinimumAmount) - { - return $this->setData(self::KEY_IS_MINIMUM_ORDER_AMOUNT, $isMinimumAmount); - } - /** * {@inheritdoc} * diff --git a/app/code/Magento/Quote/Test/Unit/Model/Cart/CartTotalRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/Cart/CartTotalRepositoryTest.php index 55ad2b0609b03..c52f1fb07418c 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Cart/CartTotalRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Cart/CartTotalRepositoryTest.php @@ -14,6 +14,7 @@ use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Api\CouponManagementInterface; use Magento\Quote\Api\Data\TotalSegmentInterface; +use Magento\Quote\Api\Data\TotalsExtensionInterface; use Magento\Quote\Api\Data\TotalsInterface as QuoteTotalsInterface; use Magento\Quote\Api\Data\TotalsInterfaceFactory; use Magento\Quote\Model\Cart\CartTotalRepository; @@ -143,7 +144,6 @@ protected function setUp(): void TotalsConverter::class ); - $this->model = new CartTotalRepository( $this->totalsFactoryMock, $this->quoteRepositoryMock, @@ -253,6 +253,25 @@ public function testGetCartTotal($isVirtual, $getAddressType): void ->with(self::STUB_CURRENCY_CODE) ->willReturnSelf(); + $totalExtensionInterfaceMock = $this->getMockBuilder(TotalsExtensionInterface::class) + ->onlyMethods(['setIsMinimumOrderAmount']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $totalsMock->expects($this->once()) + ->method('getExtensionAttributes') + ->willReturn($totalExtensionInterfaceMock); + + $totalExtensionInterfaceMock->expects($this->once()) + ->method('setIsMinimumOrderAmount') + ->with(true) + ->willReturnSelf(); + + $totalsMock->expects($this->once()) + ->method('setExtensionAttributes') + ->with($totalExtensionInterfaceMock) + ->willReturnSelf(); + $this->quoteMock->expects($this->once()) ->method('validateMinimumAmount') ->willReturn(true); diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php index 0d6d100f2aa9e..8dfca53e7e8f9 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php @@ -318,16 +318,11 @@ protected function setUp(): void ['create'] ); - /*$this->totalCollector = $this->createPartialMock( - TotalsCollector::class, - ['collect'] - );*/ $this->totalsCollector = $this->getMockBuilder(TotalsCollector::class) ->onlyMethods(['collect']) ->disableOriginalConstructor() ->getMock(); - $this->orderIncrementIdChecker = $this->createMock(OrderIncrementIdChecker::class); $this->quote = (new ObjectManager($this)) ->getObject( diff --git a/app/code/Magento/Quote/etc/extension_attributes.xml b/app/code/Magento/Quote/etc/extension_attributes.xml index 6fff29e32d2ab..9d9169b7d2966 100644 --- a/app/code/Magento/Quote/etc/extension_attributes.xml +++ b/app/code/Magento/Quote/etc/extension_attributes.xml @@ -12,5 +12,6 @@ <extension_attributes for="Magento\Quote\Api\Data\TotalsInterface"> <attribute code="coupon_label" type="string" /> + <attribute code="is_minimum_order_amount" type="int" /> </extension_attributes> </config> diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php index 31815be96c841..c22235442fab3 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php @@ -240,8 +240,7 @@ private function getData(Quote $quote, Address $shippingAddress) : array Totals::KEY_BASE_CURRENCY_CODE => $quote->getBaseCurrencyCode(), Totals::KEY_QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode(), Totals::KEY_ITEMS_QTY => $quote->getItemsQty(), - Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)], - Totals::KEY_IS_MINIMUM_ORDER_AMOUNT => $quote->validateMinimumAmount() + Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)] ]; } } diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php index e9af481fa3c92..ce0a09197b138 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php @@ -86,8 +86,7 @@ public function testGetTotals() Totals::KEY_BASE_CURRENCY_CODE => $quote->getBaseCurrencyCode(), Totals::KEY_QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode(), Totals::KEY_ITEMS_QTY => $quote->getItemsQty(), - Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)], - Totals::KEY_IS_MINIMUM_ORDER_AMOUNT => $quote->validateMinimumAmount() + Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)] ]; $requestData = ['cartId' => $cartId]; From c100ffc544c757912103bff5ecb307cbd0c57fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Bordinh=C3=A3o?= <vinicius.bordinhao@blueacornici.com> Date: Sat, 10 Jul 2021 23:52:20 -0300 Subject: [PATCH 6/8] ISSUE-20004: Adjusting the functional test to make sure that default shipping does not influence the minimum amount --- .../Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml index d53498dce1fd2..3bf5e2679a58f 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml @@ -29,7 +29,7 @@ <createData entity="ApiCategory" stepKey="createCategory"/> <createData entity="defaultSimpleProduct" stepKey="simpleProduct"> <requiredEntity createDataKey="createCategory"/> - <field key="price">95.00</field> + <field key="price">93.00</field> </createData> </before> <after> @@ -52,7 +52,7 @@ <argument name="address" value="US_Address_NY_Default_Shipping"/> </actionGroup> <click selector="{{CheckoutCartSummarySection.shippingMethodElementId('freeshipping', 'freeshipping')}}" stepKey="selectShippingMethod"/> - <see selector="{{CheckoutCartSummarySection.taxAmount}}" userInput="$7.70" stepKey="seeTaxAmount"/> + <see selector="{{CheckoutCartSummarySection.taxAmount}}" userInput="$7.53" stepKey="seeTaxAmount"/> <scrollTo selector="{{CheckoutCartSummarySection.proceedToCheckout}}" stepKey="scrollToProceedToCheckout" /> <actionGroup ref="StorefrontClickProceedToCheckoutActionGroup" stepKey="goToCheckout"/> <comment userInput="Adding the comment to replace waitForPageToLoad action for preserving Backward Compatibility" stepKey="waitForPageToLoad"/> From 7710b5e55d9948e9d5dc7fc576ef19dfd0fd6d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Bordinh=C3=A3o?= <vinicius.bordinhao@blueacornici.com> Date: Mon, 12 Jul 2021 19:06:49 -0300 Subject: [PATCH 7/8] ISSUE-20004: Adjusting the functional test to make sure minimum order amount is set up. --- .../StorefrontVerifyGuestCartMinimumAmountTest.xml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml index 3bf5e2679a58f..375183c12dad8 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml @@ -21,7 +21,8 @@ <before> <createData entity="FlatRateShippingMethodConfig" stepKey="enableFlatRate"/> <createData entity="FreeShippingMethodsSettingConfig" stepKey="freeShippingMethodsSettingConfig"/> - <createData entity="MinimumOrderAmount100" stepKey="minimumOrderAmount"/> + <magentoCLI command="config:set sales/minimum_order/active 1" stepKey="enableMinimumOrderAmount"/> + <magentoCLI command="config:set sales/minimum_order/amount 100" stepKey="setMinimumOrderAmount100"/> <createData entity="taxRate_US_NY_8_1" stepKey="createTaxRateUSNY"/> <createData entity="DefaultTaxRuleWithCustomTaxRate" stepKey="createTaxRuleUSNY"> <requiredEntity createDataKey="createTaxRateUSNY" /> @@ -31,6 +32,9 @@ <requiredEntity createDataKey="createCategory"/> <field key="price">93.00</field> </createData> + <actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanInvalidatedCaches"> + <argument name="tags" value="config full_page"/> + </actionGroup> </before> <after> <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> @@ -48,11 +52,14 @@ </actionGroup> <actionGroup ref="ClickViewAndEditCartFromMiniCartActionGroup" stepKey="clickMiniCart"/> <waitForElementVisible selector="{{CheckoutCartSummarySection.proceedToCheckoutDisabled}}" stepKey="goToCheckoutDisabled"/> + <actionGroup ref="AssertMessageCustomerChangeAccountInfoActionGroup" stepKey="assertMinimumAmountOrderMessage"> + <argument name="message" value="Minimum order amount is $100.00"/> + <argument name="messageType" value="notice"/> + </actionGroup> <actionGroup ref="CheckoutFillEstimateShippingAndTaxActionGroup" stepKey="fillEstimateShippingAndTaxFields"> <argument name="address" value="US_Address_NY_Default_Shipping"/> </actionGroup> <click selector="{{CheckoutCartSummarySection.shippingMethodElementId('freeshipping', 'freeshipping')}}" stepKey="selectShippingMethod"/> - <see selector="{{CheckoutCartSummarySection.taxAmount}}" userInput="$7.53" stepKey="seeTaxAmount"/> <scrollTo selector="{{CheckoutCartSummarySection.proceedToCheckout}}" stepKey="scrollToProceedToCheckout" /> <actionGroup ref="StorefrontClickProceedToCheckoutActionGroup" stepKey="goToCheckout"/> <comment userInput="Adding the comment to replace waitForPageToLoad action for preserving Backward Compatibility" stepKey="waitForPageToLoad"/> From 77600efa91f1993b4f36e6dac624d84b313caa43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Bordinh=C3=A3o?= <vinicius.bordinhao@blueacornici.com> Date: Fri, 23 Jul 2021 21:50:38 -0300 Subject: [PATCH 8/8] ISSUE-20004: Reverting changes not needed for the interface and adjusting the MTFT test. --- .../Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml | 2 +- app/code/Magento/Quote/Api/Data/TotalsInterface.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml index 375183c12dad8..b6ba5529f1a42 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontVerifyGuestCartMinimumAmountTest.xml @@ -62,7 +62,7 @@ <click selector="{{CheckoutCartSummarySection.shippingMethodElementId('freeshipping', 'freeshipping')}}" stepKey="selectShippingMethod"/> <scrollTo selector="{{CheckoutCartSummarySection.proceedToCheckout}}" stepKey="scrollToProceedToCheckout" /> <actionGroup ref="StorefrontClickProceedToCheckoutActionGroup" stepKey="goToCheckout"/> - <comment userInput="Adding the comment to replace waitForPageToLoad action for preserving Backward Compatibility" stepKey="waitForPageToLoad"/> + <waitForPageLoad stepKey="waitForPageToLoad"/> <waitForElementVisible selector="{{CheckoutShippingMethodsSection.next}}" stepKey="waitForNextButton"/> </test> </tests> diff --git a/app/code/Magento/Quote/Api/Data/TotalsInterface.php b/app/code/Magento/Quote/Api/Data/TotalsInterface.php index f7a863c1e22a2..fb8dd659980a7 100644 --- a/app/code/Magento/Quote/Api/Data/TotalsInterface.php +++ b/app/code/Magento/Quote/Api/Data/TotalsInterface.php @@ -475,7 +475,7 @@ public function getTotalSegments(); * @return $this */ public function setTotalSegments($totals = []); - + /** * Retrieve existing extension attributes object or create a new one. *