Skip to content

Commit 3b397a9

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop
Accepted Community Pull Requests: - #31776: Removed CliIndexerReindexActionGroup action group usage for Customer module (by @sergiy-v) - #31788: Removed CliIndexerReindexActionGroup action group usage for Sales module (by @sergiy-v) - #31507: [MFTF] Refactoring AdminMassOrdersCancelProcessingAndClosedTest (by @AnnaAPak) - #30883: Remove recursion in location of static files. (by @edspc) - #31636: Moving array access for CAPTCHA _.isEmpty check (by @MellenIO) - #31604: [MFTF] Adding AdminClickCreateNewStatusButtonOnOrderStatusPageActionGroup (by @AnnaAPak) - #31485: Fix delete special prices only for specified store (by @engcom-Charlie) - #31512: [MFTF] Refactoring AdminMassOrdersUpdateCancelPendingOrderTest (by @AnnaAPak) - #31502: [MFTF] Refactoring AdminPanelIsFrozenIfStorefrontIsOpenedViaCustomerViewTest (by @AnnaAPak) - #31510: [MFTF] Refactoring AdminMassOrdersHoldOnCompleteTest (by @AnnaAPak) - #31454: [MFTF] Adding AdminFillTaxIdentifierFilterOnTaxRateGridActionGroup (by @AnnaAPak) - #31488: [MFTF] Refactoring AdminValidateShippingTrackingNumberTest (by @AnnaAPak) - #30943: FIX Perfomance Issue for Backend EDIT of CMS #30936 (by @larsroettig) - #31299: fix reference layout cms_noroute_index core (by @PierW) - #30871: Update sortOrder load for async css plugin (by @mrtuvn) - #29804: Fixed Unable to apply data patch issue after upgrade in 2.4 #29365 (by @ravi-chandra3197) Fixed GitHub Issues: - #31801: [Issue] Removed CliIndexerReindexActionGroup action group usage for Sales module (reported by @m2-assistant[bot]) has been fixed in #31788 by @sergiy-v in 2.4-develop branch Related commits: 1. 9dd746a - #31517: [Issue] [MFTF] Refactoring AdminMassOrdersCancelProcessingAndClosedTest (reported by @m2-assistant[bot]) has been fixed in #31507 by @AnnaAPak in 2.4-develop branch Related commits: 1. 7c478a9 - #31530: [Issue] Remove recursion in location of static files. (reported by @m2-assistant[bot]) has been fixed in #30883 by @edspc in 2.4-develop branch Related commits: 1. 9f3ab3a 2. dc1662d - #31641: [Issue] Moving array access for CAPTCHA _.isEmpty check (reported by @m2-assistant[bot]) has been fixed in #31636 by @MellenIO in 2.4-develop branch Related commits: 1. 36c031a - #31623: [Issue] [MFTF] Adding AdminClickCreateNewStatusButtonOnOrderStatusPageActionGroup (reported by @m2-assistant[bot]) has been fixed in #31604 by @AnnaAPak in 2.4-develop branch Related commits: 1. 031c1dd 2. 1666c33 3. 2f31728 - #25907: CatalogSpecialPriceStorage API delete does not delete by store id (reported by @nthurston) has been fixed in #31485 by @engcom-Charlie in 2.4-develop branch Related commits: 1. de30e9c 2. 8f843ef 3. 8fccf46 4. 287084c 5. d30fea0 6. cb230b5 7. 9e51c8e 8. 2d56b2e - #31514: [Issue] [MFTF] Refactoring AdminMassOrdersUpdateCancelPendingOrderTest (reported by @m2-assistant[bot]) has been fixed in #31512 by @AnnaAPak in 2.4-develop branch Related commits: 1. 7aea8c5 2. 7befff5 - #31519: [Issue] [MFTF] Refactoring AdminPanelIsFrozenIfStorefrontIsOpenedViaCustomerViewTest (reported by @m2-assistant[bot]) has been fixed in #31502 by @AnnaAPak in 2.4-develop branch Related commits: 1. e840a57 2. 68cd8a8 - #31515: [Issue] [MFTF] Refactoring AdminMassOrdersHoldOnCompleteTest (reported by @m2-assistant[bot]) has been fixed in #31510 by @AnnaAPak in 2.4-develop branch Related commits: 1. 9efb105 2. 4ff32df - #31520: [Issue] [MFTF] Refactoring AdminValidateShippingTrackingNumberTest (reported by @m2-assistant[bot]) has been fixed in #31488 by @AnnaAPak in 2.4-develop branch Related commits: 1. 0406e76 2. 7cedea5 3. e00dec7 - #30936: Perfomance:Cms/Model/Page/DataProvider.php#L103 loads full collection without any filter (reported by @larsroettig) has been fixed in #30943 by @larsroettig in 2.4-develop branch Related commits: 1. 94a7467 2. bb07bc0 3. 3819438 4. 3041fc6 5. b9987d1 6. 6de189f 7. 17d3895 8. cdecd30 9. 17316ae 10. 912374c 11. 8ca6c5a 12. 77ad90d 13. dc965fc 14. 65da3e6 15. a2327c9 16. 9ee832e 17. 2900e74 18. f11d277 - #31300: [Issue] fix reference layout cms_noroute_index core (reported by @m2-assistant[bot]) has been fixed in #31299 by @PierW in 2.4-develop branch Related commits: 1. 376676f - #30882: [Issue] Update sortOrder load for async css plugin (reported by @m2-assistant[bot]) has been fixed in #30871 by @mrtuvn in 2.4-develop branch Related commits: 1. cc6d016 - #29365: Magento 2.4 Upgrade issue Unable to apply data patch Magento\CatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts (reported by @sunel) has been fixed in #29804 by @ravi-chandra3197 in 2.4-develop branch Related commits: 1. b2b29ea 2. a06ec39 - #29805: Magento 2.4 upgrade fails if there is data under catalog_product_entity_varchar (reported by @HeiderSati) has been fixed in #29804 by @ravi-chandra3197 in 2.4-develop branch Related commits: 1. b2b29ea 2. a06ec39
2 parents f5c5db7 + 47e385d commit 3b397a9

