diff --git a/vendor/magento/module-rule/Model/Condition/Combine.php b/vendor/magento/module-rule/Model/Condition/Combine.php index a8a8e5fb0f843..43f7dc949d398 100644 --- a/vendor/magento/module-rule/Model/Condition/Combine.php +++ b/vendor/magento/module-rule/Model/Condition/Combine.php @@ -1,13 +1,11 @@ setAggregator( - isset($arr['aggregator']) ? $arr['aggregator'] : (isset($arr['attribute']) ? $arr['attribute'] : null) - )->setValue( - isset($arr['value']) ? $arr['value'] : (isset($arr['operator']) ? $arr['operator'] : null) - ); + $this->setAggregatorAndValue($arr); + $this->loadConditions($arr[$key] ?? [], $key); + + return $this; + } + + /** + * Set the aggregator and value from the array. + * + * @param array $arr + */ + private function setAggregatorAndValue(array $arr): void + { + $aggregator = $arr['aggregator'] ?? $arr['attribute'] ?? null; + $value = $arr['value'] ?? $arr['operator'] ?? null; + + $this->setAggregator($aggregator) + ->setValue($value); + } + + /** + * Load the conditions from the array. + * + * @param array $conditions + * @param string $key + */ + private function loadConditions(array $conditions, string $key): void + { + foreach ($conditions as $conditionArr) { + if (!empty($conditionArr['type'])) { + $this->createAndAddCondition($conditionArr, $key); + continue; + } - if (!empty($arr[$key]) && is_array($arr[$key])) { - foreach ($arr[$key] as $conditionArr) { - try { - $condition = $this->_conditionFactory->create($conditionArr['type']); - $this->addCondition($condition); - $condition->loadArray($conditionArr, $key); - } catch (\Exception $e) { - $this->_logger->critical($e); - } + // Recursively load conditions if there are nested conditions + if (!empty($conditionArr[$key])) { + $this->loadConditions($conditionArr[$key], $key); } } - return $this; + } + + /** + * Create and add a condition to the object. + * + * @param array $conditionArr + * @param string $key + */ + private function createAndAddCondition(array $conditionArr, string $key): void + { + try { + $condition = $this->_conditionFactory->create($conditionArr['type']); + $this->addCondition($condition); + $condition->loadArray($conditionArr, $key); + } catch (\Exception $e) { + $this->_logger->critical($e); + } } /**