33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
67namespace Magento \ConfigurableProduct \Plugin \Model \Attribute \Backend ;
78
9+ use Closure ;
810use Magento \Catalog \Api \Data \ProductInterface ;
911use 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 */
1418class 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}
0 commit comments