File tree

72 files changed

+843
-478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+843
-478
lines changed

app/code/Magento/Captcha/view/frontend/web/js/view/checkout/defaultCaptcha.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ define([
5656
*/
5757
checkCustomerData: function (formId, captchaData, captcha) {
5858
if (!_.isEmpty(captchaData) &&
59-
!_.isEmpty(captchaData)[formId] &&
59+
!_.isEmpty(captchaData[formId]) &&
6060
captchaData[formId].timestamp > captcha.timestamp
6161
) {
6262
if (!captcha.isRequired() && captchaData[formId].isRequired) {

app/code/Magento/Catalog/Model/Product/Price/SpecialPriceStorage.php

+110-112
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,82 @@
66

77
namespace Magento\Catalog\Model\Product\Price;
88

9+
use Magento\Catalog\Api\Data\SpecialPriceInterface;
10+
use Magento\Catalog\Api\Data\SpecialPriceInterfaceFactory;
11+
use Magento\Catalog\Api\SpecialPriceStorageInterface;
12+
use Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor;
13+
use Magento\Catalog\Model\Product\Price\Validation\Result;
14+
use Magento\Catalog\Model\ProductIdLocatorInterface;
15+
use Magento\Framework\App\ObjectManager;
916
use Magento\Framework\Exception\NoSuchEntityException;
17+
use Magento\Catalog\Helper\Data;
18+
use Magento\Store\Api\StoreRepositoryInterface;
1019

1120
/**
1221
* Special price storage presents efficient price API and is used to retrieve, update or delete special prices.
22+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1323
*/
14-
class SpecialPriceStorage implements \Magento\Catalog\Api\SpecialPriceStorageInterface
24+
class SpecialPriceStorage implements SpecialPriceStorageInterface
1525
{
1626
/**
1727
* @var \Magento\Catalog\Api\SpecialPriceInterface
1828
*/
1929
private $specialPriceResource;
2030

2131
/**
22-
* @var \Magento\Catalog\Api\Data\SpecialPriceInterfaceFactory
32+
* @var SpecialPriceInterfaceFactory
2333
*/
2434
private $specialPriceFactory;
2535

2636
/**
27-
* @var \Magento\Catalog\Model\ProductIdLocatorInterface
37+
* @var ProductIdLocatorInterface
2838
*/
2939
private $productIdLocator;
3040

3141
/**
32-
* @var \Magento\Store\Api\StoreRepositoryInterface
42+
* @var StoreRepositoryInterface
3343
*/
3444
private $storeRepository;
3545

3646
/**
37-
* @var \Magento\Catalog\Model\Product\Price\Validation\Result
47+
* @var Result
3848
*/
3949
private $validationResult;
4050

4151
/**
42-
* @var \Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor
52+
* @var InvalidSkuProcessor
4353
*/
4454
private $invalidSkuProcessor;
4555

4656
/**
4757
* @var array
4858
*/
49-
private $allowedProductTypes = [];
59+
private $allowedProductTypes;
60+
61+
/**
62+
* @var Data
63+
*/
64+
private $catalogData;
5065

5166
/**
5267
* @param \Magento\Catalog\Api\SpecialPriceInterface $specialPriceResource
53-
* @param \Magento\Catalog\Api\Data\SpecialPriceInterfaceFactory $specialPriceFactory
54-
* @param \Magento\Catalog\Model\ProductIdLocatorInterface $productIdLocator
55-
* @param \Magento\Store\Api\StoreRepositoryInterface $storeRepository
56-
* @param \Magento\Catalog\Model\Product\Price\Validation\Result $validationResult
57-
* @param \Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor $invalidSkuProcessor
58-
* @param array $allowedProductTypes [optional]
68+
* @param SpecialPriceInterfaceFactory $specialPriceFactory
69+
* @param ProductIdLocatorInterface $productIdLocator
70+
* @param StoreRepositoryInterface $storeRepository
71+
* @param Result $validationResult
72+
* @param InvalidSkuProcessor $invalidSkuProcessor
73+
* @param array $allowedProductTypes
74+
* @param Data|null $catalogData
5975
*/
6076
public function __construct(
6177
\Magento\Catalog\Api\SpecialPriceInterface $specialPriceResource,
62-
\Magento\Catalog\Api\Data\SpecialPriceInterfaceFactory $specialPriceFactory,
63-
\Magento\Catalog\Model\ProductIdLocatorInterface $productIdLocator,
64-
\Magento\Store\Api\StoreRepositoryInterface $storeRepository,
65-
\Magento\Catalog\Model\Product\Price\Validation\Result $validationResult,
66-
\Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor $invalidSkuProcessor,
67-
array $allowedProductTypes = []
78+
SpecialPriceInterfaceFactory $specialPriceFactory,
79+
ProductIdLocatorInterface $productIdLocator,
80+
StoreRepositoryInterface $storeRepository,
81+
Result $validationResult,
82+
InvalidSkuProcessor $invalidSkuProcessor,
83+
array $allowedProductTypes = [],
84+
?Data $catalogData = null
6885
) {
6986
$this->specialPriceResource = $specialPriceResource;
7087
$this->specialPriceFactory = $specialPriceFactory;
@@ -73,10 +90,11 @@ public function __construct(
7390
$this->validationResult = $validationResult;
7491
$this->invalidSkuProcessor = $invalidSkuProcessor;
7592
$this->allowedProductTypes = $allowedProductTypes;
93+
$this->catalogData = $catalogData ?: ObjectManager::getInstance()->get(Data::class);
7694
}
7795

7896
/**
79-
* {@inheritdoc}
97+
* @inheritdoc
8098
*/
8199
public function get(array $skus)
82100
{
@@ -85,7 +103,7 @@ public function get(array $skus)
85103

86104
$prices = [];
87105
foreach ($rawPrices as $rawPrice) {
88-
/** @var \Magento\Catalog\Api\Data\SpecialPriceInterface $price */
106+
/** @var SpecialPriceInterface $price */
89107
$price = $this->specialPriceFactory->create();
90108
$sku = isset($rawPrice['sku'])
91109
? $rawPrice['sku']
@@ -102,7 +120,7 @@ public function get(array $skus)
102120
}
103121

104122
/**
105-
* {@inheritdoc}
123+
* @inheritdoc
106124
*/
107125
public function update(array $prices)
108126
{
@@ -113,7 +131,7 @@ public function update(array $prices)
113131
}
114132

115133
/**
116-
* {@inheritdoc}
134+
* @inheritdoc
117135
*/
118136
public function delete(array $prices)
119137
{
@@ -140,52 +158,14 @@ private function retrieveValidPrices(array $prices)
140158

141159
foreach ($prices as $key => $price) {
142160
if (!$price->getSku() || in_array($price->getSku(), $failedSkus)) {
143-
$this->validationResult->addFailedItem(
144-
$key,
145-
__(
146-
'The product that was requested doesn\'t exist. Verify the product and try again. '
147-
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.',
148-
[
149-
'SKU' => $price->getSku(),
150-
'storeId' => $price->getStoreId(),
151-
'priceFrom' => $price->getPriceFrom(),
152-
'priceTo' => $price->getPriceTo()
153-
]
154-
),
155-
[
156-
'SKU' => $price->getSku(),
157-
'storeId' => $price->getStoreId(),
158-
'priceFrom' => $price->getPriceFrom(),
159-
'priceTo' => $price->getPriceTo()
160-
]
161-
);
161+
$errorMessage = 'The product that was requested doesn\'t exist. Verify the product and try again. '
162+
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.';
163+
$this->addFailedItemPrice($price, $key, $errorMessage, []);
162164
}
165+
$this->checkStore($price, $key);
163166
$this->checkPrice($price, $key);
164167
$this->checkDate($price, $price->getPriceFrom(), 'Price From', $key);
165168
$this->checkDate($price, $price->getPriceTo(), 'Price To', $key);
166-
try {
167-
$this->storeRepository->getById($price->getStoreId());
168-
} catch (NoSuchEntityException $e) {
169-
$this->validationResult->addFailedItem(
170-
$key,
171-
__(
172-
'Requested store is not found. '
173-
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.',
174-
[
175-
'SKU' => $price->getSku(),
176-
'storeId' => $price->getStoreId(),
177-
'priceFrom' => $price->getPriceFrom(),
178-
'priceTo' => $price->getPriceTo()
179-
]
180-
),
181-
[
182-
'SKU' => $price->getSku(),
183-
'storeId' => $price->getStoreId(),
184-
'priceFrom' => $price->getPriceFrom(),
185-
'priceTo' => $price->getPriceTo()
186-
]
187-
);
188-
}
189169
}
190170

191171
foreach ($this->validationResult->getFailedRowIds() as $id) {
@@ -195,77 +175,95 @@ private function retrieveValidPrices(array $prices)
195175
return $prices;
196176
}
197177

178+
/**
179+
* Check that store exists and is global when price scope is global and otherwise add error to aggregator.
180+
*
181+
* @param SpecialPriceInterface $price
182+
* @param int $key
183+
* @return void
184+
*/
185+
private function checkStore(SpecialPriceInterface $price, int $key): void
186+
{
187+
if ($this->catalogData->isPriceGlobal() && $price->getStoreId() !== 0) {
188+
$errorMessage = 'Could not change non global Price when price scope is global. '
189+
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.';
190+
$this->addFailedItemPrice($price, $key, $errorMessage, []);
191+
}
192+
193+
try {
194+
$this->storeRepository->getById($price->getStoreId());
195+
} catch (NoSuchEntityException $e) {
196+
$errorMessage = 'Requested store is not found. '
197+
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.';
198+
$this->addFailedItemPrice($price, $key, $errorMessage, []);
199+
}
200+
}
201+
198202
/**
199203
* Check that date value is correct and add error to aggregator if it contains incorrect data.
200204
*
201-
* @param \Magento\Catalog\Api\Data\SpecialPriceInterface $price
205+
* @param SpecialPriceInterface $price
202206
* @param string $value
203207
* @param string $label
204208
* @param int $key
205209
* @return void
206210
*/
207-
private function checkDate(\Magento\Catalog\Api\Data\SpecialPriceInterface $price, $value, $label, $key)
211+
private function checkDate(SpecialPriceInterface $price, $value, $label, $key)
208212
{
209213
if ($value && !$this->isCorrectDateValue($value)) {
210-
$this->validationResult->addFailedItem(
211-
$key,
212-
__(
213-
'Invalid attribute %label = %priceTo. '
214-
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.',
215-
[
216-
'label' => $label,
217-
'SKU' => $price->getSku(),
218-
'storeId' => $price->getStoreId(),
219-
'priceFrom' => $price->getPriceFrom(),
220-
'priceTo' => $price->getPriceTo()
221-
]
222-
),
223-
[
224-
'label' => $label,
225-
'SKU' => $price->getSku(),
226-
'storeId' => $price->getStoreId(),
227-
'priceFrom' => $price->getPriceFrom(),
228-
'priceTo' => $price->getPriceTo()
229-
]
230-
);
214+
$errorMessage = 'Invalid attribute %label = %priceTo. '
215+
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.';
216+
$this->addFailedItemPrice($price, $key, $errorMessage, ['label' => $label]);
231217
}
232218
}
233219

234220
/**
235-
* Check that provided price value is not empty and not lower then zero and add error to aggregator if price
221+
* Check price.
222+
*
223+
* Verify that provided price value is not empty and not lower then zero and add error to aggregator if price
236224
* contains not valid data.
237225
*
238-
* @param \Magento\Catalog\Api\Data\SpecialPriceInterface $price
226+
* @param SpecialPriceInterface $price
239227
* @param int $key
240228
* @return void
241229
*/
242-
private function checkPrice(\Magento\Catalog\Api\Data\SpecialPriceInterface $price, $key)
230+
private function checkPrice(SpecialPriceInterface $price, int $key): void
243231
{
244232
if (null === $price->getPrice() || $price->getPrice() < 0) {
245-
$this->validationResult->addFailedItem(
246-
$key,
247-
__(
248-
'Invalid attribute Price = %price. '
249-
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.',
250-
[
251-
'price' => $price->getPrice(),
252-
'SKU' => $price->getSku(),
253-
'storeId' => $price->getStoreId(),
254-
'priceFrom' => $price->getPriceFrom(),
255-
'priceTo' => $price->getPriceTo()
256-
]
257-
),
258-
[
259-
'price' => $price->getPrice(),
260-
'SKU' => $price->getSku(),
261-
'storeId' => $price->getStoreId(),
262-
'priceFrom' => $price->getPriceFrom(),
263-
'priceTo' => $price->getPriceTo()
264-
]
265-
);
233+
$errorMessage = 'Invalid attribute Price = %price. '
234+
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.';
235+
$this->addFailedItemPrice($price, $key, $errorMessage, ['price' => $price->getPrice()]);
266236
}
267237
}
268238

239+
/**
240+
* Adds failed item price to validation result
241+
*
242+
* @param SpecialPriceInterface $price
243+
* @param int $key
244+
* @param string $message
245+
* @param array $firstParam
246+
* @return void
247+
*/
248+
private function addFailedItemPrice(
249+
SpecialPriceInterface $price,
250+
int $key,
251+
string $message,
252+
array $firstParam
253+
): void {
254+
$additionalInfo = [];
255+
if ($firstParam) {
256+
$additionalInfo = array_merge($additionalInfo, $firstParam);
257+
}
258+
259+
$additionalInfo['SKU'] = $price->getSku();
260+
$additionalInfo['storeId'] = $price->getStoreId();
261+
$additionalInfo['priceFrom'] = $price->getPriceFrom();
262+
$additionalInfo['priceTo'] = $price->getPriceTo();
263+
264+
$this->validationResult->addFailedItem($key, __($message, $additionalInfo), $additionalInfo);
265+
}
266+
269267
/**
270268
* Retrieve SKU by product ID.
271269
*

0 commit comments

Comments
 (0)