Skip to content

Commit b6880b2

Browse files
MC-23986: Cart price rule based on payment methods not aplied in checkout
1 parent 0ff7d22 commit b6880b2

File tree

20 files changed

+346
-192
lines changed

20 files changed

+346
-192
lines changed

app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCheckoutWithDifferentShippingAndBillingAddressAndProductWithTierPricesTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<checkOption selector="{{CheckoutPaymentSection.bankTransfer}}" stepKey="selectBankTransfer"/>
7878
<waitForElementVisible selector="{{CheckoutPaymentSection.billingAddressNotSameBankTransferCheckbox}}" stepKey="waitForElementToBeVisible"/>
7979
<uncheckOption selector="{{CheckoutPaymentSection.billingAddressNotSameBankTransferCheckbox}}" stepKey="uncheckSameBillingAndShippingAddress"/>
80+
<waitForElementVisible selector="{{CheckoutShippingSection.editActiveAddressButton}}" stepKey="waitForEditButtonToBeVisible"/>
8081
<conditionalClick selector="{{CheckoutShippingSection.editActiveAddressButton}}" dependentSelector="{{CheckoutShippingSection.editActiveAddressButton}}" visible="true" stepKey="clickEditButton"/>
8182
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
8283

app/code/Magento/Checkout/Test/Mftf/Test/StorefrontNotApplicableShippingMethodInReviewAndPaymentStepTest.xml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727
<magentoCLI command="config:set {{AdminFreeshippingActiveConfigData.path}} {{AdminFreeshippingActiveConfigData.enabled}}" stepKey="enableFreeShippingMethod" />
2828
<magentoCLI command="config:set {{AdminFreeshippingMinimumOrderAmountConfigData.path}} {{AdminFreeshippingMinimumOrderAmountConfigData.hundred}}" stepKey="setFreeShippingMethodMinimumOrderAmountToBe100" />
2929

30-
<!--Set Fedex configs data-->
31-
<magentoCLI command="config:set {{AdminFedexEnableForCheckoutConfigData.path}} {{AdminFedexEnableForCheckoutConfigData.value}}" stepKey="enableCheckout"/>
32-
<magentoCLI command="config:set {{AdminFedexEnableSandboxModeConfigData.path}} {{AdminFedexEnableSandboxModeConfigData.value}}" stepKey="enableSandbox"/>
33-
<magentoCLI command="config:set {{AdminFedexEnableDebugConfigData.path}} {{AdminFedexEnableDebugConfigData.value}}" stepKey="enableDebug"/>
34-
<magentoCLI command="config:set {{AdminFedexEnableShowMethodConfigData.path}} {{AdminFedexEnableShowMethodConfigData.value}}" stepKey="enableShowMethod"/>
35-
3630
<!--Set StoreInformation configs data-->
3731
<magentoCLI command="config:set {{AdminGeneralSetStoreNameConfigData.path}} '{{AdminGeneralSetStoreNameConfigData.value}}'" stepKey="setStoreInformationName"/>
3832
<magentoCLI command="config:set {{AdminGeneralSetStorePhoneConfigData.path}} {{DE_Address_Berlin_Not_Default_Address.telephone}}" stepKey="setStoreInformationPhone"/>
@@ -75,10 +69,6 @@
7569
<magentoCLI command="config:set {{AdminFreeshippingMinimumOrderAmountConfigData.path}} {{AdminFreeshippingMinimumOrderAmountConfigData.default}}" stepKey="setFreeShippingMethodMinimumOrderAmountAsDefault" />
7670
<magentoCLI command="config:set {{AdminFreeshippingActiveConfigData.path}} {{AdminFreeshippingActiveConfigData.disabled}}" stepKey="disableFreeShippingMethod" />
7771
<!--Reset configs-->
78-
<magentoCLI command="config:set {{AdminFedexDisableForCheckoutConfigData.path}} {{AdminFedexDisableForCheckoutConfigData.value}}" stepKey="disableCheckout"/>
79-
<magentoCLI command="config:set {{AdminFedexDisableSandboxModeConfigData.path}} {{AdminFedexDisableSandboxModeConfigData.value}}" stepKey="disableSandbox"/>
80-
<magentoCLI command="config:set {{AdminFedexDisableDebugConfigData.path}} {{AdminFedexDisableDebugConfigData.value}}" stepKey="disableDebug"/>
81-
<magentoCLI command="config:set {{AdminFedexDisableShowMethodConfigData.path}} {{AdminFedexDisableShowMethodConfigData.value}}" stepKey="disableShowMethod"/>
8272
<magentoCLI command="config:set {{AdminGeneralSetStoreNameConfigData.path}} ''" stepKey="setStoreInformationName"/>
8373
<magentoCLI command="config:set {{AdminGeneralSetStorePhoneConfigData.path}} ''" stepKey="setStoreInformationPhone"/>
8474
<magentoCLI command="config:set {{AdminGeneralSetCityConfigData.path}} ''" stepKey="setStoreInformationCity"/>
@@ -187,7 +177,7 @@
187177
<!-- Assert Shipping total is not yet calculated -->
188178
<actionGroup ref="AssertStorefrontNotCalculatedValueInShippingTotalInOrderSummaryActionGroup" stepKey="assertNotYetCalculated2"/>
189179

