30 $this->container = $container;
35 if ($destinationType === self::SKU_PRODUCT)
37 return $this->convertSimpleProductToSkuProduct($product);
46 'Could not convert product {%s} to type {%s}.',
61 if (!$item->isSimple())
66 $skuItem = $this->convertSimpleSkuToSku($item);
70 'CONVERTED_SKU' => $skuItem,
81 protected function convertSimpleSkuToSku(BaseSku $simpleItem): BaseSku
84 $skuFactory = $this->container->get(Dependency::SKU_FACTORY, [
85 Dependency::IBLOCK_INFO => $simpleItem->getIblockInfo(),
93 $skuItem = $skuFactory->createEntity($skuFactory::SKU);
94 if ($skuItem->isSimple())
100 $skuCollection = $simpleItem->getParentCollection();
102 ->remove($simpleItem)
103 ->clearRemoved($simpleItem)
107 $fields = array_diff_key($simpleItem->getFields(), [
111 'DETAIL_TEXT' =>
true,
112 'DETAIL_TEXT_TYPE' =>
true,
113 'PREVIEW_TEXT' =>
true,
114 'PREVIEW_TEXT_TYPE' =>
true,
116 $skuItem->setFields($fields);
118 $skuItem->getPriceCollection()->setValues($simpleItem->getPriceCollection()->getValues());
120 $defaultRatio = $simpleItem->getMeasureRatioCollection()->findDefault();
123 $skuItem->getMeasureRatioCollection()->setDefault($defaultRatio->getRatio());
130 protected function convertSkuToSimpleProduct(BaseProduct $product): Result
132 $result =
new Result();
134 if (!$product->isSimple() && $product->getSkuCollection()->count() <= 1)
137 foreach ($product->getSkuCollection() as $item)
139 if ($item->isSimple())
145 $skuItem = $this->convertSkuToSimpleSku($item);
149 'CONVERTED_SKU' => $skuItem,
160 protected function convertSkuToSimpleSku(BaseSku $skuItem): BaseSku
163 $skuFactory = $this->container->get(Dependency::SKU_FACTORY, [
164 Dependency::IBLOCK_INFO => $skuItem->getIblockInfo(),
172 $simpleItem = $skuFactory->createEntity($skuFactory::SIMPLE_SKU);
175 $skuCollection = $skuItem->getParentCollection();
176 $skuCollection->remove($skuItem)
180 $fields = array_diff_key($skuItem->getFields(), [
185 $simpleItem->setFields($fields);
187 $simpleItem->getPriceCollection()->setValues($skuItem->getPriceCollection()->getValues());
189 $defaultRatio = $skuItem->getMeasureRatioCollection()->findDefault();
192 $simpleItem->getMeasureRatioCollection()->setDefault($defaultRatio->getRatio());