1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
initskucollectionfromparams.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Component\GridVariation;
4
5use Bitrix\Catalog\Component\GridServiceForm;
6use Bitrix\Catalog\Component\GridVariationForm;
7use Bitrix\Catalog\v2\Barcode\Barcode;
8use Bitrix\Catalog\v2\Sku\BaseSku;
9use Bitrix\Catalog\v2\Sku\SkuCollection;
10
11trait InitSkuCollectionFromParams
12{
25 protected function initFieldsSkuCollectionItems(SkuCollection $skuCollection, array $rows, bool $isServiceForm): void
26 {
27 if (empty($rows))
28 {
29 return;
30 }
31
32 foreach ($rows as $id => $row)
33 {
34 if (!is_array($row))
35 {
36 continue;
37 }
38
39 $isNew = (string)(int)$id !== (string)$id; // available exist: 564; new ids: oX03gdf, 000000001450000000
40 $sku =
41 $isNew
42 ? $skuCollection->create()
43 : $skuCollection->findById((int)$id)
44 ;
45 if (!($sku instanceof BaseSku))
46 {
47 continue;
48 }
49
50
51 $form =
52 $isServiceForm
53 ? new GridServiceForm($sku)
54 : new GridVariationForm($sku)
55 ;
56 $fields = $form->prepareFieldsValues($row);
57
58 $sku->setFields($fields);
59
60 if (isset($fields['PROPERTIES']))
61 {
62 $sku->getPropertyCollection()->setValues($fields['PROPERTIES']);
63 }
64
65 if (isset($fields['PRICES']))
66 {
67 $sku->getPriceCollection()->setValues($fields['PRICES']);
68 }
69
70 if (isset($fields['MEASURE_RATIO']))
71 {
72 $sku->getMeasureRatioCollection()->setDefault((float)$fields['MEASURE_RATIO']);
73 }
74
75 if (isset($fields['BARCODES']))
76 {
80 $existBarcodes = [];
81
82 foreach ($sku->getBarcodeCollection() as $barcode)
83 {
84 $code = $barcode->getBarcode();
85 if ($code)
86 {
87 $existBarcodes[$code] = $barcode;
88 }
89 }
90
91 foreach ($fields['BARCODES'] as $code)
92 {
93 if (empty($code))
94 {
95 continue;
96 }
97
98 $existBarcode = $existBarcodes[$code] ?? null;
99 if ($existBarcode instanceof Barcode)
100 {
101 unset($existBarcodes[$code]);
102 }
103 else
104 {
105 $sku->getBarcodeCollection()->create()->setBarcode($code);
106 }
107 }
108
109 if ($existBarcodes)
110 {
111 $sku->getBarcodeCollection()->remove(...$existBarcodes);
112 }
113 }
114 }
115 }
116}
prepareFieldsValues(array $dirtyValues)
Определения gridvariationform.php:974
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$rows
Определения options.php:264
$fields
Определения yandex_run.php:501