3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \ConfigurableProduct \Plugin \Model \Attribute \Backend ;
7
8
9
+ use Closure ;
8
10
use Magento \Catalog \Api \Data \ProductInterface ;
9
11
use Magento \ConfigurableProduct \Model \Product \Type \Configurable ;
12
+ use Magento \Eav \Model \Entity \Attribute \Backend \AbstractBackend ;
13
+ use Magento \Framework \DataObject ;
10
14
11
15
/**
12
- * Skip validate attributes used for create configurable product
16
+ * Skip validate attributes used for create configurable product.
13
17
*/
14
18
class AttributeValidation
15
19
{
@@ -19,29 +23,36 @@ class AttributeValidation
19
23
private $ configurableProductType ;
20
24
21
25
/**
22
- * AttributeValidation constructor.
26
+ * @var array
27
+ */
28
+ private $ unskippableAttributes ;
29
+
30
+ /**
23
31
* @param Configurable $configurableProductType
32
+ * @param array|null $unskippableAttributes
24
33
*/
25
34
public function __construct (
26
- Configurable $ configurableProductType
35
+ Configurable $ configurableProductType ,
36
+ array $ unskippableAttributes = []
27
37
) {
28
38
$ this ->configurableProductType = $ configurableProductType ;
39
+ $ this ->unskippableAttributes = $ unskippableAttributes ;
29
40
}
30
41
31
42
/**
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
33
46
* @param \Closure $proceed
34
- * @param \Magento\Framework\ DataObject $entity
47
+ * @param DataObject $entity
35
48
* @return bool
36
49
*/
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
+ {
42
52
$ attribute = $ subject ->getAttribute ();
43
53
if ($ entity instanceof ProductInterface
44
54
&& $ entity ->getTypeId () == Configurable::TYPE_CODE
55
+ && !in_array ($ attribute ->getAttributeCode (), $ this ->unskippableAttributes )
45
56
&& in_array (
46
57
$ attribute ->getAttributeId (),
47
58
$ this ->configurableProductType ->getUsedProductAttributeIds ($ entity ),
@@ -50,6 +61,7 @@ public function aroundValidate(
50
61
) {
51
62
return true ;
52
63
}
64
+
53
65
return $ proceed ($ entity );
54
66
}
55
67
}
0 commit comments