1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
product_set.php
См. документацию.
1<?php
2
6
8{
9 public const TYPE_SET = 1;
10 public const TYPE_GROUP = 2;
11
12 protected static $arErrors = array();
13 protected static $disableShowErrors = 0;
14 protected static $disableCheckProduct = false;
15 protected static $recalculateSet = 0;
16
17 public static function enableShowErrors()
18 {
19 self::$disableShowErrors++;
20 }
21
22 public static function disableShowErrors()
23 {
24 self::$disableShowErrors--;
25 }
26
27 public static function isEnabledShowErrors()
28 {
29 return (self::$disableShowErrors >= 0);
30 }
31
32 public static function enableRecalculateSet()
33 {
34 self::$recalculateSet++;
35 }
36
37 public static function disableRecalculateSet()
38 {
39 self::$recalculateSet--;
40 }
41
42 public static function isEnabledRecalculateSet()
43 {
44 return (self::$recalculateSet >= 0);
45 }
46
47 public static function getErrors()
48 {
49 return self::$arErrors;
50 }
51
52 public static function setCheckParams($params)
53 {
54 if (!empty($params) && is_array($params))
55 {
56 if (isset($params['CHECK_PRODUCT']))
57 {
58 self::$disableCheckProduct = ('N' == $params['CHECK_PRODUCT']);
59 }
60 }
61 }
62
63 public static function clearCheckParams()
64 {
65 self::$disableCheckProduct = false;
66 }
67
68 public static function checkFields($strAction, &$arFields, $intID = 0)
69 {
70 self::$arErrors = array();
71
72 $strAction = mb_strtoupper($strAction);
73 if ('ADD' != $strAction && 'UPDATE' != $strAction && 'TEST' != $strAction)
74 return false;
75 if (empty($arFields) || !is_array($arFields))
76 return false;
77 if (array_key_exists('ID', $arFields))
78 unset($arFields['ID']);
79
80 if (array_key_exists('DATE_CREATE', $arFields))
81 unset($arFields['DATE_CREATE']);
82 if (array_key_exists('TIMESTAMP_X', $arFields))
83 unset($arFields['TIMESTAMP_X']);
84
85 $boolCheck = ('UPDATE' != $strAction ? self::checkFieldsToAdd($arFields, 'TEST' == $strAction) : self::checkFieldsToUpdate($intID, $arFields));
86 if (!$boolCheck || !empty(self::$arErrors))
87 {
88 if (static::isEnabledShowErrors())
89 {
90 global $APPLICATION;
91 $obError = new CAdminException(self::$arErrors);
92 $APPLICATION->ResetException();
93 $APPLICATION->ThrowException($obError);
94 }
95 return false;
96 }
97 return true;
98 }
99
100 public static function add($arFields)
101 {
102 return false;
103 }
104
105 public static function update($intID, $arFields)
106 {
107 return false;
108 }
109
110 public static function delete($intID)
111 {
112 return false;
113 }
114
120 public static function isProductInSet($intProductID, $intSetType = 0)
121 {
122 return false;
123 }
124
130 public static function isProductHaveSet($arProductID, $intSetType = 0)
131 {
132 return false;
133 }
134
135 public static function canCreateSetByProduct($intProductID, $intSetType)
136 {
137 $intProductID = (int)$intProductID;
138 if ($intProductID <= 0)
139 return false;
140
141 if (self::isProductInSet($intProductID, $intSetType))
142 return false;
143
144 if (CCatalogSku::IsExistOffers($intProductID))
145 return false;
146
147 return true;
148 }
149
155 public static function getAllSetsByProduct($intProductID, $intSetType)
156 {
157 return false;
158 }
159
164 public static function getSetByID($intID)
165 {
166 return false;
167 }
168
169 public static function deleteAllSetsByProduct($intProductID, $intSetType)
170 {
171 global $DB;
172
173 $intProductID = (int)$intProductID;
174 if (0 >= $intProductID)
175 return false;
176 $intSetType = (int)$intSetType;
177 if (self::TYPE_SET != $intSetType && self::TYPE_GROUP != $intSetType)
178 return false;
179
180 foreach (GetModuleEvents('catalog', 'OnBeforeProductAllSetsDelete', true) as $arEvent)
181 {
182 if (ExecuteModuleEventEx($arEvent, array($intProductID, $intSetType)) === false)
183 return false;
184 }
185
186 $strSql = 'delete from b_catalog_product_sets where OWNER_ID='.$intProductID.' and TYPE='.$intSetType;
187 $DB->Query($strSql);
188 switch ($intSetType)
189 {
190 case self::TYPE_SET:
192 break;
193 case self::TYPE_GROUP:
194 if (!static::isProductHaveSet($intProductID, self::TYPE_GROUP))
196 break;
197 }
198
199 foreach (GetModuleEvents('catalog', 'OnProductAllSetsDelete', true) as $arEvent)
200 ExecuteModuleEventEx($arEvent, array($intProductID, $intSetType));
201
202 return true;
203 }
204
209 public static function recalculateSetsByProduct($product) {}
210
211 public static function recalculateSet($setID, $productID = 0)
212 {
213 $setID = (int)$setID;
214 $productID = (int)$productID;
215 if ($setID > 0)
216 {
217 if ($productID > 0)
218 {
219 $setParams = static::createSetItemsParamsFromUpdate($setID, false);
220 }
221 else
222 {
223 $extSetParams = static::createSetItemsParamsFromUpdate($setID, true);
224 $productID = $extSetParams['ITEM_ID'];
225 $setParams = $extSetParams['ITEMS'];
226 unset($extSetParams);
227 }
228 static::fillSetItemsParams($setParams);
229 static::calculateSetParams($productID, $setParams);
230 }
231 }
232
233 protected static function checkFieldsToAdd(&$arFields, $boolCheckNew = false)
234 {
235 global $DB;
236 global $USER;
237
238 $boolCheckNew = !!$boolCheckNew;
239
240 $intCurrentUser = 0;
242 $intCurrentUser = (int)$USER->GetID();
243 if ($intCurrentUser <= 0)
244 $intCurrentUser = false;
245
246 $strTimeFunc = $DB->GetNowFunction();
247
248 $arProductInSet = array();
249 $dblDiscountPercent = 0;
250
251 $arDefItem = self::getEmptyItemFields();
252
253 $arFields = array_merge(self::getEmptyFields(), $arFields);
254
255 if (empty(self::$arErrors))
256 {
257 $arFields['ITEM_ID'] = (int)$arFields['ITEM_ID'];
258 if (!$boolCheckNew)
259 {
260 if (0 >= $arFields['ITEM_ID'])
261 self::$arErrors[] = array('id' => 'ITEM_ID', 'text' => Loc::getMessage('BT_CAT_SET_ERR_PRODUCT_ID_IS_BAD'));
262 }
263 else
264 {
265 if (0 > $arFields['ITEM_ID'])
266 self::$arErrors[] = array('id' => 'ITEM_ID', 'text' => Loc::getMessage('BT_CAT_SET_ERR_PRODUCT_ID_IS_BAD'));
267 }
268
269 $arFields['TYPE'] = (int)$arFields['TYPE'];
270 if (self::TYPE_SET != $arFields['TYPE'] && self::TYPE_GROUP != $arFields['TYPE'])
271 self::$arErrors[] = array('id' => 'TYPE', 'text' => Loc::getMessage('BT_CAT_SET_ERR_TYPE_IS_BAD'));
272
273 if (empty($arFields['ITEMS']) || !is_array($arFields['ITEMS']))
274 self::$arErrors[] = array('id' => 'ITEMS', 'text' => Loc::getMessage('BT_CAT_SET_ERR_ITEMS_IS_ABSENT'));
275 }
276
277 if (empty(self::$arErrors))
278 {
279 $arFields['QUANTITY'] = false;
280 $arFields['MEASURE'] = false;
281 $arFields['DISCOUNT_PERCENT'] = false;
282 }
283 if (empty(self::$arErrors))
284 {
285 if (0 < $arFields['ITEM_ID'])
286 $arProductInSet[$arFields['ITEM_ID']] = true;
287
288 $arValidItems = array();
289 foreach ($arFields['ITEMS'] as &$arOneItem)
290 {
291 if (empty($arOneItem) || !is_array($arOneItem))
292 continue;
293 $arOneItem = array_merge($arDefItem, $arOneItem);
294 $arOneItem['ITEM_ID'] = (int)$arOneItem['ITEM_ID'];
295 if (0 >= $arOneItem['ITEM_ID'])
296 continue;
297 if (isset($arProductInSet[$arOneItem['ITEM_ID']]))
298 {
299 self::$arErrors[] = array('id' => 'ITEM_ID', 'text' => Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_ITEM_ID_DUBLICATE'));
300 continue;
301 }
302 $arProductInSet[$arOneItem['ITEM_ID']] = true;
303 $arOneItem['QUANTITY'] = doubleval($arOneItem['QUANTITY']);
304 if (0 >= $arOneItem['QUANTITY'])
305 {
306 self::$arErrors[] = array(
307 'id' => 'QUANTITY',
308 'text' => (
309 self::TYPE_SET == $arFields['TYPE']
310 ? Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_QUANTITY_IS_BAD')
311 : Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_QUANTITY_GROUP_IS_BAD')
312 )
313 );
314 continue;
315 }
316 if (self::TYPE_SET == $arFields['TYPE'])
317 {
318 $arOneItem['MEASURE'] = (int)$arOneItem['MEASURE'];
319 if (0 > $arOneItem['MEASURE'])
320 $arOneItem['MEASURE'] = 0;
321
322 if (false !== $arOneItem['DISCOUNT_PERCENT'])
323 {
324 $arOneItem['DISCOUNT_PERCENT'] = doubleval($arOneItem['DISCOUNT_PERCENT']);
325 if (0 > $arOneItem['DISCOUNT_PERCENT'] || 100 < $arOneItem['DISCOUNT_PERCENT'])
326 {
327 self::$arErrors[] = array('id' => 'DISCOUNT_PERCENT', 'text' => Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_DISCOUNT_PERCENT_IS_BAD'));
328 continue;
329 }
330 $dblDiscountPercent += $arOneItem['DISCOUNT_PERCENT'];
331 }
332 }
333 else
334 {
335 $arOneItem['MEASURE'] = false;
336 $arOneItem['DISCOUNT_PERCENT'] = false;
337 }
338 $arValidItems[] = $arOneItem;
339 }
340 unset($arOneItem);
341 if (empty($arValidItems))
342 self::$arErrors[] = array('id' => 'ITEMS', 'text' => Loc::getMessage('BT_CAT_SET_ERR_EMPTY_VALID_ITEMS'));
343 else
344 $arFields['ITEMS'] = $arValidItems;
345 unset($arValidItems);
346 if (100 < $dblDiscountPercent)
347 self::$arErrors[] = array('id' => 'DISCOUNT_PERCENT', 'text' => Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_ALL_DISCOUNT_PERCENT_IS_BAD'));
348 }
349
350 if (empty(self::$arErrors))
351 {
352 $arProductList = array_keys($arProductInSet);
353 if (!self::$disableCheckProduct)
354 {
355 if ($arFields['TYPE'] == self::TYPE_GROUP)
356 {
357 $checkProductList = $arProductInSet;
358 if ($arFields['ITEM_ID'] > 0)
359 unset($checkProductList[$arFields['ITEM_ID']]);
360 $checkProductList = array_keys($checkProductList);
361 }
362 else
363 {
364 $checkProductList = $arProductList;
365 }
366 if (!static::checkProducts($arFields['TYPE'], $checkProductList))
367 {
368 self::$arErrors[] = array(
369 'id' => 'ITEMS',
370 'text' => (
371 $arFields['TYPE'] == self::TYPE_GROUP
372 ? Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_BAD_ITEMS_IN_GROUP')
373 : Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_BAD_ITEMS_IN_SET')
374 )
375 );
376 }
377 unset($checkProductList);
378 }
379 }
380
381 if (empty(self::$arErrors))
382 {
383 $arFields['ACTIVE'] = ('N' != $arFields['ACTIVE'] ? 'Y' : 'N');
384 $arFields['SORT'] = (int)$arFields['SORT'];
385 if (0 >= $arFields['SORT'])
386 $arFields['SORT'] = 100;
387
388 $arFields['SET_ID'] = 0;
389 $arFields['OWNER_ID'] = $arFields['ITEM_ID'];
390 $arFields['~DATE_CREATE'] = $strTimeFunc;
391 $arFields['~TIMESTAMP_X'] = $strTimeFunc;
392 $arFields['CREATED_BY'] = (!array_key_exists('CREATED_BY', $arFields) ? 0 : (int)$arFields['CREATED_BY']);
393 if (0 >= $arFields['CREATED_BY'])
394 $arFields['CREATED_BY'] = $intCurrentUser;
395 $arFields['MODIFIED_BY'] = (!array_key_exists('MODIFIED_BY', $arFields) ? 0 : (int)$arFields['MODIFIED_BY']);
396 if (0 >= $arFields['MODIFIED_BY'])
397 $arFields['MODIFIED_BY'] = $intCurrentUser;
398
400 }
401 return empty(self::$arErrors);
402 }
403
404 protected static function checkFieldsToUpdate($intID, &$arFields)
405 {
406 global $DB;
407 global $USER;
408
409 $intCurrentUser = 0;
411 $intCurrentUser = (int)$USER->GetID();
412 if ($intCurrentUser <= 0)
413 $intCurrentUser = false;
414
415 $strTimeFunc = $DB->GetNowFunction();
416
417 $arDefItem = self::getEmptyItemFields();
418
419 $arProductInSet = array();
420 $dblDiscountPercent = 0;
421 $boolItems = false;
422
423 $intID = (int)$intID;
424 if ($intID <= 0)
425 self::$arErrors[] = array('id' => 'ID', 'text' => Loc::getMessage('BT_CAT_SET_ERR_ID_IS_BAD'));
426
427 $arCurrent = array();
428 if (empty(self::$arErrors))
429 {
430 $arCurrent = CCatalogProductSet::getSetByID($intID);
431 if (empty($arCurrent))
432 self::$arErrors[] = array('id' => 'ID', 'text' => Loc::getMessage('BT_CAT_SET_ERR_ID_IS_BAD'));
433 }
434
435 if (empty(self::$arErrors))
436 {
437 self::clearFieldsForUpdate($arFields, $arCurrent['TYPE']);
438 if (array_key_exists('ACTIVE', $arFields))
439 $arFields['ACTIVE'] = ('N' != $arFields['ACTIVE'] ? 'Y' : 'N');
440 if (array_key_exists('SORT', $arFields))
441 {
442 $arFields['SORT'] = (int)$arFields['SORT'];
443 if ($arFields['SORT'] <= 0)
444 $arFields['SORT'] = 100;
445 }
446
447 $arFields['MODIFIED_BY'] = (!array_key_exists('MODIFIED_BY', $arFields) ? 0 : (int)$arFields['MODIFIED_BY']);
448 if ($arFields['MODIFIED_BY'] <= 0)
449 $arFields['MODIFIED_BY'] = $intCurrentUser;
450
451 $arFields['~TIMESTAMP_X'] = $strTimeFunc;
452 }
453
454 if (empty(self::$arErrors))
455 {
456 $arProductInSet[$arCurrent['ITEM_ID']] = true;
457
458 if (array_key_exists('ITEMS', $arFields))
459 {
460 if (empty($arFields['ITEMS']) || !is_array($arFields['ITEMS']))
461 {
462 self::$arErrors[] = array('id' => 'ITEMS', 'text' => Loc::getMessage('BT_CAT_SET_ERR_ITEMS_IS_ABSENT'));
463 }
464 else
465 {
466 $arValidItems = array();
467 foreach ($arFields['ITEMS'] as &$arOneItem)
468 {
469 if (empty($arOneItem) || !is_array($arOneItem))
470 continue;
471 if (array_key_exists('ID', $arOneItem))
472 unset($arOneItem['ID']);
473 if (!array_key_exists('ITEM_ID', $arOneItem))
474 continue;
475 $arOneItem['ITEM_ID'] = (int)$arOneItem['ITEM_ID'];
476 if ($arOneItem['ITEM_ID'] <= 0)
477 continue;
478 if (isset($arProductInSet[$arOneItem['ITEM_ID']]))
479 {
480 self::$arErrors[] = array('id' => 'ITEM_ID', 'text' => Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_ITEM_ID_DUBLICATE'));
481 continue;
482 }
483 $arProductInSet[$arOneItem['ITEM_ID']] = true;
484 $intRowID = self::searchItem($arOneItem['ITEM_ID'], $arCurrent['ITEMS']);
485 if (false === $intRowID)
486 {
487 $arOneItem = array_merge($arDefItem, $arOneItem);
488 }
489 else
490 {
491 $arOneItem['ID'] = $intRowID;
492 }
493 if (array_key_exists('SORT', $arOneItem))
494 {
495 $arOneItem['SORT'] = (int)$arOneItem['SORT'];
496 if ($arOneItem['SORT'] <= 0)
497 $arOneItem['SORT'] = 100;
498 }
499 if (array_key_exists('QUANTITY', $arOneItem))
500 {
501 $arOneItem['QUANTITY'] = doubleval($arOneItem['QUANTITY']);
502 if (0 >= $arOneItem['QUANTITY'])
503 {
504 self::$arErrors[] = array(
505 'id' => 'QUANTITY',
506 'text' => (
507 self::TYPE_SET == $arCurrent['TYPE']
508 ? Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_QUANTITY_IS_BAD')
509 : Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_QUANTITY_GROUP_IS_BAD')
510 )
511 );
512 continue;
513 }
514 }
515 if (self::TYPE_SET == $arCurrent['TYPE'])
516 {
517 if (array_key_exists('MEASURE', $arOneItem))
518 {
519 $arOneItem['MEASURE'] = (int)$arOneItem['MEASURE'];
520 if ($arOneItem['MEASURE'] < 0)
521 $arOneItem['MEASURE'] = 0;
522 }
523 if (array_key_exists('DISCOUNT_PERCENT', $arOneItem))
524 {
525 if (false !== $arOneItem['DISCOUNT_PERCENT'])
526 {
527 $arOneItem['DISCOUNT_PERCENT'] = doubleval($arOneItem['DISCOUNT_PERCENT']);
528 if (0 > $arOneItem['DISCOUNT_PERCENT'] || 100 < $arOneItem['DISCOUNT_PERCENT'])
529 {
530 self::$arErrors[] = array('id' => 'DISCOUNT_PERCENT', 'text' => Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_DISCOUNT_PERCENT_IS_BAD'));
531 continue;
532 }
533 $dblDiscountPercent += $arOneItem['DISCOUNT_PERCENT'];
534 }
535 }
536 else
537 {
538 if (false !== $intRowID)
539 {
540 if (false !== $arCurrent['ITEMS'][$intRowID]['DISCOUNT_PERCENT'])
541 $dblDiscountPercent += $arCurrent['ITEMS'][$intRowID]['DISCOUNT_PERCENT'];
542 }
543 }
544 }
545
546 $arValidItems[] = $arOneItem;
547 }
548 unset($arOneItem);
549 if (empty($arValidItems))
550 {
551 self::$arErrors[] = array('id' => 'ITEMS', 'text' => Loc::getMessage('BT_CAT_SET_ERR_EMPTY_VALID_ITEMS'));
552 }
553 else
554 {
555 $arFields['ITEMS'] = $arValidItems;
556 $boolItems = true;
557 }
558 unset($arValidItems);
559 if (100 < $dblDiscountPercent)
560 self::$arErrors[] = array('id' => 'DISCOUNT_PERCENT', 'text' => Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_ALL_DISCOUNT_PERCENT_IS_BAD'));
561 }
562 }
563 if (empty(self::$arErrors))
564 {
565 if (isset($arProductInSet[$arCurrent['ITEM_ID']]))
566 unset($arProductInSet[$arCurrent['ITEM_ID']]);
567 if (!self::$disableCheckProduct)
568 {
569 if (!static::checkProducts($arCurrent['TYPE'], array_keys($arProductInSet)))
570 {
571 self::$arErrors[] = array(
572 'id' => 'ITEMS',
573 'text' => (
574 $arCurrent['TYPE'] == self::TYPE_GROUP
575 ? Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_BAD_ITEMS_IN_GROUP')
576 : Loc::getMessage('BT_CAT_PRODUCT_SET_ERR_BAD_ITEMS_IN_SET')
577 )
578 );
579 }
580 }
581 }
582 }
583
584 if (empty(self::$arErrors))
585 {
586 if ($boolItems)
588 }
589
590 return empty(self::$arErrors);
591 }
592
593 protected static function getSetID($intID)
594 {
595 return false;
596 }
597
598 protected static function getEmptySet($intSetType)
599 {
600 if (self::TYPE_SET == $intSetType)
601 {
602 return array(
603 'TYPE' => self::TYPE_SET,
604 'SET_ID' => 0,
605 'ITEM_ID' => 0,
606 'ACTIVE' => '',
607 'QUANTITY' => 0,
608 'MEASURE' => false,
609 'DISCOUNT_PERCENT' => false,
610 'SORT' => 0,
611 'ITEMS' => array()
612 );
613 }
614 else
615 {
616 return array(
617 'TYPE' => self::TYPE_GROUP,
618 'SET_ID' => 0,
619 'ITEM_ID' => 0,
620 'ACTIVE' => '',
621 'QUANTITY' => 0,
622 'SORT' => 0,
623 'ITEMS' => array()
624 );
625 }
626 }
627
628 protected static function deleteFromSet($intID, $arEx)
629 {
630 return false;
631 }
632
633 protected static function setItemFieldsForAdd(&$arFields)
634 {
635 $arClear = array(
636 'ID', 'DATE_CREATE', 'TIMESTAMP_X'
637 );
638 foreach ($arFields['ITEMS'] as &$arOneItem)
639 {
640 foreach ($arClear as &$strKey)
641 {
642 if (array_key_exists($strKey, $arOneItem))
643 unset($arOneItem[$strKey]);
644 }
645 unset($strKey);
646
647 $arOneItem['TYPE'] = $arFields['TYPE'];
648 $arOneItem['OWNER_ID'] = $arFields['ITEM_ID'];
649 $arOneItem['ACTIVE'] = $arFields['ACTIVE'];
650 $arOneItem['CREATED_BY'] = $arFields['CREATED_BY'];
651 $arOneItem['~DATE_CREATE'] = $arFields['~DATE_CREATE'];
652 $arOneItem['MODIFIED_BY'] = $arFields['MODIFIED_BY'];
653 $arOneItem['~TIMESTAMP_X'] = $arFields['~TIMESTAMP_X'];
654 }
655 unset($arOneItem);
656 }
657
658 protected static function setItemFieldsForUpdate(&$arFields, $arCurrent)
659 {
660 $strActive = (isset($arFields['ACTIVE']) ? $arFields['ACTIVE'] : $arCurrent['ACTIVE']);
661
662 if (self::TYPE_GROUP == $arCurrent['TYPE'])
663 {
664 $arClear = array(
665 'CREATED_BY', 'TYPE', 'SET_ID', 'OWNER_ID', 'ITEM_ID', 'MEASURE', 'DISCOUNT_PERCENT'
666 );
667 }
668 else
669 {
670 $arClear = array(
671 'CREATED_BY', 'TYPE', 'SET_ID', 'OWNER_ID', 'ITEM_ID'
672 );
673 }
674 foreach ($arFields['ITEMS'] as &$arOneItem)
675 {
676 if (array_key_exists('DATE_CREATE', $arOneItem))
677 unset($arOneItem['DATE_CREATE']);
678
679 $arOneItem['ACTIVE'] = $strActive;
680 $arOneItem['MODIFIED_BY'] = $arFields['MODIFIED_BY'];
681 $arOneItem['~TIMESTAMP_X'] = $arFields['~TIMESTAMP_X'];
682
683 if (array_key_exists('ID', $arOneItem))
684 {
685 foreach ($arClear as &$strKey)
686 {
687 if (array_key_exists($strKey, $arOneItem))
688 unset($arOneItem[$strKey]);
689 }
690 unset($strKey);
691 }
692 else
693 {
694 $arOneItem['TYPE'] = $arCurrent['TYPE'];
695 $arOneItem['SET_ID'] = $arCurrent['ID'];
696 $arOneItem['OWNER_ID'] = $arCurrent['ITEM_ID'];
697
698 $arOneItem['CREATED_BY'] = $arFields['MODIFIED_BY'];
699 $arOneItem['~DATE_CREATE'] = $arFields['~TIMESTAMP_X'];
700 }
701 }
702 unset($arOneItem);
703 }
704
705 protected static function clearFieldsForUpdate(&$arFields, $intSetType)
706 {
707 $intSetType = (int)$intSetType;
708 $arClear = array(
709 'TYPE', 'SET_ID', 'ITEM_ID', 'OWNER_ID', 'CREATED_BY', 'MEASURE', 'DISCOUNT_PERCENT'
710 );
711 if ($intSetType == self::TYPE_SET)
712 $arClear[] = 'QUANTITY';
713 foreach ($arClear as &$strKey)
714 {
715 if (array_key_exists($strKey, $arFields))
716 unset($arFields[$strKey]);
717 }
718 unset($strKey);
719 }
720
721 protected static function getEmptyFields()
722 {
723 return array(
724 'TYPE' => 0,
725 'SET_ID' => 0,
726 'ACTIVE' => 'Y',
727 'OWNER_ID' => 0,
728 'ITEM_ID' => 0,
729 'QUANTITY' => false,
730 'MEASURE' => false,
731 'DISCOUNT_PERCENT' => false,
732 'SORT' => 100,
733 'XML_ID' => false,
734 'ITEMS' => array()
735 );
736 }
737
738 protected static function getEmptyItemFields()
739 {
740 return array(
741 'TYPE' => 0,
742 'SET_ID' => 0,
743 'ACTIVE' => 'Y',
744 'OWNER_ID' => 0,
745 'ITEM_ID' => 0,
746 'QUANTITY' => false,
747 'MEASURE' => false,
748 'DISCOUNT_PERCENT' => false,
749 'SORT' => 100,
750 'XML_ID' => false,
751 );
752 }
753
754 protected static function searchItem($intItemID, &$arItems)
755 {
756 $mxResult = false;
757 foreach ($arItems as &$arOneItem)
758 {
759 if ($intItemID === $arOneItem['ITEM_ID'])
760 {
761 $mxResult = $arOneItem['ID'];
762 break;
763 }
764 }
765 unset($arOneItem);
766 return $mxResult;
767 }
768
769 protected static function calculateSetParams($productID, $items)
770 {
771 return false;
772 }
773
774 protected static function fillSetItemsParams(&$items)
775 {
776 if (empty($items) || !is_array($items))
777 {
778 return;
779 }
780
781 $productIterator = Catalog\ProductTable::getList([
782 'select' => ['ID', 'QUANTITY', 'QUANTITY_TRACE', 'CAN_BUY_ZERO', 'WEIGHT'],
783 'filter' => ['@ID' => array_keys($items)]
784 ]);
785 while ($product = $productIterator->fetch())
786 {
787 $product['ID'] = (int)$product['ID'];
788 if (isset($items[$product['ID']]))
789 {
790 $items[$product['ID']] = array_merge($items[$product['ID']], $product);
791 }
792 }
793 }
794
795 protected static function createSetItemsParamsFromAdd($items)
796 {
797 $result = array();
798 foreach ($items as &$oneItem)
799 {
800 $oneItem['ITEM_ID'] = (int)$oneItem['ITEM_ID'];
801 $result[$oneItem['ITEM_ID']] = array(
802 'QUANTITY_IN_SET' => $oneItem['QUANTITY']
803 );
804 }
805 unset($oneItem);
806 return $result;
807 }
808
809 protected static function createSetItemsParamsFromUpdate($setID, $getProductID = false)
810 {
811 return array();
812 }
813
814 protected static function isTracedItem($item)
815 {
816 return (
817 isset($item['QUANTITY_TRACE']) && $item['QUANTITY_TRACE'] === 'Y'
818 && isset($item['CAN_BUY_ZERO']) && $item['CAN_BUY_ZERO'] === 'N'
819 );
820 }
821
822 protected static function checkProducts($type, array $productList)
823 {
824 $type = (int)$type;
825 if ($type != self::TYPE_SET && $type != self::TYPE_GROUP)
826 return false;
827
828 if (empty($productList))
829 return false;
830
832 if (empty($productList))
833 return false;
834
835 $allowTypes = array(
838 );
839 if ($type == self::TYPE_GROUP)
840 $allowTypes[Catalog\ProductTable::TYPE_SET] = true;
841
842 $productIterator = Catalog\ProductTable::getList(array(
843 'select' => array('ID', 'TYPE'),
844 'filter' => array('@ID' => $productList)
845 ));
846 $productList = array_fill_keys($productList, true);
847 while ($product = $productIterator->fetch())
848 {
849 $id = (int)$product['ID'];
850 $productType = (int)$product['TYPE'];
851 if (isset($allowTypes[$productType]) && isset($productList[$id]))
852 unset($productList[$id]);
853 unset($productType, $id);
854 }
855 unset($product, $productIterator);
856
857 return (empty($productList));
858 }
859}
$type
Определения options.php:106
global $APPLICATION
Определения include.php:80
const TYPE_SET
Определения product.php:71
const STATUS_NO
Определения product.php:67
const TYPE_OFFER
Определения product.php:73
const TYPE_PRODUCT
Определения product.php:70
static getMessage($code, $replace=null, $language=null)
Определения loc.php:30
static getList(array $parameters=array())
Определения datamanager.php:431
static normalizeArrayValuesByInt(&$map, $sorted=true)
Определения collection.php:150
static IsUserExists()
Определения catalog.php:1812
static Update($id, $fields)
Определения product.php:557
static SetProductType($intID, $intTypeID)
Определения product.php:293
static getEmptySet($intSetType)
Определения product_set.php:598
static calculateSetParams($productID, $items)
Определения product_set.php:769
static update($intID, $arFields)
Определения product_set.php:105
static enableRecalculateSet()
Определения product_set.php:32
static fillSetItemsParams(&$items)
Определения product_set.php:774
static setItemFieldsForUpdate(&$arFields, $arCurrent)
Определения product_set.php:658
static checkFieldsToUpdate($intID, &$arFields)
Определения product_set.php:404
static searchItem($intItemID, &$arItems)
Определения product_set.php:754
static $arErrors
Определения product_set.php:12
static deleteAllSetsByProduct($intProductID, $intSetType)
Определения product_set.php:169
static createSetItemsParamsFromAdd($items)
Определения product_set.php:795
static getErrors()
Определения product_set.php:47
static checkFields($strAction, &$arFields, $intID=0)
Определения product_set.php:68
static isProductInSet($intProductID, $intSetType=0)
Определения product_set.php:120
static disableShowErrors()
Определения product_set.php:22
static enableShowErrors()
Определения product_set.php:17
static $recalculateSet
Определения product_set.php:15
static disableRecalculateSet()
Определения product_set.php:37
const TYPE_SET
Определения product_set.php:9
static isEnabledShowErrors()
Определения product_set.php:27
static getEmptyFields()
Определения product_set.php:721
static deleteFromSet($intID, $arEx)
Определения product_set.php:628
static getEmptyItemFields()
Определения product_set.php:738
static getAllSetsByProduct($intProductID, $intSetType)
Определения product_set.php:155
static $disableCheckProduct
Определения product_set.php:14
static setItemFieldsForAdd(&$arFields)
Определения product_set.php:633
static getSetID($intID)
Определения product_set.php:593
static $disableShowErrors
Определения product_set.php:13
static canCreateSetByProduct($intProductID, $intSetType)
Определения product_set.php:135
static isTracedItem($item)
Определения product_set.php:814
static clearFieldsForUpdate(&$arFields, $intSetType)
Определения product_set.php:705
static clearCheckParams()
Определения product_set.php:63
static isProductHaveSet($arProductID, $intSetType=0)
Определения product_set.php:130
static checkFieldsToAdd(&$arFields, $boolCheckNew=false)
Определения product_set.php:233
static isEnabledRecalculateSet()
Определения product_set.php:42
const TYPE_GROUP
Определения product_set.php:10
static createSetItemsParamsFromUpdate($setID, $getProductID=false)
Определения product_set.php:809
static checkProducts($type, array $productList)
Определения product_set.php:822
static setCheckParams($params)
Определения product_set.php:52
static recalculateSet($setID, $productID=0)
Определения product_set.php:211
static getSetByID($intID)
Определения product_set.php:164
static add($arFields)
Определения product_set.php:100
static recalculateSetsByProduct($product)
Определения product_set.php:209
static getSetByID($intID)
Определения product_set.php:415
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$items
Определения template.php:224