1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
product_set.php
См. документацию.
1<?php
2
5
6require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/catalog/general/product_set.php");
7
9{
10 public static function add($arFields)
11 {
12 global $DB;
13
14 foreach (GetModuleEvents("catalog", "OnBeforeProductSetAdd", true) as $arEvent)
15 {
16 if (false === ExecuteModuleEventEx($arEvent, array(&$arFields)))
17 return false;
18 }
19
20 if (!self::checkFields('ADD', $arFields, 0))
21 return false;
22
23 $arSet = $arFields;
24 unset($arSet['ITEMS']);
25 $arInsert = $DB->PrepareInsert("b_catalog_product_sets", $arFields);
26 $strSql = "insert into b_catalog_product_sets(".$arInsert[0].") values(".$arInsert[1].")";
27 $DB->Query($strSql);
28 $intID = (int)$DB->LastID();
29 if (0 < $intID)
30 {
31 foreach ($arFields['ITEMS'] as &$arOneItem)
32 {
33 $arOneItem['SET_ID'] = $intID;
34 $arInsert = $DB->PrepareInsert("b_catalog_product_sets", $arOneItem);
35 $strSql = "insert into b_catalog_product_sets(".$arInsert[0].") values(".$arInsert[1].")";
36 $DB->Query($strSql);
37 }
38 unset($arOneItem);
39 switch ($arSet['TYPE'])
40 {
41 case self::TYPE_SET:
42 $setParams = self::createSetItemsParamsFromAdd($arFields['ITEMS']);
43 self::fillSetItemsParams($setParams);
44 self::calculateSetParams($arSet['ITEM_ID'], $setParams);
45 break;
46 case self::TYPE_GROUP:
48 unset($result);
49 break;
50 }
51
52 foreach (GetModuleEvents("catalog", "OnProductSetAdd", true) as $arEvent)
53 {
54 ExecuteModuleEventEx($arEvent, array($intID, $arFields));
55 }
56 return $intID;
57 }
58 return false;
59 }
60
61 public static function update($intID, $arFields)
62 {
63 global $DB;
64
65 foreach (GetModuleEvents("catalog", "OnBeforeProductSetUpdate", true) as $arEvent)
66 {
67 if (false === ExecuteModuleEventEx($arEvent, array($intID, &$arFields)))
68 return false;
69 }
70
71 if (!self::checkFields('UPDATE', $arFields, $intID))
72 return false;
73
74 $intID = (int)$intID;
75
76 if (!empty($arFields))
77 {
78 $arSet = $arFields;
79 $boolItems = array_key_exists('ITEMS', $arFields);
80 if ($boolItems)
81 unset($arSet['ITEMS']);
82 $strUpdate = $DB->PrepareUpdate("b_catalog_product_sets", $arSet);
83 if (!empty($strUpdate))
84 {
85 $strSql = "update b_catalog_product_sets set ".$strUpdate." where ID = ".$intID;
86 $DB->Query($strSql);
87 }
88 if ($boolItems)
89 {
90 $arIDs = array();
91 foreach ($arFields['ITEMS'] as &$arOneItem)
92 {
93 if (isset($arOneItem['ID']))
94 {
95 $intSubID = $arOneItem['ID'];
96 unset($arOneItem['ID']);
97 $strUpdate = $DB->PrepareUpdate("b_catalog_product_sets", $arOneItem);
98 if (!empty($strUpdate))
99 {
100 $strSql = "update b_catalog_product_sets set ".$strUpdate." where ID = ".$intSubID;
101 $DB->Query($strSql);
102 }
103 }
104 else
105 {
106 $arInsert = $DB->PrepareInsert("b_catalog_product_sets", $arOneItem);
107 $strSql = "insert into b_catalog_product_sets(".$arInsert[0].") values(".$arInsert[1].")";
108 $DB->Query($strSql);
109 $intSubID = (int)$DB->LastID();
110 }
111 $arOneItem['ID'] = $intSubID;
112 $arIDs[] = $intSubID;
113 }
114 unset($arOneItem);
115 if (!empty($arIDs))
116 self::deleteFromSet($intID, $arIDs);
117 }
118 $strSql = "select ID, ITEM_ID, TYPE from b_catalog_product_sets where ID = ".$intID;
119 $rsSets = $DB->Query($strSql);
120 if ($arSet = $rsSets->Fetch())
121 {
122 switch ($arSet['TYPE'])
123 {
124 case self::TYPE_SET:
125 $setParams = self::createSetItemsParamsFromUpdate($intID);
126 self::fillSetItemsParams($setParams);
127 self::calculateSetParams($arSet['ITEM_ID'], $setParams);
128 break;
129 case self::TYPE_GROUP:
130 $result = Catalog\Model\Product::update($arSet['ITEM_ID'], ['BUNDLE' => Catalog\ProductTable::STATUS_YES]);
131 unset($result);
132 break;
133 }
134 }
135
136 foreach (GetModuleEvents("catalog", "OnProductSetUpdate", true) as $arEvent)
137 {
138 ExecuteModuleEventEx($arEvent, array($intID, $arFields));
139 }
140 return true;
141 }
142 return false;
143 }
144
145 public static function delete($intID)
146 {
147 global $DB;
148
149 $intID = (int)$intID;
150 if (0 >= $intID)
151 return false;
152
153 foreach (GetModuleEvents("catalog", "OnBeforeProductSetDelete", true) as $arEvent)
154 {
155 if (false === ExecuteModuleEventEx($arEvent, array($intID)))
156 return false;
157 }
158
159 $arItem = self::getSetID($intID);
160 if (!empty($arItem) && is_array($arItem))
161 {
162 $strSql = "delete from b_catalog_product_sets where SET_ID=".$arItem['ID'];
163 $DB->Query($strSql);
164 $strSql = "delete from b_catalog_product_sets where ID=".$arItem['ID'];
165 $DB->Query($strSql);
166 switch ($arItem['TYPE'])
167 {
168 case self::TYPE_SET:
170 unset($result);
171 break;
172 case self::TYPE_GROUP:
173 if (!static::isProductHaveSet($arItem['ITEM_ID'], self::TYPE_GROUP))
174 {
175 $result = Catalog\Model\Product::update($arItem['ITEM_ID'], ['BUNDLE' => Catalog\ProductTable::STATUS_NO]);
176 unset($result);
177 }
178 break;
179 }
180
181 foreach (GetModuleEvents("catalog", "OnProductSetDelete", true) as $arEvent)
182 {
183 ExecuteModuleEventEx($arEvent, array($intID));
184 }
185 return true;
186 }
187
188 return false;
189 }
190
191 public static function getList($arOrder = array(), $arFilter = array(), $arGroupBy = false, $arNavStartParams = false, $arSelect = array())
192 {
193 global $DB;
194
196 'ID' => array('FIELD' => 'CPS.ID', 'TYPE' => 'int'),
197 'TYPE' => array('FIELD' => 'CPS.TYPE', 'TYPE' => 'int'),
198 'SET_ID' => array('FIELD' => 'CPS.SET_ID', 'TYPE' => 'int'),
199 'ACTIVE' => array('FIELD' => 'CPS.ACTIVE', 'TYPE' => 'char'),
200 'OWNER_ID' => array('FIELD' => 'CPS.OWNER_ID', 'TYPE' => 'int'),
201 'ITEM_ID' => array('FIELD' => 'CPS.ITEM_ID', 'TYPE' => 'int'),
202 'QUANTITY' => array('FIELD' => 'CPS.QUANTITY', 'TYPE' => 'double'),
203 'MEASURE' => array('FIELD' => 'CPS.MEASURE', 'TYPE' => 'int'),
204 'DISCOUNT_PERCENT' => array('FIELD' => 'CPS.DISCOUNT_PERCENT', 'TYPE' => 'double'),
205 'SORT' => array('FIELD' => 'CPS.SORT', 'TYPE' => 'int'),
206 'CREATED_BY' => array('FIELD' => 'CPS.CREATED_BY', 'TYPE' => 'int'),
207 'DATE_CREATE' => array('FIELD' => 'CPS.DATE_CREATE', 'TYPE' => 'datetime'),
208 'MODIFIED_BY' => array('FIELD' => 'CPS.MODIFIED_BY', 'TYPE' => 'int'),
209 'TIMESTAMP_X' => array('FIELD' => 'CPS.TIMESTAMP_X', 'TYPE' => 'datetime'),
210 'XML_ID' => array('FIELD' => 'CPS.XML_ID', 'TYPE' => 'string')
211 );
212
213 $arSqls = CCatalog::PrepareSql($arFields, $arOrder, $arFilter, $arGroupBy, $arSelect);
214
215 $arSqls["SELECT"] = str_replace("%%_DISTINCT_%%", "", $arSqls["SELECT"]);
216
217 if (empty($arGroupBy) && is_array($arGroupBy))
218 {
219 $strSql = "select ".$arSqls["SELECT"]." from b_catalog_product_sets CPS ".$arSqls["FROM"];
220 if (!empty($arSqls["WHERE"]))
221 $strSql .= " where ".$arSqls["WHERE"];
222 if (!empty($arSqls["GROUPBY"]))
223 $strSql .= " group by ".$arSqls["GROUPBY"];
224
225 $dbRes = $DB->Query($strSql);
226 if ($arRes = $dbRes->Fetch())
227 return $arRes["CNT"];
228 else
229 return false;
230 }
231
232 $strSql = "select ".$arSqls["SELECT"]." from b_catalog_product_sets CPS ".$arSqls["FROM"];
233 if (!empty($arSqls["WHERE"]))
234 $strSql .= " where ".$arSqls["WHERE"];
235 if (!empty($arSqls["GROUPBY"]))
236 $strSql .= " group by ".$arSqls["GROUPBY"];
237 if (!empty($arSqls["ORDERBY"]))
238 $strSql .= " order by ".$arSqls["ORDERBY"];
239
240 $intTopCount = 0;
241 $boolNavStartParams = (!empty($arNavStartParams) && is_array($arNavStartParams));
242 if ($boolNavStartParams && isset($arNavStartParams['nTopCount']))
243 {
244 $intTopCount = (int)$arNavStartParams["nTopCount"];
245 }
246 if ($boolNavStartParams && 0 >= $intTopCount)
247 {
248 $strSql_tmp = "select COUNT('x') as CNT from b_catalog_product_sets CPS ".$arSqls["FROM"];
249 if (!empty($arSqls["WHERE"]))
250 $strSql_tmp .= " where ".$arSqls["WHERE"];
251 if (!empty($arSqls["GROUPBY"]))
252 $strSql_tmp .= " group by ".$arSqls["GROUPBY"];
253
254 $dbRes = $DB->Query($strSql_tmp);
255 $cnt = 0;
256 if (empty($arSqls["GROUPBY"]))
257 {
258 if ($arRes = $dbRes->Fetch())
259 $cnt = $arRes["CNT"];
260 }
261 else
262 {
263 $cnt = $dbRes->SelectedRowsCount();
264 }
265
266 $dbRes = new CDBResult();
267
268 $dbRes->NavQuery($strSql, $cnt, $arNavStartParams);
269 }
270 else
271 {
272 if ($boolNavStartParams && 0 < $intTopCount)
273 {
274 $strSql .= " limit ".$intTopCount;
275 }
276 $dbRes = $DB->Query($strSql);
277 }
278
279 return $dbRes;
280 }
281
287 public static function isProductInSet($intProductID, $intSetType = 0)
288 {
289 global $DB;
290
291 $intProductID = (int)$intProductID;
292 if (0 >= $intProductID)
293 return false;
294 $intSetType = (int)$intSetType;
295 $strSql = 'select ID from b_catalog_product_sets where ITEM_ID='.$intProductID;
296 if (self::TYPE_SET == $intSetType || self::TYPE_GROUP == $intSetType)
297 $strSql .= ' and TYPE='.$intSetType;
298 $strSql .= ' limit 1';
299 $rsRes = $DB->Query($strSql);
300 if ($arRes = $rsRes->Fetch())
301 {
302 return true;
303 }
304 return false;
305
306 }
307
313 public static function isProductHaveSet($arProductID, $intSetType = 0)
314 {
315 global $DB;
316
317 if (!is_array($arProductID))
318 $arProductID = array($arProductID);
320 if (empty($arProductID))
321 return false;
322 $intSetType = (int)$intSetType;
323
324 $strSql = 'select ID from b_catalog_product_sets where OWNER_ID in('.implode(', ', $arProductID).')';
325 if (self::TYPE_SET == $intSetType || self::TYPE_GROUP == $intSetType)
326 $strSql .= ' and TYPE='.$intSetType;
327 $strSql .= ' limit 1';
328 $rsRes = $DB->Query($strSql);
329 if ($arRes = $rsRes->Fetch())
330 {
331 return true;
332 }
333 return false;
334 }
335
341 public static function getAllSetsByProduct($intProductID, $intSetType)
342 {
343 global $DB;
344
345 $intProductID = (int)$intProductID;
346 if (0 >= $intProductID)
347 return false;
348 $intSetType = (int)$intSetType;
349 if (self::TYPE_SET != $intSetType && self::TYPE_GROUP != $intSetType)
350 return false;
351
352 $arEmptySet = static::getEmptySet($intSetType);
353
354 $boolSet = self::TYPE_SET == $intSetType;
355
356 $arResult = array();
357 $strSql = "select CPS.ID, CPS.SET_ID, CPS.ACTIVE, CPS.OWNER_ID, CPS.ITEM_ID, CPS.SORT, CPS.QUANTITY, CP.MEASURE";
358 if ($boolSet)
359 $strSql .= ", CPS.DISCOUNT_PERCENT";
360 $strSql .= " from b_catalog_product_sets CPS".
361 " left join b_catalog_product CP on (CP.ID = CPS.ITEM_ID)".
362 " where CPS.OWNER_ID=".$intProductID." and CPS.TYPE=".$intSetType;
363 $rsItems = $DB->Query($strSql);
364 while ($arItem = $rsItems->Fetch())
365 {
366 $arItem['ID'] = (int)$arItem['ID'];
367 $arItem['SET_ID'] = (int)$arItem['SET_ID'];
368 $arItem['OWNER_ID'] = (int)$arItem['OWNER_ID'];
369 $arItem['ITEM_ID'] = (int)$arItem['ITEM_ID'];
370 $arItem['SORT'] = (int)$arItem['SORT'];
371
372 $boolProduct = $arItem['ITEM_ID'] == $arItem['OWNER_ID'];
373 $intSetID = ($boolProduct ? $arItem['ID'] : $arItem['SET_ID']);
374 if ($boolSet)
375 {
376 $arItem['QUANTITY'] = ($arItem['QUANTITY'] === null ? false : (float)$arItem['QUANTITY']);
377 $arItem['MEASURE'] = ($arItem['MEASURE'] === null ? false : (int)$arItem['MEASURE']);
378 $arItem['DISCOUNT_PERCENT'] = ($arItem['DISCOUNT_PERCENT'] === null ? false : $arItem['DISCOUNT_PERCENT']);
379 }
380 if ($boolProduct)
381 {
382 unset($arItem['OWNER_ID']);
383 unset($arItem['SET_ID']);
384 unset($arItem['ID']);
385
386 }
387 else
388 {
389 unset($arItem['SET_ID']);
390 unset($arItem['OWNER_ID']);
391 unset($arItem['ACTIVE']);
392 }
393 if (!isset($arResult[$intSetID]))
394 {
395 $arResult[$intSetID] = $arEmptySet;
396 $arResult[$intSetID]['SET_ID'] = $intSetID;
397 }
398 if ($boolProduct)
399 {
400 $arResult[$intSetID] = array_merge($arResult[$intSetID], $arItem);
401 }
402 else
403 {
404 $arResult[$intSetID]['ITEMS'][$arItem['ID']] = $arItem;
405 }
406 }
407
408 return (!empty($arResult) ? $arResult : false);
409 }
410
415 public static function getSetByID($intID)
416 {
417 global $DB;
418
419 $intID = (int)$intID;
420 if ($intID <= 0)
421 return false;
422
423 $arResult = array();
424 $strSql = "select CPS.ID, CPS.SET_ID, CPS.ACTIVE, CPS.OWNER_ID, CPS.ITEM_ID, CPS.SORT, CPS.QUANTITY, CP.MEASURE".
425 ", CPS.DISCOUNT_PERCENT, CPS.TYPE";
426 $strSql .= " from b_catalog_product_sets CPS".
427 " left join b_catalog_product CP on (CP.ID = CPS.ITEM_ID)".
428 " where CPS.ID=".$intID;
429 $rsItems = $DB->Query($strSql);
430 if ($arItem = $rsItems->Fetch())
431 {
432 $arItem['ID'] = (int)$arItem['ID'];
433 $arItem['TYPE'] = (int)$arItem['TYPE'];
434 $arItem['SET_ID'] = (int)$arItem['SET_ID'];
435 $arItem['OWNER_ID'] = (int)$arItem['OWNER_ID'];
436 $arItem['ITEM_ID'] = (int)$arItem['ITEM_ID'];
437 $arItem['SORT'] = (int)$arItem['SORT'];
438 $arItem['QUANTITY'] = ($arItem['QUANTITY'] === null ? false : (float)$arItem['QUANTITY']);
439 $arItem['MEASURE'] = ($arItem['MEASURE'] === null ? false : (int)$arItem['MEASURE']);
440 $arItem['DISCOUNT_PERCENT'] = ($arItem['DISCOUNT_PERCENT'] === null ? false : (float)$arItem['DISCOUNT_PERCENT']);
441
442 $arResult = $arItem;
443 $arResult['ITEMS'] = array();
444 $strSql = "select CPS.ID, CPS.SET_ID, CPS.ACTIVE, CPS.OWNER_ID, CPS.ITEM_ID, CPS.SORT, CPS.QUANTITY, CP.MEASURE".
445 ", CPS.DISCOUNT_PERCENT, CPS.TYPE";
446 $strSql .= " from b_catalog_product_sets CPS".
447 " left join b_catalog_product CP on (CP.ID = CPS.ITEM_ID)".
448 " where CPS.SET_ID=".$intID;
449 $rsSubs = $DB->Query($strSql);
450 while ($arSub = $rsSubs->Fetch())
451 {
452 $arSub['ID'] = (int)$arSub['ID'];
453 $arSub['TYPE'] = (int)$arSub['TYPE'];
454 $arSub['SET_ID'] = (int)$arSub['SET_ID'];
455 $arSub['OWNER_ID'] = (int)$arSub['OWNER_ID'];
456 $arSub['ITEM_ID'] = (int)$arSub['ITEM_ID'];
457 $arSub['SORT'] = (int)$arSub['SORT'];
458 $arSub['QUANTITY'] = ($arSub['QUANTITY'] === null ? false: (float)$arSub['QUANTITY']);
459 $arSub['MEASURE'] = ($arSub['MEASURE'] === null ? false: (int)$arSub['MEASURE']);
460 $arSub['DISCOUNT_PERCENT'] = ($arSub['DISCOUNT_PERCENT'] === null ? false : (float)$arSub['DISCOUNT_PERCENT']);
461
462 $arResult['ITEMS'][$arSub['ID']] = $arSub;
463 }
464 }
465 return (!empty($arResult) ? $arResult : false);
466 }
467
472 public static function recalculateSetsByProduct($product)
473 {
474 global $DB;
475
476 if (!static::isEnabledRecalculateSet())
477 return;
478
479 $setsList = array();
480 $setsID = array();
481 $product = (int)$product;
482 $query = 'select SET_ID, OWNER_ID, ITEM_ID from b_catalog_product_sets where ITEM_ID='.$product.' and TYPE='.self::TYPE_SET;
483 $setIterator = $DB->Query($query);
484 while ($setItem = $setIterator->Fetch())
485 {
486 $setItem['SET_ID'] = (int)$setItem['SET_ID'];
487 $setItem['OWNER_ID'] = (int)$setItem['OWNER_ID'];
488 $setItem['ITEM_ID'] = (int)$setItem['ITEM_ID'];
489 if ($setItem['ITEM_ID'] === $setItem['OWNER_ID'])
490 continue;
491 $setsList[$setItem['OWNER_ID']] = array();
492 $setsID[] = $setItem['SET_ID'];
493 }
494 unset($setItem, $setIterator, $query);
495
496 if (!empty($setsID))
497 {
498 $productMap = array();
499 $productIds = [];
500 $query = 'select SET_ID, OWNER_ID, ITEM_ID, QUANTITY as QUANTITY_IN_SET from b_catalog_product_sets where SET_ID IN('.implode(',', $setsID).')';
501 $setIterator = $DB->Query($query);
502 while ($setItem = $setIterator->Fetch())
503 {
504 $setItem['SET_ID'] = (int)$setItem['SET_ID'];
505 $setItem['OWNER_ID'] = (int)$setItem['OWNER_ID'];
506 $setItem['ITEM_ID'] = (int)$setItem['ITEM_ID'];
507 if ($setItem['ITEM_ID'] === $setItem['OWNER_ID'])
508 continue;
509 if (!isset($setsList[$setItem['OWNER_ID']]))
510 $setsList[$setItem['OWNER_ID']] = array();
511 $setsList[$setItem['OWNER_ID']][$setItem['ITEM_ID']] = $setItem;
512 if (!isset($productMap[$setItem['ITEM_ID']]))
513 $productMap[$setItem['ITEM_ID']] = array();
514 $productMap[$setItem['ITEM_ID']][] = $setItem['OWNER_ID'];
515 $productIds[$setItem['ITEM_ID']] = $setItem['ITEM_ID'];
516 }
517 unset($setItem, $setIterator, $query);
518
519 sort($productIds);
520 foreach (array_chunk($productIds, 500) as $rowIds)
521 {
523 'select' => ['ID', 'QUANTITY', 'QUANTITY_TRACE', 'CAN_BUY_ZERO', 'WEIGHT'],
524 'filter' => ['@ID' => $rowIds]
525 ]);
526 while ($item = $iterator->fetch())
527 {
528 $item['ID'] = (int)$item['ID'];
529 if (!isset($productMap[$item['ID']]))
530 continue;
531 foreach ($productMap[$item['ID']] as &$setKey)
532 $setsList[$setKey][$item['ID']] = array_merge($setsList[$setKey][$item['ID']], $item);
533 unset($setKey);
534 }
535 unset($item, $iterator);
536 }
537 unset($productIds);
538
539 $setsList = array_filter($setsList);
540 if (!empty($setsList))
541 {
542 foreach ($setsList as $setKey => $oneSet)
543 static::calculateSetParams($setKey, $oneSet);
544 unset($setKey, $oneSet);
545 }
546 }
547 }
548
549 protected static function getSetID($intID)
550 {
551 global $DB;
552
553 $intID = (int)$intID;
554 if (0 >= $intID)
555 return false;
556
557 $strSql = "select ID, TYPE, SET_ID, OWNER_ID, ITEM_ID from b_catalog_product_sets where ID=".$intID;
558 $rsItems = $DB->Query($strSql);
559 if ($arItem = $rsItems->Fetch())
560 {
561 $arItem['ID'] = (int)$arItem['ID'];
562 $arItem['SET_ID'] = (int)$arItem['SET_ID'];
563 $arItem['OWNER_ID'] = (int)$arItem['OWNER_ID'];
564 $arItem['ITEM_ID'] = (int)$arItem['ITEM_ID'];
565 $arItem['TYPE'] = (int)$arItem['TYPE'];
566 if ($arItem['OWNER_ID'] == $arItem['ITEM_ID'] && 0 == $arItem['SET_ID'])
567 {
568 return $arItem;
569 }
570 }
571 return false;
572 }
573
574 protected static function deleteFromSet($intID, $arEx)
575 {
576 global $DB;
577
578 $intID = (int)$intID;
579 if (0 >= $intID)
580 return false;
582 if (empty($arEx))
583 return false;
584
585 $strSql = "delete from b_catalog_product_sets where SET_ID=".$intID." and ID NOT IN(".implode(', ', $arEx).")";
586 $DB->Query($strSql);
587 return true;
588 }
589
590 protected static function calculateSetParams($productID, $items)
591 {
592 global $DB;
593
594 if (empty($items) || !is_array($items))
595 return false;
596
597 $quantityTrace = 'N';
598 $canBuyZero = 'Y';
599 $quantity = null;
600 $weight = 0;
601
602 $allItems = true;
603 $tracedItems = array_filter($items, [__CLASS__, 'isTracedItem']);
604 if (empty($tracedItems))
605 {
606 $tracedItems = $items;
607 }
608 else
609 {
610 $allItems = false;
611 $quantityTrace = 'Y';
612 $canBuyZero = 'N';
613 foreach ($items as &$oneItem)
614 $weight += $oneItem['WEIGHT']*$oneItem['QUANTITY_IN_SET'];
615 unset($oneItem);
616 }
617 foreach ($tracedItems as &$oneItem)
618 {
619 if ($oneItem['QUANTITY'] <= 0)
620 $itemQuantity = 0;
621 else
622 $itemQuantity = (int)floor($oneItem['QUANTITY']/$oneItem['QUANTITY_IN_SET']);
623
624 if ($quantity === null || $quantity > $itemQuantity)
625 $quantity = $itemQuantity;
626 if ($allItems)
627 $weight += $oneItem['WEIGHT']*$oneItem['QUANTITY_IN_SET'];
628 }
629 unset($oneItem);
630
631 $measure = CCatalogMeasure::getDefaultMeasure(true, false);
632
633 $fields = array(
634 'WEIGHT' => $weight,
635 'QUANTITY' => $quantity,
636 'QUANTITY_TRACE' => $quantityTrace,
637 'CAN_BUY_ZERO' => $canBuyZero,
638 'MEASURE' => $measure['ID'],
640 );
644 );
645
646 if ($productData = Catalog\ProductTable::getRowById($productID))
647 {
648 $fields['SUBSCRIBE'] = $productData['SUBSCRIBE'];
649 if(Catalog\SubscribeTable::checkPermissionSubscribe($productData['SUBSCRIBE']))
650 Catalog\SubscribeTable::setOldProductAvailable($productID, $productData['AVAILABLE']);
651 }
652
653 foreach(GetModuleEvents('catalog', 'OnBeforeProductSetAvailableUpdate', true) as $arEvent)
654 ExecuteModuleEventEx($arEvent, array($productID, &$fields));
655 //TODO: change to Catalog\Product\Model after blocked call recurrence
656 $update = $DB->PrepareUpdate('b_catalog_product', $fields);
657
658 $query = "update b_catalog_product set ".$update." where ID = ".$productID;
659 $DB->Query($query);
660
662
663 foreach (GetModuleEvents('catalog', 'OnProductSetAvailableUpdate', true) as $arEvent)
664 ExecuteModuleEventEx($arEvent, array($productID, $fields));
665
666 $query = "delete from b_catalog_measure_ratio where PRODUCT_ID = ".$productID;
667 $DB->Query($query);
668 $fields = array(
669 'PRODUCT_ID' => $productID,
670 'RATIO' => 1,
671 'IS_DEFAULT' => 'Y'
672 );
673 $insert = $DB->PrepareInsert('b_catalog_measure_ratio', $fields);
674 $query = "insert into b_catalog_measure_ratio (".$insert[0].") values(".$insert[1].")";
675 $DB->Query($query);
676
677 return true;
678 }
679
680 protected static function createSetItemsParamsFromUpdate($setID, $getProductID = false)
681 {
682 global $DB;
683 $result = array();
684
685 $getProductID = ($getProductID === true);
686 if ($getProductID)
687 {
688 $result = array(
689 'ITEM_ID' => 0,
690 'ITEMS' => array()
691 );
692 $query = 'select ID, ITEM_ID, QUANTITY from b_catalog_product_sets where SET_ID = '.$setID.' or ID = '.$setID;
693 $setIterator = $DB->Query($query);
694 while ($item = $setIterator->Fetch())
695 {
696 $item['ID'] = (int)$item['ID'];
697 if ($item['ID'] == $setID)
698 {
699 $result['ITEM_ID'] = $item['ID'];
700 }
701 else
702 {
703 $item['ITEM_ID'] = (int)$item['ITEM_ID'];
704 $result['ITEMS'][$item['ITEM_ID']] = array(
705 'QUANTITY_IN_SET' => $item['QUANTITY']
706 );
707 }
708 }
709 }
710 else
711 {
712 $query = 'select ITEM_ID, QUANTITY from b_catalog_product_sets where SET_ID = '.$setID;
713 $setIterator = $DB->Query($query);
714 while ($item = $setIterator->Fetch())
715 {
716 $item['ITEM_ID'] = (int)$item['ITEM_ID'];
717 $result[$item['ITEM_ID']] = array(
718 'QUANTITY_IN_SET' => $item['QUANTITY']
719 );
720 }
721 }
722 return $result;
723 }
724}
$arResult
Определения generate_coupon.php:16
static update($id, array $data)
Определения entity.php:229
const STATUS_YES
Определения product.php:66
const TYPE_SET
Определения product.php:71
const STATUS_NO
Определения product.php:67
const TYPE_PRODUCT
Определения product.php:70
static onProductSetAvailableUpdate($productId, $fields)
Определения subscribe.php:340
static checkPermissionSubscribe($subscribe)
Определения subscribe.php:434
static setOldProductAvailable($productId, $available)
Определения subscribe.php:446
static getRowById($id, array $parameters=[])
Определения datamanager.php:380
static getList(array $parameters=array())
Определения datamanager.php:431
static normalizeArrayValuesByInt(&$map, $sorted=true)
Определения collection.php:150
static PrepareSql(&$arFields, $arOrder, $arFilter, $arGroupBy, $arSelectFields)
Определения catalog.php:389
static isAvailable($product)
Определения product.php:180
static fillSetItemsParams(&$items)
Определения product_set.php:774
static createSetItemsParamsFromAdd($items)
Определения product_set.php:795
static calculateSetParams($productID, $items)
Определения product_set.php:590
static update($intID, $arFields)
Определения product_set.php:61
static isProductInSet($intProductID, $intSetType=0)
Определения product_set.php:287
static deleteFromSet($intID, $arEx)
Определения product_set.php:574
static getAllSetsByProduct($intProductID, $intSetType)
Определения product_set.php:341
static getSetID($intID)
Определения product_set.php:549
static getList($arOrder=array(), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelect=array())
Определения product_set.php:191
static isProductHaveSet($arProductID, $intSetType=0)
Определения product_set.php:313
static createSetItemsParamsFromUpdate($setID, $getProductID=false)
Определения product_set.php:680
static getSetByID($intID)
Определения product_set.php:415
static add($arFields)
Определения product_set.php:10
static recalculateSetsByProduct($product)
Определения product_set.php:472
$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
$query
Определения get_search.php:11
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
return false
Определения prolog_main_admin.php:185
$items
Определения template.php:224
$arRes
Определения options.php:104
$arFilter
Определения user_search.php:106
$dbRes
Определения yandex_detail.php:168
$iterator
Определения yandex_run.php:610
$fields
Определения yandex_run.php:501