14 private static $instance;
23 if (!isset(self::$instance))
25 self::$instance =
new self;
28 return self::$instance;
31 private function __construct()
36 private function __clone()
47 if(empty($discount[
'ID']))
52 $condition = $this->getConditionStructure($discount);
58 list($elementIds, $sectionIds) = $this->extractElementsAndSections($condition);
62 if(!$elementIds && !$sectionIds)
82 list($elementIds, $sectionIds) = $this->extractElementsAndSections($discount[
'CONDITIONS']);
84 return !empty($elementIds) || !empty($sectionIds);
87 private function getConditionStructure(array $discount)
89 if(empty($discount[
'CONDITIONS']) && empty($discount[
'CONDITIONS_LIST']))
94 if(!empty($discount[
'CONDITIONS_LIST']))
96 $conditions = $discount[
'CONDITIONS_LIST'];
100 $conditions = $discount[
'CONDITIONS'];
103 if(is_string($conditions))
105 $conditions = unserialize($conditions, [
'allowed_classes' =>
false]);
108 if(!$conditions || !is_array($conditions))
116 private function extractElementsAndSections(array $condition)
118 if(empty($condition[
'CLASS_ID']))
123 if($condition[
'CLASS_ID'] !==
'CondGroup' || empty($condition[
'DATA']))
128 if(empty($condition[
'CHILDREN']))
134 !($condition[
'DATA'][
'All'] ===
'AND' && $condition[
'DATA'][
'True'] ===
'True') &&
135 !($condition[
'DATA'][
'All'] ===
'OR' && $condition[
'DATA'][
'True'] ===
'True')
141 $elementIds = $sectionIds = array();
142 foreach($condition[
'CHILDREN'] as $child)
145 isset($child[
'CHILDREN'])
146 && is_array($child[
'CHILDREN'])
147 && count($child[
'CHILDREN']) === 1
148 && $child[
'DATA'][
'All'] ===
'AND'
149 && $child[
'DATA'][
'Found'] ===
'Found';
152 $child[
'CLASS_ID'] ===
'CondBsktProductGroup' &&
154 ($child[
'DATA'][
'All'] ===
'OR' && $child[
'DATA'][
'Found'] ===
'Found') ||
159 foreach($child[
'CHILDREN'] as $grandchild)
161 switch($grandchild[
'CLASS_ID'])
163 case 'CondIBElement':
164 if (is_array($grandchild[
'DATA'][
'value']))
166 $elementIds = array_merge($elementIds, $grandchild[
'DATA'][
'value']);
170 $elementIds[] = $grandchild[
'DATA'][
'value'];
173 case 'CondIBSection':
174 if($grandchild[
'DATA'][
'logic'] ===
'Equal')
176 $sectionIds[] = $grandchild[
'DATA'][
'value'];
184 $elementIds = $this->convertSkuToMainProducts($elementIds);
186 return array($elementIds, $sectionIds);
189 private function convertSkuToMainProducts(array $elementIds)
191 if (!Loader::includeModule(
'catalog'))
196 $products = \CCatalogSKU::getProductList($elementIds);
197 if (empty($products))
202 $newElementIds = array_combine($elementIds, $elementIds);
203 foreach($products as $offerId => $product)
205 if(isset($newElementIds[$offerId]))
207 $newElementIds[$product[
'ID']] = $product[
'ID'];
208 unset($newElementIds[$offerId]);
212 return array_values($newElementIds);