190-
<!-- Assert order cannot be placed and error message will shown. -->
180+
<!-- Assert order cannot be placed and error message will shown. -->
191181
<actionGroup ref="AssertStorefrontOrderCannotBePlacedActionGroup" stepKey="assertOrderCannotBePlaced2">
192182
<argument name="error" value="The shipping method is missing. Select the shipping method and try again."/>
193183
</actionGroup>

app/code/Magento/Checkout/view/frontend/web/js/action/select-payment-method.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @api
88
*/
99
define([
10-
'../model/quote'
10+
'Magento_Checkout/js/model/quote'
1111
], function (quote) {
1212
'use strict';
1313

app/code/Magento/CheckoutAgreements/Model/Checkout/Plugin/GuestValidation.php

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter;
1212

1313
/**
14-
* Class GuestValidation
14+
* Guest checkout agreements validation.
1515
*
1616
* Plugin that checks if checkout agreement enabled and validates all agreements.
1717
* Current plugin is duplicate from Magento\CheckoutAgreements\Model\Checkout\Plugin\Validation due to different
@@ -58,6 +58,8 @@ public function __construct(
5858
}
5959

6060
/**
61+
* Validates agreements before save payment information and order placing.
62+
*
6163
* @param \Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject
6264
* @param string $cartId
6365
* @param string $email
@@ -80,28 +82,8 @@ public function beforeSavePaymentInformationAndPlaceOrder(
8082
}
8183

8284
/**
83-
* @param \Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject
84-
* @param string $cartId
85-
* @param string $email
86-
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
87-
* @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
88-
* @throws \Magento\Framework\Exception\CouldNotSaveException
89-
* @return void
90-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
91-
*/
92-
public function beforeSavePaymentInformation(
93-
\Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject,
94-
$cartId,
95-
$email,
96-
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
97-
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
98-
) {
99-
if ($this->isAgreementEnabled()) {
100-
$this->validateAgreements($paymentMethod);
101-
}
102-
}
103-
104-
/**
85+
* Validates agreements.
86+
*
10587
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
10688
* @throws \Magento\Framework\Exception\CouldNotSaveException
10789
* @return void
@@ -123,7 +105,8 @@ private function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $pa
123105
}
124106

125107
/**
126-
* Verify if agreement validation needed
108+
* Verify if agreement validation needed.
109+
*
127110
* @return bool
128111
*/
129112
private function isAgreementEnabled()

app/code/Magento/CheckoutAgreements/Model/Checkout/Plugin/Validation.php

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
use Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter;
1212

1313
/**
14-
* Class Validation
14+
* Checkout agreements validation.
1515
*/
1616
class Validation
1717
{
1818
/**
1919
* @var \Magento\Framework\App\Config\ScopeConfigInterface
2020
*/
21-
protected $scopeConfiguration;
21+
private $scopeConfiguration;
2222

2323
/**
2424
* @var \Magento\Checkout\Api\AgreementsValidatorInterface
2525
*/
26-
protected $agreementsValidator;
26+
private $agreementsValidator;
2727

2828
/**
2929
* @var \Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface
@@ -54,6 +54,8 @@ public function __construct(
5454
}
5555

5656
/**
57+
* Validates agreements before save payment information and order placing.
58+
*
5759
* @param \Magento\Checkout\Api\PaymentInformationManagementInterface $subject
5860
* @param int $cartId
5961
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
@@ -74,31 +76,13 @@ public function beforeSavePaymentInformationAndPlaceOrder(
7476
}
7577

7678
/**
77-
* @param \Magento\Checkout\Api\PaymentInformationManagementInterface $subject
78-
* @param int $cartId
79-
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
80-
* @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
81-
* @throws \Magento\Framework\Exception\CouldNotSaveException
82-
* @return void
83-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
84-
*/
85-
public function beforeSavePaymentInformation(
86-
\Magento\Checkout\Api\PaymentInformationManagementInterface $subject,
87-
$cartId,
88-
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
89-
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
90-
) {
91-
if ($this->isAgreementEnabled()) {
92-
$this->validateAgreements($paymentMethod);
93-
}
94-
}
95-
96-
/**
79+
* Validates agreements.
80+
*
9781
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
9882
* @throws \Magento\Framework\Exception\CouldNotSaveException
9983
* @return void
10084
*/
101-
protected function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod)
85+
private function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod)
10286
{
10387
$agreements = $paymentMethod->getExtensionAttributes() === null
10488
? []
@@ -115,10 +99,11 @@ protected function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $
11599
}
116100

117101
/**
118-
* Verify if agreement validation needed
102+
* Verify if agreement validation needed.
103+
*
119104
* @return bool
120105
*/
121-
protected function isAgreementEnabled()
106+
private function isAgreementEnabled()
122107
{
123108
$isAgreementsEnabled = $this->scopeConfiguration->isSetFlag(
124109
AgreementsProvider::PATH_ENABLED,

app/code/Magento/CheckoutAgreements/Test/Unit/Model/Checkout/Plugin/GuestValidationTest.php

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Store\Model\ScopeInterface;
1111

1212
/**
13-
* Class GuestValidationTest
1413
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1514
*/
1615
class GuestValidationTest extends \PHPUnit\Framework\TestCase
@@ -109,7 +108,7 @@ public function testBeforeSavePaymentInformationAndPlaceOrder()
109108
$this->paymentMock->expects(static::atLeastOnce())
110109
->method('getExtensionAttributes')
111110
->willReturn($this->extensionAttributesMock);
112-
$this->model->beforeSavePaymentInformation(
111+
$this->model->beforeSavePaymentInformationAndPlaceOrder(
113112
$this->subjectMock,
114113
$cartId,
115114
$email,
@@ -144,7 +143,7 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
144143
$this->paymentMock->expects(static::atLeastOnce())
145144
->method('getExtensionAttributes')
146145
->willReturn($this->extensionAttributesMock);
147-
$this->model->beforeSavePaymentInformation(
146+
$this->model->beforeSavePaymentInformationAndPlaceOrder(
148147
$this->subjectMock,
149148
$cartId,
150149
$email,
@@ -156,36 +155,4 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
156155
"The order wasn't placed. First, agree to the terms and conditions, then try placing your order again."
157156
);
158157
}
159-
160-
public function testBeforeSavePaymentInformation()
161-
{
162-
$cartId = 100;
163-
$email = 'email@example.com';
164-
$agreements = [1, 2, 3];
165-
$this->scopeConfigMock
166-
->expects($this->once())
167-
->method('isSetFlag')
168-
->with(AgreementsProvider::PATH_ENABLED, ScopeInterface::SCOPE_STORE)
169-
->willReturn(true);
170-
$searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteria::class);
171-
$this->agreementsFilterMock->expects($this->once())
172-
->method('buildSearchCriteria')
173-
->willReturn($searchCriteriaMock);
174-
$this->checkoutAgreementsListMock->expects($this->once())
175-
->method('getList')
176-
->with($searchCriteriaMock)
177-
->willReturn([1]);
178-
$this->extensionAttributesMock->expects($this->once())->method('getAgreementIds')->willReturn($agreements);
179-
$this->agreementsValidatorMock->expects($this->once())->method('isValid')->with($agreements)->willReturn(true);
180-
$this->paymentMock->expects(static::atLeastOnce())
181-
->method('getExtensionAttributes')
182-
->willReturn($this->extensionAttributesMock);
183-
$this->model->beforeSavePaymentInformation(
184-
$this->subjectMock,
185-
$cartId,
186-
$email,
187-
$this->paymentMock,
188-
$this->addressMock
189-
);
190-
}
191158
}

app/code/Magento/CheckoutAgreements/Test/Unit/Model/Checkout/Plugin/ValidationTest.php

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Store\Model\ScopeInterface;
1111

1212
/**
13-
* Class ValidationTest
1413
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1514
*/
1615
class ValidationTest extends \PHPUnit\Framework\TestCase
@@ -108,7 +107,12 @@ public function testBeforeSavePaymentInformationAndPlaceOrder()
108107
$this->paymentMock->expects(static::atLeastOnce())
109108
->method('getExtensionAttributes')
110109
->willReturn($this->extensionAttributesMock);
111-
$this->model->beforeSavePaymentInformation($this->subjectMock, $cartId, $this->paymentMock, $this->addressMock);
110+
$this->model->beforeSavePaymentInformationAndPlaceOrder(
111+
$this->subjectMock,
112+
$cartId,
113+
$this->paymentMock,
114+
$this->addressMock
115+
);
112116
}
113117

114118
/**
@@ -136,35 +140,15 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
136140
$this->paymentMock->expects(static::atLeastOnce())
137141
->method('getExtensionAttributes')
138142
->willReturn($this->extensionAttributesMock);
139-
$this->model->beforeSavePaymentInformation($this->subjectMock, $cartId, $this->paymentMock, $this->addressMock);
143+
$this->model->beforeSavePaymentInformationAndPlaceOrder(
144+
$this->subjectMock,
145+
$cartId,
146+
$this->paymentMock,
147+
$this->addressMock
148+
);
140149

141150
$this->expectExceptionMessage(
142151
"The order wasn't placed. First, agree to the terms and conditions, then try placing your order again."
143152
);
144153
}
145-
146-
public function testBeforeSavePaymentInformation()
147-
{
148-
$cartId = 100;
149-
$agreements = [1, 2, 3];
150-
$this->scopeConfigMock
151-
->expects($this->once())
152-
->method('isSetFlag')
153-
->with(AgreementsProvider::PATH_ENABLED, ScopeInterface::SCOPE_STORE)
154-
->willReturn(true);
155-
$searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteria::class);
156-
$this->agreementsFilterMock->expects($this->once())
157-
->method('buildSearchCriteria')
158-
->willReturn($searchCriteriaMock);
159-
$this->checkoutAgreementsListMock->expects($this->once())
160-
->method('getList')
161-
->with($searchCriteriaMock)
162-
->willReturn([1]);
163-
$this->extensionAttributesMock->expects($this->once())->method('getAgreementIds')->willReturn($agreements);
164-
$this->agreementsValidatorMock->expects($this->once())->method('isValid')->with($agreements)->willReturn(true);
165-
$this->paymentMock->expects(static::atLeastOnce())
166-
->method('getExtensionAttributes')
167-
->willReturn($this->extensionAttributesMock);
168-
$this->model->beforeSavePaymentInformation($this->subjectMock, $cartId, $this->paymentMock, $this->addressMock);
169-
}
170154
}

0 commit comments

Comments
 (0)