Skip to content

Commit 57a3231

Browse files
Merge pull request #8703 from magento-l3/PR_10_JAN_2024
[Tier 4] Bug fix delivery
2 parents a98a64a + 06ae79f commit 57a3231

File tree

17 files changed

+491
-99
lines changed

17 files changed

+491
-99
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\Catalog\Model\Category\Attribute\Backend;
18+
19+
class DefaultSortby extends Sortby
20+
{
21+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\Catalog\Setup\Patch\Data;
18+
19+
use Magento\Catalog\Setup\CategorySetup;
20+
use Magento\Catalog\Setup\CategorySetupFactory;
21+
use Magento\Framework\Setup\ModuleDataSetupInterface;
22+
use Magento\Framework\Setup\Patch\DataPatchInterface;
23+
use Magento\Framework\Setup\Patch\PatchInterface;
24+
25+
class UpdateDefaultSortyByBackendType implements DataPatchInterface
26+
{
27+
/**
28+
* @var ModuleDataSetupInterface
29+
*/
30+
private $moduleDataSetup;
31+
32+
/**
33+
* @var CategorySetupFactory
34+
*/
35+
private $categorySetupFactory;
36+
37+
/**
38+
* PatchInitial constructor.
39+
* @param ModuleDataSetupInterface $moduleDataSetup
40+
* @param CategorySetupFactory $categorySetupFactory
41+
*/
42+
public function __construct(
43+
ModuleDataSetupInterface $moduleDataSetup,
44+
CategorySetupFactory $categorySetupFactory
45+
) {
46+
$this->moduleDataSetup = $moduleDataSetup;
47+
$this->categorySetupFactory = $categorySetupFactory;
48+
}
49+
50+
/**
51+
* @inheritdoc
52+
*/
53+
public function apply(): UpdateDefaultSortyByBackendType
54+
{
55+
$mediaBackendModel = \Magento\Catalog\Model\Category\Attribute\Backend\DefaultSortby::class;
56+
/** @var CategorySetup $categorySetup */
57+
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
58+
$categorySetup->updateAttribute(
59+
'catalog_category',
60+
'default_sort_by',
61+
'backend_model',
62+
$mediaBackendModel
63+
);
64+
65+
return $this;
66+
}
67+
68+
/**
69+
* @inheritdoc
70+
*/
71+
public static function getDependencies()
72+
{
73+
return [];
74+
}
75+
76+
/**
77+
* @inheritdoc
78+
*/
79+
public function getAliases()
80+
{
81+
return [];
82+
}
83+
}

app/code/Magento/Catalog/Test/Fixture/Category.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Category implements RevertibleDataFixtureInterface
2727
'include_in_menu' => true,
2828
'available_sort_by' => [],
2929
'custom_attributes' => [
30-
'default_sort_by' => ['name']
30+
'default_sort_by' => 'position'
3131
],
3232
'extension_attributes' => [],
3333
'created_at' => null,

app/code/Magento/Catalog/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@
740740
<item name="Magento\Catalog\Model\Product\Attribute\Backend\Category" xsi:type="string">int[]</item>
741741
<item name="Magento\Catalog\Model\Product\Attribute\Backend\Stock" xsi:type="string">Magento\CatalogInventory\Api\Data\StockItemInterface[]</item>
742742
<item name="Magento\Catalog\Model\Category\Attribute\Backend\Sortby" xsi:type="string">string[]</item>
743+
<item name="Magento\Catalog\Model\Category\Attribute\Backend\DefaultSortby" xsi:type="string">string</item>
743744
</argument>
744745
</arguments>
745746
</type>

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

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66

77
namespace Magento\CheckoutAgreements\Model\Checkout\Plugin;
88

9+
use Magento\Checkout\Api\AgreementsValidatorInterface;
10+
use Magento\Checkout\Api\GuestPaymentInformationManagementInterface;
11+
use Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface;
912
use Magento\CheckoutAgreements\Model\AgreementsProvider;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\Exception\CouldNotSaveException;
15+
use Magento\Framework\Exception\NoSuchEntityException;
16+
use Magento\Quote\Api\Data\AddressInterface;
17+
use Magento\Quote\Api\Data\PaymentInterface;
18+
use Magento\Quote\Api\GuestCartRepositoryInterface;
19+
use Magento\Store\Model\App\Emulation;
1020
use Magento\Store\Model\ScopeInterface;
1121
use Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter;
1222

@@ -40,62 +50,85 @@ class GuestValidation
4050
private $activeStoreAgreementsFilter;
4151

4252
/**
43-
* @param \Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator
44-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration
45-
* @param \Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface $checkoutAgreementsList
53+
* @var GuestCartRepositoryInterface
54+
*/
55+
private GuestCartRepositoryInterface $quoteRepository;
56+
57+
/**
58+
* @var Emulation
59+
*/
60+
private Emulation $storeEmulation;
61+
62+
/**
63+
* @param AgreementsValidatorInterface $agreementsValidator
64+
* @param ScopeConfigInterface $scopeConfiguration
65+
* @param CheckoutAgreementsListInterface $checkoutAgreementsList
4666
* @param ActiveStoreAgreementsFilter $activeStoreAgreementsFilter
67+
* @param GuestCartRepositoryInterface $quoteRepository
68+
* @param Emulation $storeEmulation
4769
*/
4870
public function __construct(
4971
\Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator,
5072
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration,
5173
\Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface $checkoutAgreementsList,
52-
\Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter $activeStoreAgreementsFilter
74+
\Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter $activeStoreAgreementsFilter,
75+
GuestCartRepositoryInterface $quoteRepository,
76+
Emulation $storeEmulation
5377
) {
5478
$this->agreementsValidator = $agreementsValidator;
5579
$this->scopeConfiguration = $scopeConfiguration;
5680
$this->checkoutAgreementsList = $checkoutAgreementsList;
5781
$this->activeStoreAgreementsFilter = $activeStoreAgreementsFilter;
82+
$this->quoteRepository = $quoteRepository;
83+
$this->storeEmulation = $storeEmulation;
5884
}
5985

6086
/**
6187
* Validates agreements before save payment information and order placing.
6288
*
63-
* @param \Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject
89+
* @param GuestPaymentInformationManagementInterface $subject
6490
* @param string $cartId
6591
* @param string $email
66-
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
67-
* @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
68-
* @throws \Magento\Framework\Exception\CouldNotSaveException
92+
* @param PaymentInterface $paymentMethod
93+
* @param AddressInterface|null $billingAddress
6994
* @return void
7095
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
96+
* @throws CouldNotSaveException|NoSuchEntityException
7197
*/
7298
public function beforeSavePaymentInformationAndPlaceOrder(
73-
\Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject,
99+
GuestPaymentInformationManagementInterface $subject,
74100
$cartId,
75101
$email,
76-
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
77-
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
102+
PaymentInterface $paymentMethod,
103+
AddressInterface $billingAddress = null
78104
) {
79105
if ($this->isAgreementEnabled()) {
80-
$this->validateAgreements($paymentMethod);
106+
$quote = $this->quoteRepository->get($cartId);
107+
$storeId = $quote->getStoreId();
108+
$this->validateAgreements($paymentMethod, $storeId);
81109
}
82110
}
83111

84112
/**
85113
* Validates agreements.
86114
*
87-
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
88-
* @throws \Magento\Framework\Exception\CouldNotSaveException
115+
* @param PaymentInterface $paymentMethod
116+
* @param int $storeId
89117
* @return void
118+
* @throws CouldNotSaveException
90119
*/
91-
private function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod)
120+
private function validateAgreements(PaymentInterface $paymentMethod, int $storeId)
92121
{
93122
$agreements = $paymentMethod->getExtensionAttributes() === null
94123
? []
95124
: $paymentMethod->getExtensionAttributes()->getAgreementIds();
96125

97-
if (!$this->agreementsValidator->isValid($agreements)) {
98-
throw new \Magento\Framework\Exception\CouldNotSaveException(
126+
$this->storeEmulation->startEnvironmentEmulation($storeId);
127+
$isValid = $this->agreementsValidator->isValid($agreements);
128+
$this->storeEmulation->stopEnvironmentEmulation();
129+
130+
if (!$isValid) {
131+
throw new CouldNotSaveException(
99132
__(
100133
"The order wasn't placed. "
101134
. "First, agree to the terms and conditions, then try placing your order again."

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

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@
66

77
namespace Magento\CheckoutAgreements\Model\Checkout\Plugin;
88

9+
use Magento\Checkout\Api\AgreementsValidatorInterface;
10+
use Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface;
911
use Magento\CheckoutAgreements\Model\AgreementsProvider;
1012
use Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter;
13+
use Magento\CheckoutAgreements\Model\EmulateStore;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
15+
use Magento\Framework\Exception\CouldNotSaveException;
1116
use Magento\Quote\Api\CartRepositoryInterface;
17+
use Magento\Quote\Api\Data\PaymentInterface;
18+
use Magento\Store\Model\App\Emulation;
1219
use Magento\Store\Model\ScopeInterface;
1320

1421
/**
@@ -37,31 +44,37 @@ class Validation
3744
private $activeStoreAgreementsFilter;
3845

3946
/**
40-
* Quote repository.
41-
*
4247
* @var \Magento\Quote\Api\CartRepositoryInterface
4348
*/
4449
private $quoteRepository;
4550

4651
/**
47-
* @param \Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator
48-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration
49-
* @param \Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface $checkoutAgreementsList
52+
* @var Emulation
53+
*/
54+
private Emulation $storeEmulation;
55+
56+
/**
57+
* @param AgreementsValidatorInterface $agreementsValidator
58+
* @param ScopeConfigInterface $scopeConfiguration
59+
* @param CheckoutAgreementsListInterface $checkoutAgreementsList
5060
* @param ActiveStoreAgreementsFilter $activeStoreAgreementsFilter
5161
* @param CartRepositoryInterface $quoteRepository
62+
* @param Emulation $storeEmulation
5263
*/
5364
public function __construct(
5465
\Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator,
5566
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration,
5667
\Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface $checkoutAgreementsList,
5768
\Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter $activeStoreAgreementsFilter,
58-
CartRepositoryInterface $quoteRepository
69+
CartRepositoryInterface $quoteRepository,
70+
Emulation $storeEmulation
5971
) {
6072
$this->agreementsValidator = $agreementsValidator;
6173
$this->scopeConfiguration = $scopeConfiguration;
6274
$this->checkoutAgreementsList = $checkoutAgreementsList;
6375
$this->activeStoreAgreementsFilter = $activeStoreAgreementsFilter;
6476
$this->quoteRepository = $quoteRepository;
77+
$this->storeEmulation = $storeEmulation;
6578
}
6679

6780
/**
@@ -82,24 +95,31 @@ public function beforeSavePaymentInformationAndPlaceOrder(
8295
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
8396
) {
8497
if ($this->isAgreementEnabled()) {
85-
$this->validateAgreements($paymentMethod);
98+
$quote = $this->quoteRepository->get($cartId);
99+
$storeId = $quote->getStoreId();
100+
$this->validateAgreements($paymentMethod, $storeId);
86101
}
87102
}
88103

89104
/**
90105
* Validate agreements base on the payment method
91106
*
92-
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
93-
* @throws \Magento\Framework\Exception\CouldNotSaveException
107+
* @param PaymentInterface $paymentMethod
108+
* @param int $storeId
94109
* @return void
110+
* @throws CouldNotSaveException
95111
*/
96-
protected function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod)
112+
private function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod, int $storeId)
97113
{
98114
$agreements = $paymentMethod->getExtensionAttributes() === null
99115
? []
100116
: $paymentMethod->getExtensionAttributes()->getAgreementIds();
101117

102-
if (!$this->agreementsValidator->isValid($agreements)) {
118+
$this->storeEmulation->startEnvironmentEmulation($storeId);
119+
$isValid = $this->agreementsValidator->isValid($agreements);
120+
$this->storeEmulation->stopEnvironmentEmulation();
121+
122+
if (!$isValid) {
103123
throw new \Magento\Framework\Exception\CouldNotSaveException(
104124
__(
105125
"The order wasn't placed. "

0 commit comments

Comments
 (0)