Skip to content

Commit 1fd2f67

Browse files
Merge branch '2.4-develop' into order-cancellation
2 parents bee35e4 + 0cdd86b commit 1fd2f67

File tree

5 files changed

+96
-8
lines changed

5 files changed

+96
-8
lines changed

app/code/Magento/Checkout/Model/TotalsInformationManagement.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,34 @@
66
namespace Magento\Checkout\Model;
77

88
use Magento\Checkout\Api\Data\TotalsInformationInterface;
9+
use Magento\Quote\Api\CartRepositoryInterface;
10+
use Magento\Quote\Api\CartTotalRepositoryInterface;
911

1012
/**
1113
* Class for management of totals information.
1214
*/
1315
class TotalsInformationManagement implements \Magento\Checkout\Api\TotalsInformationManagementInterface
1416
{
1517
/**
16-
* @var \Magento\Quote\Api\CartTotalRepositoryInterface
18+
* @var CartTotalRepositoryInterface
1719
*/
1820
protected $cartTotalRepository;
1921

2022
/**
2123
* Quote repository.
2224
*
23-
* @var \Magento\Quote\Api\CartRepositoryInterface
25+
* @var CartRepositoryInterface
2426
*/
2527
protected $cartRepository;
2628

2729
/**
28-
* @param \Magento\Quote\Api\CartRepositoryInterface $cartRepository
29-
* @param \Magento\Quote\Api\CartTotalRepositoryInterface $cartTotalRepository
30+
* @param CartRepositoryInterface $cartRepository
31+
* @param CartTotalRepositoryInterface $cartTotalRepository
3032
* @codeCoverageIgnore
3133
*/
3234
public function __construct(
33-
\Magento\Quote\Api\CartRepositoryInterface $cartRepository,
34-
\Magento\Quote\Api\CartTotalRepositoryInterface $cartTotalRepository
35+
CartRepositoryInterface $cartRepository,
36+
CartTotalRepositoryInterface $cartTotalRepository
3537
) {
3638
$this->cartRepository = $cartRepository;
3739
$this->cartTotalRepository = $cartTotalRepository;
@@ -66,6 +68,7 @@ public function calculate(
6668
}
6769
$quoteShippingAddress->setCollectShippingRates(true)
6870
->setShippingMethod($shippingMethod);
71+
$quoteShippingAddress->save();
6972
}
7073
}
7174
$quote->collectTotals();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StorefrontApplyCouponWithShippingMethodConditionAppliedTest">
12+
<annotations>
13+
<features value="Shipping"/>
14+
<stories value="Cart price rules"/>
15+
<title value="Assert that coupon applied for shipping methods cart price rule"/>
16+
<description value="Coupon should applied correctly on checkout for shipping methods cart price rule"/>
17+
<severity value="CRITICAL"/>
18+
<testCaseId value="AC-2044"/>
19+
<group value="shipping"/>
20+
<group value="SalesRule"/>
21+
</annotations>
22+
<before>
23+
<createData entity="SimpleProduct2" stepKey="createProduct"/>
24+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
25+
<magentoCLI command="config:set {{EnableFlatRateConfigData.path}} {{EnableFlatRateConfigData.value}}" stepKey="enableFlatRate"/>
26+
27+
<actionGroup ref="AdminOpenNewCartPriceRuleFormPageActionGroup" stepKey="createCartPriceRule"/>
28+
<actionGroup ref="AdminCartPriceRuleFillMainInfoActionGroup" stepKey="selectCustomCustomerGroup">
29+
<argument name="name" value="{{ActiveSalesRuleWithPercentPriceDiscountCoupon.name}}"/>
30+
<argument name="description" value="{{ActiveSalesRuleWithPercentPriceDiscountCoupon.description}}"/>
31+
</actionGroup>
32+
<actionGroup ref="AdminCartPriceRuleFillCouponInfoActionGroup" stepKey="fillCartPriceRuleCouponInfo">
33+
<argument name="couponCode" value="{{ActiveSalesRuleWithPercentPriceDiscountCoupon.coupon_code}}"/>
34+
<argument name="userPerCoupon" value="1"/>
35+
<argument name="userPerCustomer" value="1"/>
36+
</actionGroup>
37+
<actionGroup ref="AdminCartPriceRuleFillShippingConditionActionGroup" stepKey="setCartAttributeConditionForCartPriceRule"/>
38+
<actionGroup ref="AdminCartPriceRuleSaveActionGroup" stepKey="saveCartPriceRule"/>
39+
</before>
40+
<after>
41+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
42+
<actionGroup ref="DeleteCartPriceRuleByName" stepKey="deleteCartPriceRule">
43+
<argument name="ruleName" value="{{ActiveSalesRuleWithPercentPriceDiscountCoupon.name}}"/>
44+
</actionGroup>
45+
46+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
47+
</after>
48+
49+
<actionGroup ref="OpenStoreFrontProductPageActionGroup" stepKey="navigateToProductPage">
50+
<argument name="productUrlKey" value="$createProduct.custom_attributes[url_key]$"/>
51+
</actionGroup>
52+
53+
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addProductToCart">
54+
<argument name="product" value="$createProduct$" />
55+
<argument name="productCount" value="1" />
56+
</actionGroup>
57+
58+
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="openShoppingCartPage"/>
59+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.estimateShippingAndTaxForm}}" stepKey="waitForEstimateShippingAndTaxForm"/>
60+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.shippingMethodForm}}" stepKey="waitForShippingMethodForm"/>
61+
<!-- Apply Discount Coupon to the Order -->
62+
<actionGroup ref="StorefrontShoppingCartClickApplyDiscountButtonActionGroup" stepKey="clickApplyButton"/>
63+
<actionGroup ref="StorefrontShoppingCartFillCouponCodeFieldActionGroup" stepKey="fillDiscountCodeField">
64+
<argument name="discountCode" value="{{ActiveSalesRuleWithPercentPriceDiscountCoupon.coupon_code}}"/>
65+
</actionGroup>
66+
<actionGroup ref="StorefrontShoppingCartClickApplyDiscountButtonActionGroup" stepKey="clickApplyDiscountButton"/>
67+
<actionGroup ref="AssertMessageCustomerChangeAccountInfoActionGroup" stepKey="assertSuccessMessage">
68+
<argument name="message" value='You used coupon code "{{ActiveSalesRuleWithPercentPriceDiscountCoupon.coupon_code}}".'/>
69+
</actionGroup>
70+
</test>
71+
</tests>

