Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
price.php
1<?php
3
10
11Loc::loadMessages(__FILE__);
12
13class Price extends Entity
14{
16 private static $separateSkuMode = null;
17
18 private static $productPrices = [];
19
20 private static $basePriceType = null;
21
22 private static $priceTypes = null;
23
24 private static $extraList = null;
25
26 private static $productList = [];
27
29 private static $queryElementDate;
30
36 public static function getTabletClassName(): string
37 {
38 return '\Bitrix\Catalog\PriceTable';
39 }
40
46 protected static function getDefaultCachedFieldList(): array
47 {
48 return [
49 'ID',
50 'PRODUCT_ID',
51 'CATALOG_GROUP_ID',
52 'PRICE',
53 'CURRENCY'
54 ];
55 }
56
57 public static function recountPricesFromBase($id): bool
58 {
59 $id = (int)$id;
60 if ($id <= 0)
61 return false;
62
63 if (self::$separateSkuMode === null)
64 {
65 self::loadSettings();
66 }
67
68 if (empty(self::$extraList) || self::$basePriceType == 0)
69 {
70 return false;
71 }
72
73 $iterator = Catalog\PriceTable::getList([
74 'select' => ['ID', 'PRODUCT_ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY', 'QUANTITY_FROM', 'QUANTITY_TO'],
75 'filter' => ['=ID' => $id]
76 ]);
77 $price = $iterator->fetch();
78 unset($iterator);
79 if (empty($price))
80 return false;
81
82 $price['CATALOG_GROUP_ID'] = (int)$price['CATALOG_GROUP_ID'];
83 if ($price['CATALOG_GROUP_ID'] != self::$basePriceType)
84 return false;
85
86 $productId = (int)$price['PRODUCT_ID'];
87 $product = Product::getCacheItem($productId, true);
88 if (empty($product))
89 return false;
90
91 if (
92 !self::$separateSkuMode
93 && ($product['TYPE'] == Catalog\ProductTable::TYPE_SKU || $product['TYPE'] == Catalog\ProductTable::TYPE_EMPTY_SKU)
94 )
95 return false;
96
97 //TODO: replace CCurrency::GetByID to d7 cached method
98 $currency = \CCurrency::GetByID($price['CURRENCY']);
99 if (empty($currency))
100 return false;
101
102 $filter = ORM\Query\Query::filter();
103 $filter->where('PRODUCT_ID', '=', $productId);
104 $filter->where('CATALOG_GROUP_ID', '!=', self::$basePriceType);
105 $filter->whereIn('EXTRA_ID', array_keys(self::$extraList));
106 if ($price['QUANTITY_FROM'] === null)
107 $filter->whereNull('QUANTITY_FROM');
108 else
109 $filter->where('QUANTITY_FROM', '=', (int)$price['QUANTITY_FROM']);
110
111 if ($price['QUANTITY_TO'] === null)
112 $filter->whereNull('QUANTITY_TO');
113 else
114 $filter->where('QUANTITY_TO', '=', (int)$price['QUANTITY_TO']);
115
116 $datetime = new Main\Type\DateTime();
117 $updatePriceTypes = [];
118 $iterator = Catalog\PriceTable::getList([
119 'select' => ['ID', 'EXTRA_ID', 'CATALOG_GROUP_ID', 'QUANTITY_FROM', 'QUANTITY_TO'],
120 'filter' => $filter
121 ]);
122 while ($row = $iterator->fetch())
123 {
124 $fields = [
125 'PRICE' => $price['PRICE']*self::$extraList[$row['EXTRA_ID']],
126 'CURRENCY' => $price['CURRENCY'],
127 'TIMESTAMP_X' => $datetime
128 ];
129 $fields['PRICE_SCALE'] = $fields['PRICE']*$currency['CURRENT_BASE_RATE'];
130
131 $result = Catalog\PriceTable::update($row['ID'], $fields);
132 if ($result->isSuccess())
133 $updatePriceTypes[$row['CATALOG_TYPE_ID']] = $row['CATALOG_TYPE_ID'];
134 }
135 unset($result, $fields, $currency, $index);
136 unset($row, $iterator);
137
138 if (!empty($updatePriceTypes) && $product['TYPE'] == Catalog\ProductTable::TYPE_OFFER)
139 Catalog\Product\Sku::calculatePrice($productId, null, Catalog\ProductTable::TYPE_OFFER, $updatePriceTypes);
140
141 return true;
142 }
143
152 protected static function prepareForAdd(ORM\Data\AddResult $result, $id, array &$data): void
153 {
154 $fields = $data['fields'];
155 parent::prepareForAdd($result, $id, $fields);
156 if (!$result->isSuccess())
157 return;
158
159 if (self::$separateSkuMode === null)
160 {
161 self::loadSettings();
162 }
163
164 static $defaultValues = null,
165 $blackList = null;
166
167 if ($defaultValues === null)
168 {
169 $defaultValues = [
170 'PRODUCT_ID' => 0,
171 'CATALOG_GROUP_ID' => 0,
172 'EXTRA_ID' => null,
173 'PRICE' => null,
174 'CURRENCY' => null,
175 'QUANTITY_FROM' => null,
176 'QUANTITY_TO' => null,
177 'TMP_ID' => null
178 ];
179
180 $blackList = [
181 'ID' => true
182 ];
183 }
184
185 $fields = array_merge($defaultValues, array_diff_key($fields, $blackList));
186
187 $fields['PRODUCT_ID'] = (int)$fields['PRODUCT_ID'];
188 if ($fields['PRODUCT_ID'] <= 0)
189 {
190 $result->addError(new ORM\EntityError(
191 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_PRODUCT_ID')
192 ));
193 return;
194 }
195 $fields['CATALOG_GROUP_ID'] = (int)$fields['CATALOG_GROUP_ID'];
196 if (!isset(self::$priceTypes[$fields['CATALOG_GROUP_ID']]))
197 {
198 $result->addError(new ORM\EntityError(
199 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_CATALOG_GROUP_ID')
200 ));
201 return;
202 }
203 else
204 {
205 if ($fields['CATALOG_GROUP_ID'] == self::$basePriceType)
206 {
207 $fields['EXTRA_ID'] = null;
208 if (isset($data['actions']['OLD_RECOUNT']))
209 {
210 if ($data['actions']['OLD_RECOUNT'] === true)
211 $data['actions']['PARENT_PRICE'] = true;
212 }
213 }
214 }
215
216 if ($fields['TMP_ID'] !== null)
217 $fields['TMP_ID'] = mb_substr($fields['TMP_ID'], 0, 40);
218
219 static::checkQuantityRange($result, $fields);
220
221 if ($fields['EXTRA_ID'] !== null)
222 {
223 $fields['EXTRA_ID'] = (int)$fields['EXTRA_ID'];
224 if (!isset(self::$extraList[$fields['EXTRA_ID']]))
225 {
226 unset($fields['EXTRA_ID']);
227 }
228 else
229 {
230 if (
231 (!isset($fields['PRICE']) && !isset($fields['CURRENCY']))
232 || (isset($data['actions']['OLD_RECOUNT']) && $data['actions']['OLD_RECOUNT'] === true)
233 )
234 self::calculatePriceFromBase(null, $fields);
235 }
236 }
237
238 if ($fields['PRICE'] === null)
239 {
240 $result->addError(new ORM\EntityError(
241 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_PRICE')
242 ));
243 }
244 else
245 {
246 $fields['PRICE'] = self::checkPriceValue($fields['PRICE']);
247 if ($fields['PRICE'] === null || $fields['PRICE'] < 0)
248 {
249 $result->addError(new ORM\EntityError(
250 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_PRICE')
251 ));
252 }
253 }
254 $fields['CURRENCY'] = (string)$fields['CURRENCY'];
255 if (!Currency\CurrencyManager::isCurrencyExist($fields['CURRENCY']))
256 {
257 $result->addError(new ORM\EntityError(
258 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_CURRENCY')
259 ));
260 }
261
262 if ($result->isSuccess())
263 {
264 $fields['TIMESTAMP_X'] = new Main\Type\DateTime();
265 if (isset($fields['PRICE_SCALE']))
266 $fields['PRICE_SCALE'] = self::checkPriceValue($fields['PRICE_SCALE']);
267 // self::checkPriceValue return float or null
268 if (!isset($fields['PRICE_SCALE']))
269 {
270 //TODO: replace CCurrency::GetByID to d7 cached method
271 $currency = \CCurrency::GetByID($fields['CURRENCY']);
272 $fields['PRICE_SCALE'] = $fields['PRICE']*$currency['CURRENT_BASE_RATE'];
273 unset($currency);
274 }
275
276 if (isset($data['actions']['PARENT_PRICE']))
277 unset($data['actions']['PARENT_PRICE']);
278 if (!self::$separateSkuMode)
279 {
280 $product = Product::getCacheItem($fields['PRODUCT_ID'], true);
281 if (!empty($product) && $product['TYPE'] == Catalog\ProductTable::TYPE_OFFER)
282 $data['actions']['PARENT_PRICE'] = true;
283 unset($product);
284 }
285 if (isset($data['actions']['RECOUNT_PRICES']))
286 {
287 if ($fields['CATALOG_GROUP_ID'] != self::$basePriceType)
288 unset($data['actions']['RECOUNT_PRICES']);
289 else
290 $data['actions']['RECOUNT_PRICES'] = true;
291 }
292
293 $data['fields'] = $fields;
294 }
295
296 unset($fields);
297 }
298
307 protected static function prepareForUpdate(ORM\Data\UpdateResult $result, $id, array &$data): void
308 {
309 $id = (int)$id;
310 if ($id <= 0)
311 {
312 $result->addError(new ORM\EntityError(
313 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_PRICE_ID')
314 ));
315 return;
316 }
317
318 if (self::$separateSkuMode === null)
319 {
320 self::loadSettings();
321 }
322
323 $fields = $data['fields'];
324 parent::prepareForUpdate($result, $id, $fields);
325 if (!$result->isSuccess())
326 return;
327
328 $blackList = [
329 'ID' => true
330 ];
331
332 $fields = array_diff_key($fields, $blackList);
333
334 if (array_key_exists('PRODUCT_ID', $fields))
335 {
336 $fields['PRODUCT_ID'] = (int)$fields['PRODUCT_ID'];
337 if ($fields['PRODUCT_ID'] <= 0)
338 $result->addError(new ORM\EntityError(
339 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_PRODUCT_ID')
340 ));
341 }
342
343 if (array_key_exists('CATALOG_GROUP_ID', $fields))
344 {
345 $fields['CATALOG_GROUP_ID'] = (int)$fields['CATALOG_GROUP_ID'];
346 if (!isset(self::$priceTypes[$fields['CATALOG_GROUP_ID']]))
347 {
348 $result->addError(new ORM\EntityError(
349 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_CATALOG_GROUP_ID')
350 ));
351 }
352 else
353 {
354 if ($fields['CATALOG_GROUP_ID'] == self::$basePriceType)
355 {
356 $fields['EXTRA_ID'] = null;
357 if (isset($data['actions']['OLD_RECOUNT']))
358 {
359 if ($data['actions']['OLD_RECOUNT'] === true)
360 $data['actions']['PARENT_PRICE'] = true;
361 }
362 }
363 }
364 }
365
366 if (isset($fields['TMP_ID']))
367 $fields['TMP_ID'] = mb_substr($fields['TMP_ID'], 0, 40);
368
369 $existQuantityFrom = array_key_exists('QUANTITY_FROM', $fields);
370 $existQuantityTo = array_key_exists('QUANTITY_TO', $fields);
371 if ($existQuantityFrom != $existQuantityTo)
372 {
373 if ($existQuantityFrom)
374 $result->addError(new ORM\EntityError(
375 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_QUANTITY_RANGE_LEFT_BORDER_ONLY')
376 ));
377 else
378 $result->addError(new ORM\EntityError(
379 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_QUANTITY_RANGE_RIGHT_BORDER_ONLY')
380 ));
381 }
382 else
383 {
384 if ($existQuantityFrom)
385 static::checkQuantityRange($result, $fields);
386 }
387 unset($existQuantityTo, $existQuantityFrom);
388
389 if (isset($fields['EXTRA_ID']))
390 {
391 $fields['EXTRA_ID'] = (int)$fields['EXTRA_ID'];
392 if (!isset(self::$extraList[$fields['EXTRA_ID']]))
393 {
394 $result->addError(new ORM\EntityError(
395 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_EXTRA_ID')
396 ));
397 }
398 else
399 {
400 if (
401 (!isset($fields['PRICE']) && !isset($fields['CURRENCY']))
402 || (isset($data['actions']['OLD_RECOUNT']) && $data['actions']['OLD_RECOUNT'] === true)
403 )
404 self::calculatePriceFromBase($id, $fields);
405 }
406 }
407
408 if (array_key_exists('PRICE', $fields))
409 {
410 $fields['PRICE'] = self::checkPriceValue($fields['PRICE']);
411 if ($fields['PRICE'] === null || $fields['PRICE'] < 0)
412 {
413 $result->addError(new ORM\EntityError(
414 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_PRICE')
415 ));
416 }
417 }
418
419 if (array_key_exists('CURRENCY', $fields))
420 {
421 $fields['CURRENCY'] = (string)$fields['CURRENCY'];
422 if (!Currency\CurrencyManager::isCurrencyExist($fields['CURRENCY']))
423 {
424 $result->addError(new ORM\EntityError(
425 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_CURRENCY')
426 ));
427 }
428 }
429
430 if ($result->isSuccess())
431 {
432 if (isset($data['actions']['PARENT_PRICE']))
433 unset($data['actions']['PARENT_PRICE']);
434
435 $priceScale = !isset($fields['PRICE_SCALE']) && (isset($fields['PRICE']) || isset($fields['CURRENCY']));
436 $needCalculatePrice = (
437 !self::$separateSkuMode
438 && (
439 isset($fields['PRODUCT_ID'])
440 || isset($fields['CATALOG_GROUP_ID'])
441 || isset($fields['PRICE'])
442 || isset($fields['CURRENCY'])
443 )
444 );
445 $recountPrices = isset($data['actions']['RECOUNT_PRICES']);
446
447 $copyFields = [];
448 if ($priceScale || $needCalculatePrice || $recountPrices)
449 $copyFields = array_merge(static::getCacheItem($id, true), $fields);
450
451 if (isset($fields['PRICE_SCALE']))
452 {
453 $fields['PRICE_SCALE'] = self::checkPriceValue($fields['PRICE_SCALE']);
454 if ($fields['PRICE_SCALE'] === null || $fields['PRICE_SCALE'] < 0)
455 unset($fields['PRICE_SCALE']);
456 }
457 if (!isset($fields['PRICE_SCALE']))
458 {
459 if (isset($fields['PRICE']) || isset($fields['CURRENCY']))
460 {
461 //TODO: replace CCurrency::GetByID to d7 cached method
462 $currency = \CCurrency::GetByID($copyFields['CURRENCY']);
463 $fields['PRICE_SCALE'] = $copyFields['PRICE']*$currency['CURRENT_BASE_RATE'];
464 unset($currency);
465 }
466 }
467 if ($needCalculatePrice)
468 {
469 $product = Product::getCacheItem($copyFields['PRODUCT_ID'], true);
470 if (!empty($product) && $product['TYPE'] == Catalog\ProductTable::TYPE_OFFER)
471 $data['actions']['PARENT_PRICE'] = true;
472 unset($product);
473 }
474 if (isset($data['actions']['RECOUNT_PRICES']))
475 {
476 if ($copyFields['CATALOG_GROUP_ID'] != self::$basePriceType)
477 unset($data['actions']['RECOUNT_PRICES']);
478 else
479 $data['actions']['RECOUNT_PRICES'] = true;
480 }
481
482 unset($copyFields);
483
484 $data['fields'] = $fields;
485 }
486 unset($fields);
487 }
488
496 protected static function runAddExternalActions($id, array $data): void
497 {
498 if ((int)$data['fields']['CATALOG_GROUP_ID'] === self::$basePriceType)
499 {
500 if (isset(self::$productPrices[$data['fields']['PRODUCT_ID']]))
501 {
502 unset(self::$productPrices[$data['fields']['PRODUCT_ID']]);
503 }
504 }
505 if (isset($data['actions']['RECOUNT_PRICES']))
506 {
507 self::recountPricesFromBase($id);
508 }
509 if (isset($data['actions']['PARENT_PRICE']))
510 {
511 Catalog\Product\Sku::calculatePrice(
512 $data['fields']['PRODUCT_ID'],
513 null,
515 [0 => $data['fields']['CATALOG_GROUP_ID']]
516 );
517 }
518 self::updateProductModificationTime($data['fields']['PRODUCT_ID']);
519 }
520
528 protected static function runUpdateExternalActions($id, array $data): void
529 {
530 $price = self::getCacheItem($id);
531 if ((int)$price['CATALOG_GROUP_ID'] === self::$basePriceType)
532 {
533 if (isset(self::$productPrices[$price['PRODUCT_ID']]))
534 {
535 unset(self::$productPrices[$price['PRODUCT_ID']]);
536 }
537 }
538 if (isset($data['actions']['RECOUNT_PRICES']))
539 {
540 self::recountPricesFromBase($id);
541 }
542 if (isset($data['actions']['PARENT_PRICE']))
543 {
544 $priceTypes = [0 => $price['CATALOG_GROUP_ID']];
545 if (
546 isset($price[self::PREFIX_OLD.'CATALOG_GROUP_ID'])
547 && $price[self::PREFIX_OLD.'CATALOG_GROUP_ID'] != $price['CATALOG_GROUP_ID']
548 )
549 $priceTypes[] = $price[self::PREFIX_OLD.'CATALOG_GROUP_ID'];
550 Catalog\Product\Sku::calculatePrice(
551 $price['PRODUCT_ID'], null, Catalog\ProductTable::TYPE_OFFER, $priceTypes);
552 if (
553 isset($price[self::PREFIX_OLD.'PRODUCT_ID'])
554 && $price[self::PREFIX_OLD.'PRODUCT_ID'] != $price['PRODUCT_ID']
555 )
556 Catalog\Product\Sku::calculatePrice($price[self::PREFIX_OLD.'PRODUCT_ID'], null, null, $priceTypes);
557 unset($priceTypes);
558 }
559 self::updateProductModificationTime($price['PRODUCT_ID']);
560 if (
561 isset($price[self::PREFIX_OLD.'PRODUCT_ID'])
562 && $price[self::PREFIX_OLD.'PRODUCT_ID'] != $price['PRODUCT_ID']
563 )
564 {
565 self::updateProductModificationTime($price[self::PREFIX_OLD.'PRODUCT_ID']);
566 }
567 unset($price);
568 }
569
576 protected static function runDeleteExternalActions($id): void
577 {
578 $price = self::getCacheItem($id);
579 $product = Product::getCacheItem($price[self::PREFIX_OLD.'PRODUCT_ID']);
580 if (!empty($product) && $product['TYPE'] == Catalog\ProductTable::TYPE_OFFER)
581 {
582 Catalog\Product\Sku::calculatePrice(
583 $price[self::PREFIX_OLD.'PRODUCT_ID'],
584 null,
586 [0 => $price[self::PREFIX_OLD.'CATALOG_GROUP_ID']]
587 );
588 }
589 if (!empty($product))
590 {
591 self::updateProductModificationTime($price[self::PREFIX_OLD.'PRODUCT_ID']);
592 }
593 unset($product, $price);
594 }
595
604 private static function checkQuantityRange(ORM\Data\Result $result, array &$fields)
605 {
606 if ($fields['QUANTITY_FROM'] !== null)
607 {
608 $fields['QUANTITY_FROM'] = (int)$fields['QUANTITY_FROM'];
609 if ($fields['QUANTITY_FROM'] <= 0)
610 $result->addError(new ORM\EntityError(
611 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_QUANTITY_FROM')
612 ));
613 }
614 if ($fields['QUANTITY_TO'] != null)
615 {
616 $fields['QUANTITY_TO'] = (int)$fields['QUANTITY_TO'];
617 if ($fields['QUANTITY_TO'] <= 0)
618 $result->addError(new ORM\EntityError(
619 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_QUANTITY_TO')
620 ));
621 }
622 if ($fields['QUANTITY_FROM'] !== null && $fields['QUANTITY_TO'] != null)
623 {
624 if ($fields['QUANTITY_FROM'] == 0 && $fields['QUANTITY_TO'] == 0)
625 {
626 $result->addError(new ORM\EntityError(
627 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_QUANTITY_RANGE_ZERO')
628 ));
629 }
630 elseif ($fields['QUANTITY_FROM'] > $fields['QUANTITY_TO'])
631 {
632 $result->addError(new ORM\EntityError(
634 'BX_CATALOG_MODEL_PRICE_ERR_WRONG_QUANTITY_RANGE_INVERT',
635 ['#LEFT#' => $fields['QUANTITY_FROM'], '#RIGHT#' => $fields['QUANTITY_TO']]
636 )
637 ));
638 }
639 }
640 }
641
649 private static function checkPriceValue($price)
650 {
651 $result = null;
652
653 if ($price !== null)
654 {
655 if (is_string($price))
656 {
657 if ($price !== '' && is_numeric($price))
658 {
659 $price = (float)$price;
660 if (is_finite($price))
661 $result = $price;
662 }
663 }
664 elseif (
665 is_int($price)
666 || (is_float($price) && is_finite($price))
667 )
668 {
669 $result = $price;
670 }
671 }
672
673 return $result;
674 }
675
676 private static function loadSettings()
677 {
678 self::$separateSkuMode = Main\Config\Option::get('catalog', 'show_catalog_tab_with_offers') === 'Y';
679
680 self::$extraList = [];
681 foreach (Catalog\ExtraTable::getExtraList() as $row)
682 {
683 self::$extraList[$row['ID']] = (100 + (float)$row['PERCENTAGE']) / 100;
684 }
685 unset($row);
686
687 self::$basePriceType = (int)Catalog\GroupTable::getBasePriceTypeId();
688 self::$priceTypes = Catalog\GroupTable::getTypeList();;
689 }
690
691 private static function calculatePriceFromBase($id, array &$fields)
692 {
693 $correct = false;
694 $copyFields = $fields;
695 if (
696 !isset($fields['PRODUCT_ID'])
697 || !isset($fields['CATALOG_GROUP_ID'])
698 || !array_key_exists('QUANTITY_FROM', $fields)
699 || !array_key_exists('QUANTITY_TO', $fields)
700 )
701 {
702 if ($id !== null)
703 {
704
705 $iterator = self::getList([
706 'select' => ['ID', 'PRODUCT_ID', 'CATALOG_GROUP_ID', 'QUANTITY_FROM', 'QUANTITY_TO'],
707 'filter' => ['=ID' => $id]
708 ]);
709 $data = $iterator->fetch();
710 unset($iterator);
711 if (!empty($data))
712 {
713 $copyFields = array_merge($data, $copyFields);
714 $correct = true;
715 }
716 unset($data);
717 }
718 }
719 else
720 {
721 $correct = true;
722 }
723
724 if (!$correct)
725 return;
726
727 $productId = $copyFields['PRODUCT_ID'];
728
729 if (!isset(self::$productPrices[$productId]))
730 self::loadProductBasePrices($productId);
731
732 $index = self::getPriceIndex($copyFields);
733 if (!isset(self::$productPrices[$productId][$index]))
734 return;
735
736 $fields['PRICE'] = self::$productPrices[$productId][$index]['PRICE']*self::$extraList[$copyFields['EXTRA_ID']];
737 $fields['CURRENCY'] = self::$productPrices[$productId][$index]['CURRENCY'];
738 }
739
740 private static function getPriceIndex(array $row): string
741 {
742 return ($row['QUANTITY_FROM'] === null ? 'ZERO' : $row['QUANTITY_FROM']).
743 '-'.($row['QUANTITY_TO'] === null ? 'INF' : $row['QUANTITY_TO']);
744 }
745
746 private static function loadProductBasePrices($productId)
747 {
748 self::$productPrices = [
749 $productId => []
750 ];
751 $iterator = Catalog\PriceTable::getList([
752 'select' => ['ID', 'PRICE', 'CURRENCY', 'QUANTITY_FROM', 'QUANTITY_TO'],
753 'filter' => ['=PRODUCT_ID' => $productId, '=CATALOG_GROUP_ID' => self::$basePriceType]
754 ]);
755 while ($row = $iterator->fetch())
756 self::$productPrices[$productId][self::getPriceIndex($row)] = $row;
757 unset($row, $iterator);
758 }
759
760 public static function clearSettings(): void
761 {
762 parent::clearSettings();
763
764 self::$separateSkuMode = null;
765 self::$basePriceType = null;
766 self::$priceTypes = null;
767 self::$extraList = null;
768 }
769
770 private static function updateProductModificationTime(int $productId): void
771 {
772 if (!isset(self::$productList[$productId]))
773 {
774 self::$productList[$productId] = true;
775 $conn = Main\Application::getConnection();
776 if (self::$queryElementDate === null)
777 {
778 $helper = $conn->getSqlHelper();
779 self::$queryElementDate = 'update ' . $helper->quote(Iblock\ElementTable::getTableName())
780 . ' set '.$helper->quote('TIMESTAMP_X') . ' = '.$helper->getCurrentDateTimeFunction()
781 . ' where '.$helper->quote('ID') . '=';
782 }
783 $conn->queryExecute(self::$queryElementDate . $productId);
784 }
785 }
786}
static getBasePriceTypeId()
Definition group.php:248
static getCacheItem($id, bool $load=false)
Definition entity.php:396
static prepareForUpdate(ORM\Data\UpdateResult $result, $id, array &$data)
Definition price.php:307
static getDefaultCachedFieldList()
Definition price.php:46
static recountPricesFromBase($id)
Definition price.php:57
static prepareForAdd(ORM\Data\AddResult $result, $id, array &$data)
Definition price.php:152
static runDeleteExternalActions($id)
Definition price.php:576
static getTabletClassName()
Definition price.php:36
static runUpdateExternalActions($id, array $data)
Definition price.php:528
static runAddExternalActions($id, array $data)
Definition price.php:496
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29