1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
price.php
См. документацию.
1<?php
2namespace Bitrix\Catalog\Model;
3
4use Bitrix\Catalog;
5use Bitrix\Currency;
6use Bitrix\Main;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\ORM;
9use Bitrix\Iblock;
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
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
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 = [];
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 {
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 $fields['TIMESTAMP_X'] = new Main\Type\DateTime();
485
486 $data['fields'] = $fields;
487 }
488 unset($fields);
489 }
490
498 protected static function runAddExternalActions($id, array $data): void
499 {
500 if ((int)$data['fields']['CATALOG_GROUP_ID'] === self::$basePriceType)
501 {
502 if (isset(self::$productPrices[$data['fields']['PRODUCT_ID']]))
503 {
504 unset(self::$productPrices[$data['fields']['PRODUCT_ID']]);
505 }
506 }
507 if (isset($data['actions']['RECOUNT_PRICES']))
508 {
509 self::recountPricesFromBase($id);
510 }
511 if (isset($data['actions']['PARENT_PRICE']))
512 {
514 $data['fields']['PRODUCT_ID'],
515 null,
517 [0 => $data['fields']['CATALOG_GROUP_ID']]
518 );
519 }
520 self::updateProductModificationTime($data['fields']['PRODUCT_ID']);
521 }
522
530 protected static function runUpdateExternalActions($id, array $data): void
531 {
532 $price = self::getCacheItem($id);
533 if ((int)$price['CATALOG_GROUP_ID'] === self::$basePriceType)
534 {
535 if (isset(self::$productPrices[$price['PRODUCT_ID']]))
536 {
537 unset(self::$productPrices[$price['PRODUCT_ID']]);
538 }
539 }
540 if (isset($data['actions']['RECOUNT_PRICES']))
541 {
542 self::recountPricesFromBase($id);
543 }
544 if (isset($data['actions']['PARENT_PRICE']))
545 {
546 $priceTypes = [0 => $price['CATALOG_GROUP_ID']];
547 if (
548 isset($price[self::PREFIX_OLD.'CATALOG_GROUP_ID'])
549 && $price[self::PREFIX_OLD.'CATALOG_GROUP_ID'] != $price['CATALOG_GROUP_ID']
550 )
551 $priceTypes[] = $price[self::PREFIX_OLD.'CATALOG_GROUP_ID'];
553 $price['PRODUCT_ID'], null, Catalog\ProductTable::TYPE_OFFER, $priceTypes);
554 if (
555 isset($price[self::PREFIX_OLD.'PRODUCT_ID'])
556 && $price[self::PREFIX_OLD.'PRODUCT_ID'] != $price['PRODUCT_ID']
557 )
558 Catalog\Product\Sku::calculatePrice($price[self::PREFIX_OLD.'PRODUCT_ID'], null, null, $priceTypes);
559 unset($priceTypes);
560 }
561 self::updateProductModificationTime($price['PRODUCT_ID']);
562 if (
563 isset($price[self::PREFIX_OLD.'PRODUCT_ID'])
564 && $price[self::PREFIX_OLD.'PRODUCT_ID'] != $price['PRODUCT_ID']
565 )
566 {
567 self::updateProductModificationTime($price[self::PREFIX_OLD.'PRODUCT_ID']);
568 }
569 unset($price);
570 }
571
578 protected static function runDeleteExternalActions($id): void
579 {
580 $price = self::getCacheItem($id);
581 $product = Product::getCacheItem($price[self::PREFIX_OLD.'PRODUCT_ID']);
582 if (!empty($product) && $product['TYPE'] == Catalog\ProductTable::TYPE_OFFER)
583 {
585 $price[self::PREFIX_OLD.'PRODUCT_ID'],
586 null,
588 [0 => $price[self::PREFIX_OLD.'CATALOG_GROUP_ID']]
589 );
590 }
591 if (!empty($product))
592 {
593 self::updateProductModificationTime($price[self::PREFIX_OLD.'PRODUCT_ID']);
594 }
595 unset($product, $price);
596 }
597
606 private static function checkQuantityRange(ORM\Data\Result $result, array &$fields)
607 {
608 if ($fields['QUANTITY_FROM'] !== null)
609 {
610 $fields['QUANTITY_FROM'] = (int)$fields['QUANTITY_FROM'];
611 if ($fields['QUANTITY_FROM'] <= 0)
612 $result->addError(new ORM\EntityError(
613 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_QUANTITY_FROM')
614 ));
615 }
616 if ($fields['QUANTITY_TO'] != null)
617 {
618 $fields['QUANTITY_TO'] = (int)$fields['QUANTITY_TO'];
619 if ($fields['QUANTITY_TO'] <= 0)
620 $result->addError(new ORM\EntityError(
621 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_QUANTITY_TO')
622 ));
623 }
624 if ($fields['QUANTITY_FROM'] !== null && $fields['QUANTITY_TO'] != null)
625 {
626 if ($fields['QUANTITY_FROM'] == 0 && $fields['QUANTITY_TO'] == 0)
627 {
628 $result->addError(new ORM\EntityError(
629 Loc::getMessage('BX_CATALOG_MODEL_PRICE_ERR_WRONG_QUANTITY_RANGE_ZERO')
630 ));
631 }
632 elseif ($fields['QUANTITY_FROM'] > $fields['QUANTITY_TO'])
633 {
634 $result->addError(new ORM\EntityError(
635 Loc::getMessage(
636 'BX_CATALOG_MODEL_PRICE_ERR_WRONG_QUANTITY_RANGE_INVERT',
637 ['#LEFT#' => $fields['QUANTITY_FROM'], '#RIGHT#' => $fields['QUANTITY_TO']]
638 )
639 ));
640 }
641 }
642 }
643
651 private static function checkPriceValue($price)
652 {
653 $result = null;
654
655 if ($price !== null)
656 {
657 if (is_string($price))
658 {
659 if ($price !== '' && is_numeric($price))
660 {
661 $price = (float)$price;
662 if (is_finite($price))
663 $result = $price;
664 }
665 }
666 elseif (
667 is_int($price)
668 || (is_float($price) && is_finite($price))
669 )
670 {
671 $result = $price;
672 }
673 }
674
675 return $result;
676 }
677
678 private static function loadSettings()
679 {
680 self::$separateSkuMode = Main\Config\Option::get('catalog', 'show_catalog_tab_with_offers') === 'Y';
681
682 self::$extraList = [];
683 foreach (Catalog\ExtraTable::getExtraList() as $row)
684 {
685 self::$extraList[$row['ID']] = (100 + (float)$row['PERCENTAGE']) / 100;
686 }
687 unset($row);
688
689 self::$basePriceType = (int)Catalog\GroupTable::getBasePriceTypeId();
690 self::$priceTypes = Catalog\GroupTable::getTypeList();;
691 }
692
693 private static function calculatePriceFromBase($id, array &$fields)
694 {
695 $correct = false;
696 $copyFields = $fields;
697 if (
698 !isset($fields['PRODUCT_ID'])
699 || !isset($fields['CATALOG_GROUP_ID'])
700 || !array_key_exists('QUANTITY_FROM', $fields)
701 || !array_key_exists('QUANTITY_TO', $fields)
702 )
703 {
704 if ($id !== null)
705 {
706
707 $iterator = self::getList([
708 'select' => ['ID', 'PRODUCT_ID', 'CATALOG_GROUP_ID', 'QUANTITY_FROM', 'QUANTITY_TO'],
709 'filter' => ['=ID' => $id]
710 ]);
711 $data = $iterator->fetch();
712 unset($iterator);
713 if (!empty($data))
714 {
715 $copyFields = array_merge($data, $copyFields);
716 $correct = true;
717 }
718 unset($data);
719 }
720 }
721 else
722 {
723 $correct = true;
724 }
725
726 if (!$correct)
727 return;
728
729 $productId = $copyFields['PRODUCT_ID'];
730
731 if (!isset(self::$productPrices[$productId]))
732 self::loadProductBasePrices($productId);
733
734 $index = self::getPriceIndex($copyFields);
735 if (!isset(self::$productPrices[$productId][$index]))
736 return;
737
738 $fields['PRICE'] = self::$productPrices[$productId][$index]['PRICE']*self::$extraList[$copyFields['EXTRA_ID']];
739 $fields['CURRENCY'] = self::$productPrices[$productId][$index]['CURRENCY'];
740 }
741
742 private static function getPriceIndex(array $row): string
743 {
744 return ($row['QUANTITY_FROM'] === null ? 'ZERO' : $row['QUANTITY_FROM']).
745 '-'.($row['QUANTITY_TO'] === null ? 'INF' : $row['QUANTITY_TO']);
746 }
747
748 private static function loadProductBasePrices($productId)
749 {
750 self::$productPrices = [
751 $productId => []
752 ];
753 $iterator = Catalog\PriceTable::getList([
754 'select' => ['ID', 'PRICE', 'CURRENCY', 'QUANTITY_FROM', 'QUANTITY_TO'],
755 'filter' => ['=PRODUCT_ID' => $productId, '=CATALOG_GROUP_ID' => self::$basePriceType]
756 ]);
757 while ($row = $iterator->fetch())
758 self::$productPrices[$productId][self::getPriceIndex($row)] = $row;
759 unset($row, $iterator);
760 }
761
762 public static function clearSettings(): void
763 {
764 parent::clearSettings();
765
766 self::$separateSkuMode = null;
767 self::$basePriceType = null;
768 self::$priceTypes = null;
769 self::$extraList = null;
770 }
771
772 private static function updateProductModificationTime(int $productId): void
773 {
774 if (!isset(self::$productList[$productId]))
775 {
776 self::$productList[$productId] = true;
778 if (self::$queryElementDate === null)
779 {
780 $helper = $conn->getSqlHelper();
781 self::$queryElementDate = 'update ' . $helper->quote(Iblock\ElementTable::getTableName())
782 . ' set '.$helper->quote('TIMESTAMP_X') . ' = '.$helper->getCurrentDateTimeFunction()
783 . ' where '.$helper->quote('ID') . '=';
784 }
785 $conn->queryExecute(self::$queryElementDate . $productId);
786 }
787 }
788}
static getExtraList()
Определения extra.php:124
static getBasePriceTypeId()
Определения group.php:261
static getCacheItem($id, bool $load=false)
Определения entity.php:396
static prepareForUpdate(ORM\Data\UpdateResult $result, $id, array &$data)
Определения price.php:307
static getDefaultCachedFieldList()
Определения price.php:46
static recountPricesFromBase($id)
Определения price.php:57
static prepareForAdd(ORM\Data\AddResult $result, $id, array &$data)
Определения price.php:152
static clearSettings()
Определения price.php:762
static runDeleteExternalActions($id)
Определения price.php:578
static getTabletClassName()
Определения price.php:36
static runUpdateExternalActions($id, array $data)
Определения price.php:530
static runAddExternalActions($id, array $data)
Определения price.php:498
static calculatePrice($id, $iblockId=null, $type=null, array $priceTypes=[])
Определения sku.php:396
const TYPE_EMPTY_SKU
Определения product.php:75
const TYPE_SKU
Определения product.php:72
const TYPE_OFFER
Определения product.php:73
static getTableName()
Определения elementtable.php:83
static getConnection($name="")
Определения application.php:638
static getList(array $parameters=array())
Определения datamanager.php:431
static update($primary, array $data)
Определения datamanager.php:1256
static filter()
Определения query.php:906
static GetByID($currency)
Определения currency.php:453
$data['IS_AVAILABLE']
Определения .description.php:13
</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
$defaultValues
Определения iblock_catalog_edit.php:124
$filter
Определения iblock_catalog_list.php:54
Определения aliases.php:105
Определения ufield.php:9
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$currency
Определения template.php:266
$iterator
Определения yandex_run.php:610
$fields
Определения yandex_run.php:501