1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
productaction.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Grid;
4
5use Bitrix\Main;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Iblock;
8use Bitrix\Catalog;
9use Bitrix\Catalog\Access\ActionDictionary;
10use Bitrix\Catalog\Access\AccessController;
11use Bitrix\Crm;
12use Bitrix\Main\ORM;
13use Bitrix\Sale;
14
16{
17 public const SET_FIELD = 'product_field';
18 public const CHANGE_PRICE = 'change_price';
19 public const CONVERT_PRODUCT_TO_SERVICE = 'convert_to_service';
20 public const CONVERT_SERVICE_TO_PRODUCT = 'convert_to_product';
21
22 public static function updateSectionList(int $iblockId, array $sections, array $fields): Main\Result
23 {
24 $result = new Main\Result();
25
26 if ($iblockId <= 0)
27 {
28 $result->addError(new Main\Error(
29 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_IBLOCK_ID')
30 ));
31 return $result;
32 }
33
34 $catalog = \CCatalogSku::GetInfoByIBlock($iblockId);
35 if (empty($catalog))
36 {
37 $result->addError(new Main\Error(
38 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_CATALOG')
39 ));
40 return $result;
41 }
42
43 if (empty($fields))
44 {
45 $result->addError(new Main\Error(
46 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_EMPTY_FIELDS')
47 ));
48 return $result;
49 }
50
51 $filter = [];
52 $allowedTypes = static::getAllowedProductTypes($catalog, $fields);
53 if (empty($allowedTypes))
54 {
55 $result->addError(new Main\Error(
56 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_FIELDS')
57 ));
58 return $result;
59 }
60 $filter['=TYPE'] = $allowedTypes;
61 unset($allowedTypes);
62
63 $sectionElements = self::getSectionProducts($iblockId, $sections, $filter);
64 if (empty($sectionElements))
65 {
66 return $result;
67 }
68
69 $sectionIdList = array_keys($sectionElements);
70 $sectionNames = [];
72 'select' => [
73 'ID',
74 'NAME',
75 ],
76 'filter' => [
77 '@ID' => $sectionIdList,
78 '=IBLOCK_ID' => $iblockId,
79 ],
80 'order' => ['ID' => 'ASC'],
81 ]);
82 while ($row = $iterator->fetch())
83 {
84 $row['ID'] = (int)$row['ID'];
85 $sectionNames[$row['ID']] = $row['NAME'];
86 }
87 unset($row, $iterator);
88
89 foreach ($sectionIdList as $sectionId)
90 {
91 $elementResult = static::updateElementList(
93 $sectionElements[$sectionId],
95 );
96 if (!$elementResult->isSuccess())
97 {
98 $result->addError(new Main\Error(
99 Loc::getMessage(
100 'BX_CATALOG_PRODUCT_ACTION_ERR_SECTION_PRODUCTS_UPDATE',
101 ['#ID#' => $sectionId, '#NAME#' => $sectionNames[$sectionId]]
102 ),
103 $sectionId
104 ));
105 }
106 }
107 unset($sectionId);
108 unset($sectionNames, $sectionIdList, $sectionElements);
109
110 return $result;
111 }
112
113 public static function updateElementList(int $iblockId, array $elementIds, array $fields): Main\Result
114 {
115 $result = new Main\Result();
116
117 if ($iblockId <= 0)
118 {
119 $result->addError(new Main\Error(
120 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_IBLOCK_ID')
121 ));
122 return $result;
123 }
125 if (empty($elementIds))
126 {
127 $result->addError(new Main\Error(
128 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_EMPTY_ELEMENTS')
129 ));
130 return $result;
131 }
132 if (empty($fields))
133 {
134 $result->addError(new Main\Error(
135 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_EMPTY_FIELDS')
136 ));
137 return $result;
138 }
139 $catalog = \CCatalogSku::GetInfoByIBlock($iblockId);
140 if (empty($catalog))
141 {
142 $result->addError(new Main\Error(
143 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_CATALOG')
144 ));
145 return $result;
146 }
147
148 $allowedTypes = static::getAllowedProductTypes($catalog, $fields);
149 if (empty($allowedTypes))
150 {
151 $result->addError(new Main\Error(
152 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_FIELDS')
153 ));
154 return $result;
155 }
156
157 $productResult = self::getProductListByTypeForModify($elementIds, $allowedTypes);
158 $data = $productResult->getData();
159 $newProducts = $data['NEW_PRODUCT_IDS'] ?? [];
160 $existProducts = $data['EXIST_PRODUCT_IDS'] ?? [];
161 unset($data);
162 if (!$productResult->isSuccess())
163 {
164 $result->addErrors($productResult->getErrors());
165 }
166 unset($productResult);
167
168 if (empty($newProducts) && empty($existProducts))
169 {
170 return $result;
171 }
172
173 $data = [
174 'fields' => $fields,
175 'external_fields' => [
176 'IBLOCK_ID' => $iblockId
177 ]
178 ];
179 foreach ($existProducts as $id)
180 {
181 $elementResult = Catalog\Model\Product::update($id, $data);
182 if (!$elementResult->isSuccess())
183 {
184 $result->addError(new Main\Error(
185 implode('; ', $elementResult->getErrorMessages()),
186 $id
187 ));
188 }
189 }
190 foreach ($newProducts as $id)
191 {
192 $data['fields']['ID'] = $id;
193 $elementResult = Catalog\Model\Product::add($data);
194 if (!$elementResult->isSuccess())
195 {
196 $result->addError(new Main\Error(
197 implode('; ', $elementResult->getErrorMessages()),
198 $id
199 ));
200 }
201 }
202 unset($elementResult, $id, $data);
203 unset($newProducts, $existProducts);
204 unset($blackList, $catalog);
205
206 return $result;
207 }
208
209 protected static function getSectionProducts(int $iblockId, array $sections, array $filter): ?array
210 {
211 global $USER;
212
213 if (!(isset($USER) && $USER instanceof \CUser))
214 {
215 return null;
216 }
217
218 if (!AccessController::getCurrent()->check(ActionDictionary::ACTION_PRODUCT_EDIT))
219 {
220 return null;
221 }
222
223 if ($iblockId <= 0)
224 {
225 return null;
226 }
228 if (empty($sections))
229 {
230 return null;
231 }
232
233 $filter['IBLOCK_ID'] = $iblockId;
234 $filter['INCLUDE_SUBSECTIONS'] = 'Y';
235 $filter['CHECK_PERMISSIONS'] = 'Y';
236 $filter['MIN_PERMISSION'] = 'R';
237
238 $dublicates = [];
239 $result = [];
240 foreach ($sections as $sectionId)
241 {
242 $result[$sectionId] = [];
243 $elements = [];
244 $filter['SECTION_ID'] = $sectionId;
245 $iterator = \CIBlockElement::GetList(
246 ['ID' => 'ASC'],
247 $filter,
248 false,
249 false,
250 ['ID']
251 );
252 while ($row = $iterator->fetch())
253 {
254 $id = (int)$row['ID'];
255 if (isset($dublicates[$id]))
256 {
257 continue;
258 }
259 $dublicates[$id] = true;
260 $elements[] = $id;
261 }
262 unset($id, $row, $iterator);
263
264 if (!empty($elements))
265 {
266 $operations = \CIBlockElementRights::UserHasRightTo(
267 $iblockId,
268 $elements,
269 '',
270 \CIBlockRights::RETURN_OPERATIONS
271 );
272 foreach ($elements as $elementId)
273 {
274 if (
275 isset($operations[$elementId]['element_edit'])
276 && isset($operations[$elementId]['element_edit_price'])
277 )
278 {
279 $result[$sectionId][] = $elementId;
280 }
281 }
282 unset($elementId);
283 unset($operations);
284 }
285 unset($elements);
286
287 if (empty($result[$sectionId]))
288 {
289 unset($result[$sectionId]);
290 }
291 }
292 unset($sectionId);
293 unset($dublicates);
294
295 return (!empty($result) ? $result : null);
296 }
297
299 {
300 static $list = null;
301
302 if (empty($fields))
303 {
304 return [];
305 }
306
307 if ($list === null)
308 {
309 $list = [
310 'WEIGHT',
311 'QUANTITY',
312 'QUANTITY_TRACE',
313 'CAN_BUY_ZERO',
314 'VAT_INCLUDED',
315 'VAT_ID',
316 'SUBSCRIBE',
317 'MEASURE',
318 'PURCHASING_PRICE',
319 'PURCHASING_CURRENCY',
320 ];
321 $baseTypes = [
324 CATALOG\ProductTable::TYPE_FREE_OFFER,
325 ];
326 if (
327 $catalog['CATALOG_TYPE'] === \CCatalogSku::TYPE_FULL
328 && Main\Config\Option::get('catalog', 'show_catalog_tab_with_offers') === 'Y'
329 )
330 {
331 $baseTypes[] = Catalog\ProductTable::TYPE_SKU;
332 }
333 $list = array_fill_keys($list, $baseTypes);
334 unset($baseTypes);
335
336 $list['VAT_INCLUDED'][] = Catalog\ProductTable::TYPE_SET;
337 $list['VAT_ID'][] = Catalog\ProductTable::TYPE_SET;
338 $list['SUBSCRIBE'][] = Catalog\ProductTable::TYPE_SET;
339
340 $list += Catalog\Product\SystemField::getAllowedProductTypes();
341 }
342
343 $result = [];
344 foreach (array_keys($fields) as $fieldName)
345 {
346 if (!isset($list[$fieldName]))
347 {
348 $result = [];
349 break;
350 }
351 $result[] = $list[$fieldName];
352 }
353
354 if (!empty($result))
355 {
356 if (count($result) === 1)
357 {
358 $result = reset($result);
359 }
360 else
361 {
362 $check = array_shift($result);
363 foreach ($result as $row)
364 {
365 $check = array_intersect($check, $row);
366 }
367 unset($row);
368 $result = array_values($check);
369 unset($check);
370 }
371 sort($result);
372 }
373
374 return $result;
375 }
376
377 public static function convertToServiceSectionList(int $iblockId, array $sections): Main\Result
378 {
379 return self::convertTypeSectionList($iblockId, $sections, Catalog\ProductTable::TYPE_PRODUCT);
380 }
381
382 public static function convertToProductSectionList(int $iblockId, array $sections): Main\Result
383 {
384 return self::convertTypeSectionList($iblockId, $sections, Catalog\ProductTable::TYPE_SERVICE);
385 }
386
387 public static function convertToServiceElementList(int $iblockId, array $elementIds): Main\Result
388 {
389 return self::convertTypeElementList($iblockId, $elementIds, Catalog\ProductTable::TYPE_PRODUCT);
390 }
391
392 public static function convertToProductElementList(int $iblockId, array $elementIds): Main\Result
393 {
394 return self::convertTypeElementList($iblockId, $elementIds, Catalog\ProductTable::TYPE_SERVICE);
395 }
396
397 private static function convertTypeSectionList(int $iblockId, array $sections, int $type): Main\Result
398 {
399 $result = new Main\Result();
400
401 if ($iblockId <= 0)
402 {
403 $result->addError(new Main\Error(
404 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_IBLOCK_ID')
405 ));
406
407 return $result;
408 }
409
410 $catalog = \CCatalogSku::GetInfoByIBlock($iblockId);
411 if (empty($catalog))
412 {
413 $result->addError(new Main\Error(
414 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_CATALOG')
415 ));
416
417 return $result;
418 }
419
420 $filter = [
421 '=TYPE' => $type,
422 ];
423
424 $sectionElements = self::getSectionProducts($iblockId, $sections, $filter);
425 if (empty($sectionElements))
426 {
427 return $result;
428 }
429
430 $sectionIdList = array_keys($sectionElements);
431 $sectionNames = [];
432 $iterator = Iblock\SectionTable::getList([
433 'select' => [
434 'ID',
435 'NAME',
436 ],
437 'filter' => [
438 '@ID' => $sectionIdList,
439 '=IBLOCK_ID' => $iblockId,
440 ],
441 'order' => ['ID' => 'ASC'],
442 ]);
443 while ($row = $iterator->fetch())
444 {
445 $row['ID'] = (int)$row['ID'];
446 $sectionNames[$row['ID']] = $row['NAME'];
447 }
448 unset($row, $iterator);
449
450 foreach ($sectionIdList as $sectionId)
451 {
452 $elementResult = self::convertTypeElementList(
453 $iblockId,
454 $sectionElements[$sectionId],
455 $type
456 );
457 if (!$elementResult->isSuccess())
458 {
459 $result->addError(new Main\Error(
460 Loc::getMessage(
462 ? 'BX_CATALOG_PRODUCT_ACTION_ERR_SECTION_PRODUCTS_CONVERT'
463 : 'BX_CATALOG_PRODUCT_ACTION_ERR_SECTION_SERVICES_CONVERT'
464 ,
465 [
466 '#ID#' => $sectionId,
467 '#NAME#' => $sectionNames[$sectionId],
468 ]
469 ),
470 $sectionId
471 ));
472 }
473 }
474 unset($sectionId);
475 unset($sectionNames, $sectionIdList, $sectionElements);
476
477 return $result;
478 }
479
480 private static function convertTypeElementList(int $iblockId, array $elementIds, int $type): Main\Result
481 {
482 $result = new Main\Result();
483
484 if ($iblockId <= 0)
485 {
486 $result->addError(new Main\Error(
487 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_IBLOCK_ID')
488 ));
489
490 return $result;
491 }
492
493 $catalog = \CCatalogSku::GetInfoByIBlock($iblockId);
494 if (empty($catalog))
495 {
496 $result->addError(new Main\Error(
497 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_CATALOG')
498 ));
499
500 return $result;
501 }
502
503 Main\Type\Collection::normalizeArrayValuesByInt($elementIds, true);
504 if (empty($elementIds))
505 {
506 $result->addError(new Main\Error(
507 Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_EMPTY_ELEMENTS')
508 ));
509
510 return $result;
511 }
512
513 $productResult = self::getProductListByTypeForConversion($elementIds, $type);
514 $data = $productResult->getData();
515 $products = $data['PRODUCT_IDS'] ?? [];
516 unset($data);
517 if (!$productResult->isSuccess())
518 {
519 $result->addErrors($productResult->getErrors());
520 }
521 unset($productResult);
522 if (empty($products))
523 {
524 return $result;
525 }
526
527 $inventoryResult = self::checkInventoryDocumentByProducts($products);
528 $data = $inventoryResult->getData();
529 $products = $data['PRODUCT_IDS'] ?? [];
530 unset($data);
531 if (!$inventoryResult->isSuccess())
532 {
533 $result->addErrors($inventoryResult->getErrors());
534 }
535 unset($inventoryResult);
536 if (empty($products))
537 {
538 return $result;
539 }
540
541 $convertResult = self::convertCatalogType($products, $type);
542 if (!$convertResult->isSuccess())
543 {
544 $result->addErrors($convertResult->getErrors());
545 }
546
547 return $result;
548 }
549
550 private static function getProductListByTypeForModify(array $elementIds, array $types): Main\Result
551 {
552 $result = new Main\Result();
553
554 $types = array_fill_keys($types, true);
555
556 $existList = [];
557 $newList = array_fill_keys($elementIds, true);
558 $errorList = [];
559
560 foreach (array_chunk($elementIds, 500) as $pageIds)
561 {
562 $iterator = Catalog\ProductTable::getList([
563 'select' => [
564 'ID',
565 'TYPE',
566 ],
567 'filter' => [
568 '@ID' => $pageIds,
569 ]
570 ]);
571 while ($row = $iterator->fetch())
572 {
573 $row['ID'] = (int)$row['ID'];
574 $row['TYPE'] = (int)$row['TYPE'];
575 unset($newList[$row['ID']]);
576 if (isset($types[$row['TYPE']]))
577 {
578 $existList[] = $row['ID'];
579 }
580 else
581 {
582 $errorList[] = $row['ID'];
583 }
584 }
585 unset($row, $iterator);
586 }
587
588 $result->setData([
589 'EXIST_PRODUCT_IDS' => $existList,
590 'NEW_PRODUCT_IDS' => array_values($newList),
591 ]);
592 unset($existList, $newList);
593
594 if (!empty($errorList))
595 {
596 $names = [];
597 $iterator = Iblock\ElementTable::getList([
598 'select' => [
599 'ID',
600 'NAME',
601 ],
602 'filter' => [
603 '@ID' => $errorList,
604 ],
605 ]);
606 while ($row = $iterator->fetch())
607 {
608 $names[] = '[' . $row['ID'] . '] ' . $row['NAME'];
609 }
610 unset($row, $iterator);
611 $result->addError(new Main\Error(
612 Loc::getMessage(
613 'BX_CATALOG_PRODUCT_ACTION_ERR_CANNOT_SET_FIELD_BY_TYPE',
614 [
615 '#NAMES#' => implode(', ', $names),
616 ]
617 )
618 ));
619 unset($names);
620 }
621 unset($errorList);
622
623 return $result;
624 }
625
626 private static function getProductListByTypeForConversion(array $elementIds, int $type): Main\Result
627 {
628 $result = new Main\Result();
629
630 $validList = [];
631 $errorList = [];
632
633 foreach (array_chunk($elementIds, 500) as $pageIds)
634 {
635 $iterator = Catalog\ProductTable::getList([
636 'select' => [
637 'ID',
638 'TYPE',
639 ],
640 'filter' => [
641 '@ID' => $pageIds,
642 ]
643 ]);
644 while ($row = $iterator->fetch())
645 {
646 $row['ID'] = (int)$row['ID'];
647 $row['TYPE'] = (int)$row['TYPE'];
648 if ($row['TYPE'] === $type)
649 {
650 $validList[] = $row['ID'];
651 }
652 else
653 {
654 $errorList[] = $row['ID'];
655 }
656 }
657 unset($row, $iterator);
658 }
659
660 $result->setData(['PRODUCT_IDS' => $validList]);
661 unset($validList);
662 if (!empty($errorList))
663 {
664 $names = [];
665 $iterator = Iblock\ElementTable::getList([
666 'select' => [
667 'ID',
668 'NAME',
669 ],
670 'filter' => [
671 '@ID' => $errorList,
672 ],
673 ]);
674 while ($row = $iterator->fetch())
675 {
676 $names[] = '[' . $row['ID'] . '] ' . $row['NAME'];
677 }
678 unset($row, $iterator);
679 if ($type === Catalog\ProductTable::TYPE_PRODUCT)
680 {
681 $result->addError(new Main\Error(
682 Loc::getMessage(
683 'BX_CATALOG_PRODUCT_ACTION_ERR_SELECTED_NOT_SIMPLE_PRODUCT',
684 ['#NAMES#' => implode(', ', $names)]
685 )
686 ));
687 }
688 else
689 {
690 $result->addError(new Main\Error(
691 Loc::getMessage(
692 'BX_CATALOG_PRODUCT_ACTION_ERR_SELECTED_NOT_SERVICE',
693 ['#NAMES#' => implode(', ', $names)]
694 )
695 ));
696 }
697 unset($names);
698 }
699 unset($errorList);
700
701 return $result;
702 }
703
704 private static function checkInventoryDocumentByProducts(array $elementIds): Main\Result
705 {
706 $result = new Main\Result();
707 if (!Catalog\Config\State::isUsedInventoryManagement())
708 {
709 $result->setData(['PRODUCT_IDS' => $elementIds]);
710
711 return $result;
712 }
713
714 $validList = array_fill_keys($elementIds, true);
715 $errorList = [];
716
717 $query = new ORM\Query\Query(Catalog\StoreDocumentElementTable::getEntity());
718 $query->setDistinct(true);
719 $query->setSelect([
720 'ELEMENT_ID',
721 'NAME' => 'ELEMENT.NAME'
722 ]);
723 $query->setFilter(['=DOCUMENT.STATUS' => 'Y']);
724
725 foreach (array_chunk($elementIds, 500) as $pageIds)
726 {
727 $query->addFilter('@ELEMENT_ID', $pageIds);
728 $iterator = $query->exec();
729 while ($row = $iterator->fetch())
730 {
731 $id = (int)$row['ELEMENT_ID'];
732 unset($validList[$id]);
733 $errorList[] = '[' . $row['ELEMENT_ID'] . '] ' . $row['NAME'];
734 }
735 unset($row, $iterator);
736 }
737 unset($pagesIds);
738 unset($query);
739
740 $result->setData(['PRODUCT_IDS' => array_keys($validList)]);
741 if (!empty($errorList))
742 {
743 $result->addError(new Main\Error(
744 Loc::getMessage(
745 'BX_CATALOG_PRODUCT_ACTION_ERR_SELECTED_INVENTORY_PRODUCTS',
746 ['#NAMES#' => implode(', ', $errorList)]
747 )
748 ));
749 }
750
751 return $result;
752 }
753
754 private static function convertCatalogType(array $elementIds, int $type): Main\Result
755 {
756 $result = new Main\Result();
757
758 $connection = Main\Application::getConnection();
759 $helper = $connection->getSqlHelper();
760
761 $sqlMain = 'update ' . $helper->quote(Catalog\ProductTable::getTableName());
762
763 if ($type === Catalog\ProductTable::TYPE_PRODUCT)
764 {
765 $sqlMain .= ' set ' . $helper->quote('TYPE') . ' = ' . Catalog\ProductTable::TYPE_SERVICE
766 . ', ' . $helper->quote('QUANTITY') . ' = ('
767 . 'CASE WHEN ' . $helper->quote('AVAILABLE') . ' = \'Y\' THEN 1 ELSE 0 END'
768 . '), ' . $helper->quote('QUANTITY_RESERVED') . ' = 0'
769 . ', ' . $helper->quote('QUANTITY_TRACE') . ' = \'N\''
770 . ', ' . $helper->quote('CAN_BUY_ZERO') . ' = \'Y\''
771 . ', ' . $helper->quote('NEGATIVE_AMOUNT_TRACE') . ' = \'Y\''
772 ;
773 }
774 else
775 {
776 $available = Catalog\ProductTable::calculateAvailable([
777 'QUANTITY' => 0,
778 'QUANTITY_TRACE' => Catalog\ProductTable::STATUS_DEFAULT,
779 'CAN_BUY_ZERO' => Catalog\ProductTable::STATUS_DEFAULT,
780 ]);
781 $sqlMain .= ' set ' . $helper->quote('TYPE') . ' = ' . Catalog\ProductTable::TYPE_PRODUCT
782 . (Catalog\Config\State::isUsedInventoryManagement()
783 ? ', ' . $helper->quote('AVAILABLE') . ' = \'' . $helper->forSql($available) . '\', '
784 . $helper->quote('QUANTITY') . ' = 0'
785 : ''
786 )
787 . ', ' . $helper->quote('QUANTITY_TRACE') . ' = \'D\''
788 . ', ' . $helper->quote('CAN_BUY_ZERO') . ' = \'D\''
789 . ', ' . $helper->quote('NEGATIVE_AMOUNT_TRACE') . ' = \'D\''
790 ;
791 }
792
793 $sqlMain .= ', ' . $helper->quote('TIMESTAMP_X') . ' = ' . $helper->quote('TIMESTAMP_X')
794 . ' where ID in ('
795 ;
796
797 $sqlStores = 'delete from ' . $helper->quote(Catalog\StoreProductTable::getTableName())
798 . ' where PRODUCT_ID in ('
799 ;
800
801 foreach (array_chunk($elementIds, 500) as $pageIds)
802 {
803 $list = implode(',', $pageIds);
804 $connection->query($sqlMain . $list . ')');
805
806 if ($type === Catalog\ProductTable::TYPE_PRODUCT)
807 {
808 $connection->query($sqlStores . $list . ')');
810 }
811 else
812 {
814 }
815 if (!$result->isSuccess())
816 {
817 return $result;
818 }
819 }
820
821 return $result;
822 }
823
830 protected static function convertToProduct(array $productIdList): Main\Result
831 {
832 return self::convert($productIdList, Catalog\ProductTable::TYPE_PRODUCT);
833 }
834
841 protected static function convertToService(array $productIdList): Main\Result
842 {
843 return self::convert($productIdList, Catalog\ProductTable::TYPE_SERVICE);
844 }
845
846 private static function convert(array $productIdList, int $catalogType): Main\Result
847 {
848 $result = new Main\Result();
849
850 if (Main\Loader::includeModule('crm'))
851 {
852 $convertCrmProductResult = self::convertCrmProducts($productIdList, $catalogType);
853 if (!$convertCrmProductResult->isSuccess())
854 {
855 $result->addErrors($convertCrmProductResult->getErrors());
856 }
857 }
858
859 if (Main\Loader::includeModule('sale'))
860 {
861 $convertSaleProductResult = self::convertSaleProducts($productIdList, $catalogType);
862 if (!$convertSaleProductResult->isSuccess())
863 {
864 $result->addErrors($convertSaleProductResult->getErrors());
865 }
866 }
867
868 return $result;
869 }
870
871 private static function convertCrmProducts(array $productIdList, int $type): Main\Result
872 {
873 $connection = Main\Application::getConnection();
874 $helper = $connection->getSqlHelper();
875
876 $productIdSql = $helper->forSql(implode(',', $productIdList));
877 $sql = sprintf(
878 'UPDATE %s SET TYPE = %d WHERE PRODUCT_ID IN (%s)',
879 $helper->quote(Crm\ProductRowTable::getTableName()),
880 $type,
881 $productIdSql
882 );
883
884 try
885 {
886 $connection->query($sql);
887 }
888 catch (Main\DB\SqlQueryException $exception)
889 {
890 return (new Main\Result())->addError(new Main\Error($exception->getMessage()));
891 }
892
893 return new Main\Result();
894 }
895
896 private static function convertSaleProducts(array $productIdList, int $type): Main\Result
897 {
898 $saleType = Sale\Internals\Catalog\ProductTypeMapper::getType($type);
899
900 $connection = Main\Application::getConnection();
901 $helper = $connection->getSqlHelper();
902
903 $productIdSql = $helper->forSql(implode(',', $productIdList));
904 $sql = sprintf(
905 'UPDATE %s SET TYPE = %s WHERE PRODUCT_ID IN (%s)',
906 $helper->quote(Sale\Internals\BasketTable::getTableName()),
907 $saleType ?: $helper->convertToDb($saleType),
908 $productIdSql
909 );
910
911 try
912 {
913 $connection->query($sql);
914 }
915 catch (Main\DB\SqlQueryException $exception)
916 {
917 return (new Main\Result())->addError(new Main\Error($exception->getMessage()));
918 }
919
920 return new Main\Result();
921 }
922}
$connection
Определения actionsdefinitions.php:38
$type
Определения options.php:106
static convertToProductSectionList(int $iblockId, array $sections)
Определения productaction.php:382
static convertToProduct(array $productIdList)
Определения productaction.php:830
static convertToServiceSectionList(int $iblockId, array $sections)
Определения productaction.php:377
static updateElementList(int $iblockId, array $elementIds, array $fields)
Определения productaction.php:113
static convertToServiceElementList(int $iblockId, array $elementIds)
Определения productaction.php:387
static getAllowedProductTypes(array $catalog, array $fields)
Определения productaction.php:298
static getSectionProducts(int $iblockId, array $sections, array $filter)
Определения productaction.php:209
const CONVERT_SERVICE_TO_PRODUCT
Определения productaction.php:20
const CONVERT_PRODUCT_TO_SERVICE
Определения productaction.php:19
static convertToProductElementList(int $iblockId, array $elementIds)
Определения productaction.php:392
static updateSectionList(int $iblockId, array $sections, array $fields)
Определения productaction.php:22
static convertToService(array $productIdList)
Определения productaction.php:841
static update($id, array $data)
Определения entity.php:229
static add(array $data)
Определения entity.php:150
const TYPE_SET
Определения product.php:71
const TYPE_SKU
Определения product.php:72
const TYPE_SERVICE
Определения product.php:76
const TYPE_OFFER
Определения product.php:73
const STATUS_DEFAULT
Определения product.php:68
const TYPE_PRODUCT
Определения product.php:70
static getTableName()
Определения product.php:102
static getTableName()
Определения storeproduct.php:45
Определения error.php:15
static getEntity()
Определения datamanager.php:65
static getList(array $parameters=array())
Определения datamanager.php:431
static normalizeArrayValuesByInt(&$map, $sorted=true)
Определения collection.php:150
$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
$query
Определения get_search.php:11
$iblockId
Определения iblock_catalog_edit.php:30
$catalog
Определения iblock_catalog_edit.php:135
$filter
Определения iblock_catalog_list.php:54
foreach( $arCellTemplates as $key=> $value) foreach( $arCellTemplates as $key=> $value)
global $USER
Определения csv_new_run.php:40
trait Error
Определения error.php:11
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$iterator
Определения yandex_run.php:610
$fields
Определения yandex_run.php:501