@@ -100,22 +100,7 @@ protected function _isValid($entity)
100
100
101
101
foreach ($ this ->getConditions () as $ cond ) {
102
102
if ($ entity instanceof \Magento \Framework \Model \AbstractModel) {
103
- $ attributeScope = $ cond ->getAttributeScope ();
104
- if ($ attributeScope === 'parent ' ) {
105
- $ validateEntities = [$ entity ];
106
- } elseif ($ attributeScope === 'children ' ) {
107
- $ validateEntities = $ entity ->getChildren () ?: [$ entity ];
108
- } else {
109
- $ validateEntities = $ entity ->getChildren () ?: [];
110
- $ validateEntities [] = $ entity ;
111
- }
112
- $ validated = !$ true ;
113
- foreach ($ validateEntities as $ validateEntity ) {
114
- $ validated = $ cond ->validate ($ validateEntity );
115
- if ($ validated === $ true ) {
116
- break ;
117
- }
118
- }
103
+ $ validated = $ this ->validateEntity ($ cond , $ entity );
119
104
} else {
120
105
$ validated = $ cond ->validateByEntityId ($ entity );
121
106
}
@@ -127,4 +112,44 @@ protected function _isValid($entity)
127
112
}
128
113
return $ all ? true : false ;
129
114
}
115
+
116
+ /**
117
+ * @param object $cond
118
+ * @param \Magento\Framework\Model\AbstractModel $entity
119
+ * @return bool
120
+ */
121
+ private function validateEntity ($ cond , \Magento \Framework \Model \AbstractModel $ entity )
122
+ {
123
+ $ true = (bool )$ this ->getValue ();
124
+ $ validated = !$ true ;
125
+ foreach ($ this ->retrieveValidateEntities ($ cond ->getAttributeScope (), $ entity ) as $ validateEntity ) {
126
+ $ validated = $ cond ->validate ($ validateEntity );
127
+ if ($ validated === $ true ) {
128
+ break ;
129
+ }
130
+ }
131
+
132
+ return $ validated ;
133
+ }
134
+
135
+ /**
136
+ * Retrieve entities for validation by attribute scope
137
+ *
138
+ * @param $attributeScope
139
+ * @param \Magento\Framework\Model\AbstractModel $entity
140
+ * @return \Magento\Framework\Model\AbstractModel[]
141
+ */
142
+ private function retrieveValidateEntities ($ attributeScope , \Magento \Framework \Model \AbstractModel $ entity )
143
+ {
144
+ if ($ attributeScope === 'parent ' ) {
145
+ $ validateEntities = [$ entity ];
146
+ } elseif ($ attributeScope === 'children ' ) {
147
+ $ validateEntities = $ entity ->getChildren () ?: [$ entity ];
148
+ } else {
149
+ $ validateEntities = $ entity ->getChildren () ?: [];
150
+ $ validateEntities [] = $ entity ;
151
+ }
152
+
153
+ return $ validateEntities ;
154
+ }
130
155
}
0 commit comments