app/code/Magento/Checkout/Test/Unit/Model/TotalsInformationManagementTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function testCalculate(?string $carrierCode, ?string $carrierMethod, int
8585
'setCollectShippingRates',
8686
]
8787
)
88+
->onlyMethods(['save'])
8889
->disableOriginalConstructor()
8990
->getMock();
9091

@@ -97,6 +98,9 @@ public function testCalculate(?string $carrierCode, ?string $carrierMethod, int
9798
->method('setCollectShippingRates')->with(true)->willReturn($addressMock);
9899
$addressMock->expects($this->exactly($methodSetCount))
99100
->method('setShippingMethod')->with($carrierCode . '_' . $carrierMethod);
101+
$addressMock->expects($this->exactly($methodSetCount))
102+
->method('save')
103+
->willReturnSelf();
100104
$cartMock->expects($this->once())->method('collectTotals');
101105

102106
$this->totalsInformationManagement->calculate($cartId, $addressInformationMock);
@@ -131,6 +135,7 @@ public function testResetShippingAmount()
131135
'getShippingMethod',
132136
'setShippingAmount',
133137
'setBaseShippingAmount',
138+
'save'
134139
]
135140
)
136141
->disableOriginalConstructor()
@@ -162,6 +167,9 @@ public function testResetShippingAmount()
162167
$addressMock->expects($this->once())
163168
->method('setShippingMethod')
164169
->with($carrierCode . '_' . $carrierMethod);
170+
$addressMock->expects($this->once())
171+
->method('save')
172+
->willReturnSelf();
165173
$cartMock->expects($this->once())
166174
->method('collectTotals');
167175

app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ define([
259259
rates: shippingService.getShippingRates(),
260260
isLoading: shippingService.isLoading,
261261
isSelected: ko.computed(function () {
262-
return quote.shippingMethod() ?
262+
return checkoutData.getSelectedShippingRate() ? checkoutData.getSelectedShippingRate() :
263+
quote.shippingMethod() ?
263264
quote.shippingMethod()['carrier_code'] + '_' + quote.shippingMethod()['method_code'] :
264265
null;
265266
}),

dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ define(['squire', 'ko', 'jquery', 'jquery/validate'], function (Squire, ko, $) {
6060
),
6161
'Magento_Checkout/js/checkout-data': jasmine.createSpyObj(
6262
'checkoutData',
63-
['setSelectedShippingAddress', 'setNewCustomerShippingAddress', 'setSelectedShippingRate']
63+
[
64+
'setSelectedShippingAddress',
65+
'setNewCustomerShippingAddress',
66+
'setSelectedShippingRate',
67+
'getSelectedShippingRate'
68+
]
6469
),
6570
'Magento_Ui/js/lib/registry/registry': {
6671
async: jasmine.createSpy().and.returnValue(function () {}),

0 commit comments

Comments
 (0)