3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
-
7
6
declare (strict_types=1 );
8
7
9
8
namespace Magento \ConfigurableProduct \Plugin \Model \Attribute \Backend ;
@@ -24,12 +23,10 @@ class AttributeValidation
24
23
* @var Configurable
25
24
*/
26
25
private $ configurableProductType ;
27
-
28
26
/**
29
27
* @var array
30
28
*/
31
29
private $ unskippableAttributes ;
32
-
33
30
/**
34
31
* @param Configurable $configurableProductType
35
32
* @param array|null $unskippableAttributes
@@ -41,28 +38,24 @@ public function __construct(
41
38
$ this ->configurableProductType = $ configurableProductType ;
42
39
$ this ->unskippableAttributes = $ unskippableAttributes ;
43
40
}
44
-
45
41
/**
46
- * Around plugin to skip attribute validation used for create configurable product.
42
+ * Verify is attribute used for configurable product creation and should not be validated .
47
43
*
48
44
* @param AbstractBackend $subject
49
- * @param Closure $proceed
45
+ * @param \ Closure $proceed
50
46
* @param DataObject $entity
51
47
* @return bool
52
48
*/
53
- public function aroundValidate (
54
- AbstractBackend $ subject ,
55
- Closure $ proceed ,
56
- DataObject $ entity
57
- ) {
49
+ public function aroundValidate (AbstractBackend $ subject , Closure $ proceed , DataObject $ entity )
50
+ {
58
51
$ attribute = $ subject ->getAttribute ();
59
- if ($ this ->isAttributeShouldNotBeValidated ($ entity , $ attribute )) {
52
+ if ($ this ->isAttributeShouldNotBeValidated ($ entity , $ attribute )
53
+ && !in_array ($ attribute ->getAttributeCode (), $ this ->unskippableAttributes )
54
+ ) {
60
55
return true ;
61
56
}
62
-
63
57
return $ proceed ($ entity );
64
58
}
65
-
66
59
/**
67
60
* Verify if attribute is a part of configurable product and should not be validated.
68
61
*
@@ -72,10 +65,7 @@ public function aroundValidate(
72
65
*/
73
66
private function isAttributeShouldNotBeValidated (DataObject $ entity , AbstractAttribute $ attribute ): bool
74
67
{
75
- if (!($ entity instanceof ProductInterface
76
- && $ entity ->getTypeId () == Configurable::TYPE_CODE )
77
- && in_array ($ attribute ->getAttributeCode (), $ this ->unskippableAttributes )
78
- ) {
68
+ if (!($ entity instanceof ProductInterface && $ entity ->getTypeId () === Configurable::TYPE_CODE )) {
79
69
return false ;
80
70
}
81
71
$ attributeId = $ attribute ->getAttributeId ();
0 commit comments