Skip to content

Commit f661c0e

Browse files
Merge branch '2.4-develop' into ACPT-99-2
2 parents 8430f1d + 62aafe2 commit f661c0e

File tree

8 files changed

+123
-11
lines changed

8 files changed

+123
-11
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ public function execute()
326326
return $this->returnResult('catalog/*/', [], ['error' => false]);
327327
} catch (\Exception $e) {
328328
$this->messageManager->addErrorMessage($e->getMessage());
329+
if ($attributeId === null) {
330+
unset($data['frontend_input']);
331+
}
329332
$this->_session->setAttributeData($data);
330333
return $this->returnResult(
331334
'catalog/*/edit',

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\CatalogImportExport\Model\Import\Product\StatusProcessor;
1717
use Magento\CatalogImportExport\Model\Import\Product\StockProcessor;
1818
use Magento\CatalogImportExport\Model\StockItemImporterInterface;
19+
use Magento\CatalogImportExport\Model\StockItemProcessorInterface;
1920
use Magento\CatalogInventory\Api\Data\StockItemInterface;
2021
use Magento\Framework\App\Filesystem\DirectoryList;
2122
use Magento\Framework\App\ObjectManager;
@@ -228,7 +229,6 @@ class Product extends AbstractEntity
228229
* @deprecated 101.1.0 use DI for LinkProcessor class if you want to add additional types
229230
*
230231
* @see Magento_CatalogImportExport::etc/di.xml
231-
*
232232
* @var array
233233
*/
234234
protected $_linkNameToId = [
@@ -614,8 +614,8 @@ class Product extends AbstractEntity
614614
/**
615615
* @var array
616616
* @deprecated 100.0.3
617-
* @since 100.0.3
618617
*
618+
* @since 100.0.3
619619
* @see we don't recommend this approach anymore
620620
*/
621621
protected $productUrlKeys = [];
@@ -755,6 +755,11 @@ class Product extends AbstractEntity
755755
*/
756756
private $linkProcessor;
757757

758+
/**
759+
* @var StockItemProcessorInterface
760+
*/
761+
private $stockItemProcessor;
762+
758763
/**
759764
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
760765
* @param \Magento\ImportExport\Helper\Data $importExportData
@@ -804,6 +809,7 @@ class Product extends AbstractEntity
804809
* @param StockProcessor|null $stockProcessor
805810
* @param LinkProcessor|null $linkProcessor
806811
* @param File|null $fileDriver
812+
* @param StockItemProcessorInterface|null $stockItemProcessor
807813
* @throws LocalizedException
808814
* @throws \Magento\Framework\Exception\FileSystemException
809815
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -858,7 +864,8 @@ public function __construct(
858864
StatusProcessor $statusProcessor = null,
859865
StockProcessor $stockProcessor = null,
860866
LinkProcessor $linkProcessor = null,
861-
?File $fileDriver = null
867+
?File $fileDriver = null,
868+
?StockItemProcessorInterface $stockItemProcessor = null
862869
) {
863870
$this->_eventManager = $eventManager;
864871
$this->stockRegistry = $stockRegistry;
@@ -922,6 +929,8 @@ public function __construct(
922929
$this->dateTimeFactory = $dateTimeFactory ?? ObjectManager::getInstance()->get(DateTimeFactory::class);
923930
$this->productRepository = $productRepository ?? ObjectManager::getInstance()
924931
->get(ProductRepositoryInterface::class);
932+
$this->stockItemProcessor = $stockItemProcessor ?? ObjectManager::getInstance()
933+
->get(StockItemProcessorInterface::class);
925934
}
926935

927936
/**
@@ -1290,6 +1299,7 @@ protected function _prepareRowForDb(array $rowData)
12901299
*
12911300
* @deprecated 101.1.0 use linkProcessor Directly
12921301
* @see linkProcessor
1302+
*
12931303
* @return $this
12941304
*/
12951305
protected function _saveLinks()
@@ -2331,6 +2341,7 @@ protected function _saveStockItem()
23312341
{
23322342
while ($bunch = $this->_dataSourceModel->getNextUniqueBunch($this->getIds())) {
23332343
$stockData = [];
2344+
$importedData = [];
23342345
$productIdsToReindex = [];
23352346
$stockChangedProductIds = [];
23362347
// Format bunch to stock data rows
@@ -2356,12 +2367,13 @@ protected function _saveStockItem()
23562367

23572368
if (!isset($stockData[$sku])) {
23582369
$stockData[$sku] = $row;
2370+
$importedData[$sku] = $rowData;
23592371
}
23602372
}
23612373

23622374
// Insert rows
23632375
if (!empty($stockData)) {
2364-
$this->stockItemImporter->import($stockData);
2376+
$this->stockItemProcessor->process($stockData, $importedData);
23652377
}
23662378

23672379
$this->reindexStockStatus($stockChangedProductIds);
@@ -2515,6 +2527,7 @@ public function getRowScope(array $rowData)
25152527
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
25162528
* @SuppressWarnings(PHPMD.NPathComplexity)
25172529
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2530+
* @throws \Zend_Validate_Exception
25182531
*/
25192532
public function validateRow(array $rowData, $rowNum)
25202533
{
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Model;
9+
10+
class StockItemProcessor implements StockItemProcessorInterface
11+
{
12+
/**
13+
* @var StockItemImporterInterface
14+
*/
15+
private $stockItemImporter;
16+
17+
/**
18+
* @param StockItemImporterInterface $stockItemImporter
19+
*/
20+
public function __construct(
21+
StockItemImporterInterface $stockItemImporter
22+
) {
23+
$this->stockItemImporter = $stockItemImporter;
24+
}
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
public function process(array $stockData, array $importedData): void
30+
{
31+
$this->stockItemImporter->import($stockData);
32+
}
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Model;
9+
10+
use Magento\Framework\Exception\CouldNotSaveException;
11+
use Magento\Framework\Exception\InputException;
12+
use Magento\Framework\Validation\ValidationException;
13+
14+
interface StockItemProcessorInterface
15+
{
16+
/**
17+
* Handle Import of Stock Item Data
18+
*
19+
* @param array $stockData
20+
* @param array $importedData
21+
* @return void
22+
* @throws CouldNotSaveException
23+
* @throws InputException
24+
* @throws ValidationException
25+
*/
26+
public function process(array $stockData, array $importedData): void;
27+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<preference for="Magento\CatalogImportExport\Model\Export\RowCustomizerInterface" type="Magento\CatalogImportExport\Model\Export\RowCustomizer\Composite" />
1010
<preference for="Magento\CatalogImportExport\Model\StockItemImporterInterface" type="Magento\CatalogImportExport\Model\StockItemImporter" />
11+
<preference for="Magento\CatalogImportExport\Model\StockItemProcessorInterface" type="Magento\CatalogImportExport\Model\StockItemProcessor" />
1112
<preference for="Magento\CatalogImportExport\Model\Export\ProductFilterInterface" type="Magento\CatalogImportExport\Model\Export\ProductFilters" />
1213
<type name="Magento\ImportExport\Model\Import">
1314
<plugin name="catalogProductFlatIndexerImport" type="Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import" />

app/code/Magento/Eav/Model/Entity/Attribute.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Eav\Model\Entity;
77

8+
use Magento\Eav\Model\ReservedAttributeCheckerInterface;
89
use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator;
910
use Magento\Framework\Api\AttributeValueFactory;
1011
use Magento\Framework\App\ObjectManager;
@@ -29,17 +30,17 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
2930
* The value is defined as 60 because in the flat mode attribute code will be transformed into column name.
3031
* MySQL allows only 64 symbols in column name.
3132
*/
32-
const ATTRIBUTE_CODE_MAX_LENGTH = 60;
33+
public const ATTRIBUTE_CODE_MAX_LENGTH = 60;
3334

3435
/**
3536
* Min accepted length of an attribute code.
3637
*/
37-
const ATTRIBUTE_CODE_MIN_LENGTH = 1;
38+
public const ATTRIBUTE_CODE_MIN_LENGTH = 1;
3839

3940
/**
4041
* Tag to use for attributes caching.
4142
*/
42-
const CACHE_TAG = 'EAV_ATTRIBUTE';
43+
public const CACHE_TAG = 'EAV_ATTRIBUTE';
4344

4445
/**
4546
* Prefix of model events names
@@ -69,6 +70,9 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
6970

7071
/**
7172
* @var \Magento\Catalog\Model\Product\ReservedAttributeList
73+
*
74+
* @deprecated Incorrect direct dependency on Product attribute.
75+
* @see \Magento\Eav\Model\Entity\Attribute::$reservedAttributeChecker
7276
*/
7377
protected $reservedAttributeList;
7478

@@ -87,6 +91,11 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
8791
*/
8892
private $attributeCodeValidator;
8993

94+
/**
95+
* @var ReservedAttributeCheckerInterface|null
96+
*/
97+
private $reservedAttributeChecker;
98+
9099
/**
91100
* @param \Magento\Framework\Model\Context $context
92101
* @param \Magento\Framework\Registry $registry
@@ -108,6 +117,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
108117
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
109118
* @param array $data
110119
* @param AttributeCodeValidator|null $attributeCodeValidator
120+
* @param ReservedAttributeCheckerInterface|null $reservedAttributeChecker
111121
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
112122
* @codeCoverageIgnore
113123
*/
@@ -131,7 +141,8 @@ public function __construct(
131141
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
132142
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
133143
array $data = [],
134-
AttributeCodeValidator $attributeCodeValidator = null
144+
AttributeCodeValidator $attributeCodeValidator = null,
145+
?ReservedAttributeCheckerInterface $reservedAttributeChecker = null
135146
) {
136147
parent::__construct(
137148
$context,
@@ -157,6 +168,9 @@ public function __construct(
157168
$this->attributeCodeValidator = $attributeCodeValidator ?: ObjectManager::getInstance()->get(
158169
AttributeCodeValidator::class
159170
);
171+
$this->reservedAttributeChecker = $reservedAttributeChecker ?: ObjectManager::getInstance()->get(
172+
ReservedAttributeCheckerInterface::class
173+
);
160174
}
161175

162176
/**
@@ -251,7 +265,7 @@ public function beforeSave()
251265
}
252266

253267
// prevent overriding product data
254-
if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) {
268+
if (isset($this->_data['attribute_code']) && $this->reservedAttributeChecker->isReservedAttribute($this)) {
255269
throw new LocalizedException(
256270
__(
257271
'The attribute code \'%1\' is reserved by system. Please try another attribute code',
@@ -535,6 +549,7 @@ public function __wakeup()
535549
$this->_localeDate = $objectManager->get(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
536550
$this->_localeResolver = $objectManager->get(\Magento\Framework\Locale\ResolverInterface::class);
537551
$this->reservedAttributeList = $objectManager->get(\Magento\Catalog\Model\Product\ReservedAttributeList::class);
552+
$this->reservedAttributeChecker = $objectManager->get(ReservedAttributeCheckerInterface::class);
538553
$this->dateTimeFormatter = $objectManager->get(DateTimeFormatterInterface::class);
539554
}
540555

app/code/Magento/Eav/Model/ReservedAttributeChecker.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class ReservedAttributeChecker implements ReservedAttributeCheckerInterface
1919
{
2020
/**
21-
* @var ReservedAttributeCheckerInterface[][]
21+
* @var ReservedAttributeCheckerInterface[]
2222
*/
2323
private $validators;
2424

@@ -37,7 +37,8 @@ public function __construct(
3737
public function isReservedAttribute(AbstractAttribute $attribute): bool
3838
{
3939
$isReserved = false;
40-
$validators = $this->validators[$attribute->getEntityType()->getEntityTypeCode()] ?? [];
40+
$entityTypeCode = $this->getAttributeEntityTypeCode($attribute);
41+
$validators = $this->validators[$entityTypeCode] ?? [];
4142
foreach ($validators as $validator) {
4243
$isReserved = $validator->isReservedAttribute($attribute);
4344
if ($isReserved === true) {
@@ -47,4 +48,21 @@ public function isReservedAttribute(AbstractAttribute $attribute): bool
4748

4849
return $isReserved;
4950
}
51+
52+
/**
53+
* Returns attribute entity type code.
54+
*
55+
* @param AbstractAttribute $attribute
56+
* @return string|null
57+
*/
58+
private function getAttributeEntityTypeCode(AbstractAttribute $attribute): ?string
59+
{
60+
try {
61+
$result = $attribute->getEntityType()->getEntityTypeCode();
62+
} catch (LocalizedException $e) {
63+
$result = null;
64+
}
65+
66+
return $result;
67+
}
5068
}

app/code/Magento/Theme/Test/Mftf/Test/StoreFrontCheckNotificationMessageContainerTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<group value="Theme"/>
2020
</annotations>
2121
<before>
22+
<magentoCLI command="config:set {{EnableFlatRateConfigData.path}} {{EnableFlatRateConfigData.value}}" stepKey="enableFlatRate"/>
2223
<createData entity="SimpleProduct2" stepKey="simpleProduct"/>
2324
<createData entity="SalesRuleSpecificCouponAndByPercent" stepKey="createSalesRule"/>
2425
<createData entity="SimpleSalesRuleCoupon" stepKey="createCouponForCartPriceRule">
@@ -28,6 +29,7 @@
2829
<after>
2930
<deleteData createDataKey="simpleProduct" stepKey="deleteProduct"/>
3031
<deleteData createDataKey="createSalesRule" stepKey="deleteSalesRule"/>
32+
<magentoCLI command="config:set {{DisableFlatRateConfigData.path}} {{DisableFlatRateConfigData.value}}" stepKey="disableFlatRate"/>
3133
</after>
3234

3335
<actionGroup ref="AssertProductNameAndSkuInStorefrontProductPageByCustomAttributeUrlKeyActionGroup" stepKey="openProductPageAndVerifyProduct">

0 commit comments

Comments
 (0)