143 list($elementIds, $sectionIds) = static::getGiftsData($discount);
144 list($productElementIds, $productSectionIds) = static::getProductsData($discount);
147 $mainProductSectionId = reset($productSectionIds);
148 if(!is_int($mainProductSectionId))
150 $mainProductSectionId =
null;
154 foreach($elementIds as $elementId)
157 'DISCOUNT_ID' => $discount[
'ID'],
158 'ELEMENT_ID' => $elementId,
159 'SECTION_ID' =>
null,
160 'MAIN_PRODUCT_SECTION_ID' => $mainProductSectionId,
164 foreach($sectionIds as $sectionId)
167 'DISCOUNT_ID' => $discount[
'ID'],
168 'ELEMENT_ID' =>
null,
169 'SECTION_ID' => $sectionId,
170 'MAIN_PRODUCT_SECTION_ID' => $mainProductSectionId,
174 static::insertBatch($items);
185 $sectionIds = $elementIds = array();
188 (empty($discount[
'ACTIONS_LIST']) || !is_array($discount[
'ACTIONS_LIST']))
189 && checkSerializedData($discount[
'ACTIONS']))
191 $discount[
'ACTIONS_LIST'] = unserialize($discount[
'ACTIONS'], [
'allowed_classes' =>
false]);
194 if(!isset($discount[
'ACTIONS_LIST'][
'CHILDREN']) && is_array($discount[
'ACTIONS_LIST'][
'CHILDREN']))
196 return array($elementIds, $sectionIds);
199 foreach($discount[
'ACTIONS_LIST'][
'CHILDREN'] as $child)
201 if(!isset($child[
'CLASS_ID']) || !isset($child[
'DATA']) || $child[
'CLASS_ID'] !== \CSaleActionGiftCtrlGroup::getControlID())
205 foreach($child[
'CHILDREN'] as $gifterChild)
207 switch($gifterChild[
'CLASS_ID'])
209 case 'GifterCondIBElement':
210 $elementIds = array_merge($elementIds, (array)$gifterChild[
'DATA'][
'Value']);
212 case 'GifterCondIBSection':
213 $sectionIds = array_merge($sectionIds, (array)$gifterChild[
'DATA'][
'Value']);
221 return array($elementIds, $sectionIds);
232 $sectionIds = $elementIds = array();
235 (empty($discount[
'CONDITIONS_LIST']) || !is_array($discount[
'CONDITIONS_LIST']))
236 && checkSerializedData($discount[
'CONDITIONS']))
238 $discount[
'CONDITIONS_LIST'] = unserialize($discount[
'CONDITIONS'], [
'allowed_classes' =>
false]);
241 if(!isset($discount[
'CONDITIONS_LIST'][
'CLASS_ID']) || $discount[
'CONDITIONS_LIST'][
'CLASS_ID'] !==
'CondGroup')
243 return array($elementIds, $sectionIds);
245 if(empty($discount[
'CONDITIONS_LIST'][
'CHILDREN']))
247 return array($elementIds, $sectionIds);
249 if(count($discount[
'CONDITIONS_LIST'][
'CHILDREN']) > 1)
251 return array($elementIds, $sectionIds);
253 $child = reset($discount[
'CONDITIONS_LIST'][
'CHILDREN']);
255 if($child[
'CLASS_ID'] !==
'CondBsktProductGroup')
257 return array($elementIds, $sectionIds);
260 if(empty($child[
'CHILDREN']))
262 return array($elementIds, $sectionIds);
264 if(count($child[
'CHILDREN']) > 1)
266 return array($elementIds, $sectionIds);
268 $condition = reset($child[
'CHILDREN']);
270 if(!isset($condition[
'DATA'][
'logic']) || $condition[
'DATA'][
'logic'] !==
'Equal')
272 return array($elementIds, $sectionIds);
275 switch($condition[
'CLASS_ID'])
277 case 'CondIBElement':
278 $elementIds = (array)$condition[
'DATA'][
'value'];
280 case 'CondIBSection':
281 $sectionIds = (array)$condition[
'DATA'][
'value'];
285 return array($elementIds, $sectionIds);