11trait InitSkuCollectionFromParams
25 protected function initFieldsSkuCollectionItems(SkuCollection $skuCollection, array $rows,
bool $isServiceForm): void
32 foreach ($rows as $id => $row)
39 $isNew = (string)(
int)$id !== (string)$id;
42 ? $skuCollection->create()
43 : $skuCollection->findById((
int)$id)
45 if (!($sku instanceof BaseSku))
51 $form = $isServiceForm ?
new GridServiceForm($sku) : new GridVariationForm($sku);
52 $fields = $form->prepareFieldsValues($row);
54 $sku->setFields($fields);
56 if (isset($fields[
'PROPERTIES']))
58 $sku->getPropertyCollection()->setValues($fields[
'PROPERTIES']);
61 if (isset($fields[
'PRICES']))
63 $sku->getPriceCollection()->setValues($fields[
'PRICES']);
66 if (isset($fields[
'MEASURE']))
68 $sku->getMeasureRatioCollection()->setDefault($fields[
'MEASURE']);
71 if (isset($fields[
'BARCODES']))
78 foreach ($sku->getBarcodeCollection() as $barcode)
87 foreach ($fields[
'BARCODES'] as $code)
94 $existBarcode = $existBarcodes[$code] ??
null;
95 if ($existBarcode instanceof Barcode)
97 unset($existBarcodes[$code]);
101 $sku->getBarcodeCollection()->create()->setBarcode($code);
107 $sku->getBarcodeCollection()->remove(...$existBarcodes);