Skip to content

Commit 247383a

Browse files
committed
Merge branch '2.4-develop' of https://github.com/magento-commerce/magento2ce into PR-L3-2023-07-14
2 parents bb23276 + 3cc15fb commit 247383a

File tree

12 files changed

+102
-241
lines changed

12 files changed

+102
-241
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
}),

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class QuoteManagement implements CartManagementInterface, ResetAfterRequestInter
5555
{
5656
private const LOCK_PREFIX = 'PLACE_ORDER_';
5757

58-
private const LOCK_TIMEOUT = 10;
58+
private const LOCK_TIMEOUT = 0;
5959

6060
/**
6161
* @var EventManager
@@ -615,13 +615,12 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
615615
);
616616

617617
$lockedName = self::LOCK_PREFIX . $quote->getId();
618-
if ($this->lockManager->isLocked($lockedName)) {
618+
if (!$this->lockManager->lock($lockedName, self::LOCK_TIMEOUT)) {
619619
throw new LocalizedException(__(
620620
'A server error stopped your order from being placed. Please try to place your order again.'
621621
));
622622
}
623623
try {
624-
$this->lockManager->lock($lockedName, self::LOCK_TIMEOUT);
625624
$order = $this->orderManagement->place($order);
626625
$quote->setIsActive(false);
627626
$this->eventManager->dispatch(
@@ -632,7 +631,6 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
632631
]
633632
);
634633
$this->quoteRepository->save($quote);
635-
$this->lockManager->unlock($lockedName);
636634
} catch (\Exception $e) {
637635
$this->lockManager->unlock($lockedName);
638636
$this->rollbackAddresses($quote, $order, $e);

app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ public function testSubmit(): void
837837
['order' => $order, 'quote' => $quote]
838838
]
839839
);
840-
$this->lockManagerMock->method('isLocked')->willReturn(false);
840+
$this->lockManagerMock->method('lock')->willReturn(true);
841841
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($quote);
842842
$this->assertEquals($order, $this->model->submit($quote, $orderData));
843843
}
@@ -1378,6 +1378,7 @@ public function testSubmitForCustomer(): void
13781378
['order' => $order, 'quote' => $quote]
13791379
]
13801380
);
1381+
$this->lockManagerMock->method('lock')->willReturn(true);
13811382
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($quote);
13821383
$this->assertEquals($order, $this->model->submit($quote, $orderData));
13831384
}
@@ -1501,7 +1502,7 @@ public function testSubmitWithLockException(): void
15011502
['order' => $order, 'quote' => $quote]
15021503
]
15031504
);
1504-
$this->lockManagerMock->method('isLocked')->willReturn(true);
1505+
$this->lockManagerMock->method('lock')->willReturn(false);
15051506

15061507
$this->expectExceptionMessage(
15071508
'A server error stopped your order from being placed. Please try to place your order again.'

app/code/Magento/QuoteGraphQl/Model/Cart/PlaceOrderMutex.php

Lines changed: 0 additions & 72 deletions
This file was deleted.

app/code/Magento/QuoteGraphQl/Model/Cart/PlaceOrderMutexInterface.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

app/code/Magento/QuoteGraphQl/Model/Resolver/PlaceOrder.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\QuoteGraphQl\Model\Resolver;
99

10-
use Magento\Framework\App\ObjectManager;
1110
use Magento\Framework\Exception\LocalizedException;
1211
use Magento\Framework\GraphQl\Config\Element\Field;
1312
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
@@ -17,7 +16,6 @@
1716
use Magento\QuoteGraphQl\Model\Cart\GetCartForCheckout;
1817
use Magento\GraphQl\Model\Query\ContextInterface;
1918
use Magento\QuoteGraphQl\Model\Cart\PlaceOrder as PlaceOrderModel;
20-
use Magento\QuoteGraphQl\Model\Cart\PlaceOrderMutexInterface;
2119
use Magento\Sales\Api\OrderRepositoryInterface;
2220

2321
/**
@@ -45,30 +43,22 @@ class PlaceOrder implements ResolverInterface
4543
*/
4644
private $errorMessageFormatter;
4745

48-
/**
49-
* @var PlaceOrderMutexInterface
50-
*/
51-
private $placeOrderMutex;
52-
5346
/**
5447
* @param GetCartForCheckout $getCartForCheckout
5548
* @param PlaceOrderModel $placeOrder
5649
* @param OrderRepositoryInterface $orderRepository
5750
* @param AggregateExceptionMessageFormatter $errorMessageFormatter
58-
* @param PlaceOrderMutexInterface|null $placeOrderMutex
5951
*/
6052
public function __construct(
6153
GetCartForCheckout $getCartForCheckout,
6254
PlaceOrderModel $placeOrder,
6355
OrderRepositoryInterface $orderRepository,
64-
AggregateExceptionMessageFormatter $errorMessageFormatter,
65-
?PlaceOrderMutexInterface $placeOrderMutex = null
56+
AggregateExceptionMessageFormatter $errorMessageFormatter
6657
) {
6758
$this->getCartForCheckout = $getCartForCheckout;
6859
$this->placeOrder = $placeOrder;
6960
$this->orderRepository = $orderRepository;
7061
$this->errorMessageFormatter = $errorMessageFormatter;
71-
$this->placeOrderMutex = $placeOrderMutex ?: ObjectManager::getInstance()->get(PlaceOrderMutexInterface::class);
7262
}
7363

7464
/**
@@ -80,25 +70,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8070
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
8171
}
8272

83-
return $this->placeOrderMutex->execute(
84-
$args['input']['cart_id'],
85-
\Closure::fromCallable([$this, 'run']),
86-
[$field, $context, $info, $args]
87-
);
88-
}
89-
90-
/**
91-
* Run the resolver.
92-
*
93-
* @param Field $field
94-
* @param ContextInterface $context
95-
* @param ResolveInfo $info
96-
* @param array|null $args
97-
* @return array[]
98-
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
99-
*/
100-
private function run(Field $field, ContextInterface $context, ResolveInfo $info, ?array $args): array
101-
{
10273
$maskedCartId = $args['input']['cart_id'];
10374
$userId = (int)$context->getUserId();
10475
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();

0 commit comments

Comments
 (0)