Skip to content

Commit 397ae82

Browse files
committed
Merge branch 'MC-41109' of github.com:magento-tsg/magento2ce into cia-2.4.3-3172021
2 parents a9a8547 + 052bb5d commit 397ae82

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

app/code/Magento/ConfigurableProduct/Plugin/Model/Attribute/Backend/AttributeValidation.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend;
78

9+
use Closure;
810
use Magento\Catalog\Api\Data\ProductInterface;
911
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
12+
use Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend;
13+
use Magento\Framework\DataObject;
1014

1115
/**
12-
* Skip validate attributes used for create configurable product
16+
* Skip validate attributes used for create configurable product.
1317
*/
1418
class AttributeValidation
1519
{
@@ -19,29 +23,36 @@ class AttributeValidation
1923
private $configurableProductType;
2024

2125
/**
22-
* AttributeValidation constructor.
26+
* @var array
27+
*/
28+
private $unskippableAttributes;
29+
30+
/**
2331
* @param Configurable $configurableProductType
32+
* @param array|null $unskippableAttributes
2433
*/
2534
public function __construct(
26-
Configurable $configurableProductType
35+
Configurable $configurableProductType,
36+
array $unskippableAttributes = []
2737
) {
2838
$this->configurableProductType = $configurableProductType;
39+
$this->unskippableAttributes = $unskippableAttributes;
2940
}
3041

3142
/**
32-
* @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject
43+
* Around plugin to skip attribute validation used for create configurable product.
44+
*
45+
* @param AbstractBackend $subject
3346
* @param \Closure $proceed
34-
* @param \Magento\Framework\DataObject $entity
47+
* @param DataObject $entity
3548
* @return bool
3649
*/
37-
public function aroundValidate(
38-
\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject,
39-
\Closure $proceed,
40-
\Magento\Framework\DataObject $entity
41-
) {
50+
public function aroundValidate(AbstractBackend $subject, Closure $proceed, DataObject $entity)
51+
{
4252
$attribute = $subject->getAttribute();
4353
if ($entity instanceof ProductInterface
4454
&& $entity->getTypeId() == Configurable::TYPE_CODE
55+
&& !in_array($attribute->getAttributeCode(), $this->unskippableAttributes)
4556
&& in_array(
4657
$attribute->getAttributeId(),
4758
$this->configurableProductType->getUsedProductAttributeIds($entity),
@@ -50,6 +61,7 @@ public function aroundValidate(
5061
) {
5162
return true;
5263
}
64+
5365
return $proceed($entity);
5466
}
5567
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
<type name="Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend">
3434
<plugin name="ConfigurableProduct::skipValidation" type="Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend\AttributeValidation"/>
3535
</type>
36+
<type name="Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend\AttributeValidation">
37+
<arguments>
38+
<argument name="unskippableAttributes" xsi:type="array">
39+
<item name="custom_layout_update" xsi:type="string">custom_layout_update</item>
40+
</argument>
41+
</arguments>
42+
</type>
3643
<type name="Magento\Catalog\Model\Entity\Product\Attribute\Group\AttributeMapperInterface">
3744
<plugin name="configurable_product" type="Magento\ConfigurableProduct\Model\Entity\Product\Attribute\Group\AttributeMapper\Plugin" sortOrder="50" />
3845
</type>

0 commit comments

Comments
 (0)