File manager - Edit - /home/c14075/dragmet-ural.ru/www/Sku.tar
Back
HasSkuCollection.php 0000644 00000000603 15134232062 0010464 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Sku; /** * Interface HasSkuCollection * * @package Bitrix\Catalog\v2\Sku * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ interface HasSkuCollection { public function getSkuCollection(): SkuCollection; public function setSkuCollection(SkuCollection $skuCollection); } SkuRepositoryContract.php 0000644 00000000760 15134232062 0011616 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Sku; use Bitrix\Catalog\v2\IblockElementRepositoryContract; use Bitrix\Catalog\v2\Product\BaseProduct; /** * Interface SkuRepositoryContract * * @package Bitrix\Catalog\v2\Sku * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ interface SkuRepositoryContract extends IblockElementRepositoryContract { public function getCollectionByProduct(BaseProduct $product): SkuCollection; } SkuFactory.php 0000644 00000003161 15134232062 0007346 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Sku; use Bitrix\Catalog\v2\BaseIblockElementEntity; use Bitrix\Catalog\v2\BaseIblockElementFactory; use Bitrix\Catalog\v2\IoC\Dependency; use Bitrix\Main\NotSupportedException; /** * Class SkuFactory * * @package Bitrix\Catalog\v2\Sku * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ class SkuFactory extends BaseIblockElementFactory { public const SIMPLE_SKU = SimpleSku::class; public const SKU = Sku::class; public const SKU_COLLECTION = SkuCollection::class; /** * @param string|null $entityClass * @return \Bitrix\Catalog\v2\Sku\BaseSku * @throws \Bitrix\Main\NotSupportedException */ public function createEntity(string $entityClass = null): BaseIblockElementEntity { if ($entityClass === null) { $entityClass = $this->iblockInfo->canHaveSku() ? self::SKU : self::SIMPLE_SKU; } if ($entityClass === self::SKU && !$this->iblockInfo->canHaveSku()) { throw new NotSupportedException(sprintf( 'Product catalog {%s} does not support {%s} type.', $this->iblockInfo->getProductIblockId(), $entityClass )); } if (!is_subclass_of($entityClass, BaseSku::class)) { throw new NotSupportedException(sprintf( 'Entity with type {%s} must be an instance of {%s}.', $entityClass, BaseSku::class )); } return $this->makeEntity($entityClass); } /** * @return \Bitrix\Catalog\v2\Sku\SkuCollection */ public function createCollection(): SkuCollection { return $this->container->make(self::SKU_COLLECTION, [ Dependency::IBLOCK_INFO => $this->iblockInfo, ]); } } SkuRepository.php 0000644 00000020014 15134232062 0010112 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Sku; use Bitrix\Catalog\ProductTable; use Bitrix\Catalog\v2\BaseIblockElementEntity; use Bitrix\Catalog\v2\BaseIblockElementRepository; use Bitrix\Catalog\v2\Iblock\IblockInfo; use Bitrix\Catalog\v2\Product\BaseProduct; use Bitrix\Catalog\v2\Product\ProductRepositoryContract; use Bitrix\Catalog\v2\Property\Property; use Bitrix\Catalog\v2\Property\PropertyCollection; use Bitrix\Catalog\v2\Property\PropertyRepositoryContract; /** * Class SkuRepository * * @package Bitrix\Catalog\v2\Sku * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ class SkuRepository extends BaseIblockElementRepository implements SkuRepositoryContract { /** @var \Bitrix\Catalog\v2\Sku\SkuFactory */ protected $factory; /** @var \Bitrix\Catalog\v2\Product\ProductRepositoryContract */ protected $productRepository; /** @var \Bitrix\Catalog\v2\Property\PropertyRepositoryContract */ protected $propertyRepository; /** * SkuRepository constructor. * * @param \Bitrix\Catalog\v2\Sku\SkuFactory $factory * @param \Bitrix\Catalog\v2\Iblock\IblockInfo $iblockInfo * @param \Bitrix\Catalog\v2\Product\ProductRepositoryContract $productRepository * @param \Bitrix\Catalog\v2\Property\PropertyRepositoryContract $propertyRepository */ public function __construct( SkuFactory $factory, IblockInfo $iblockInfo, ProductRepositoryContract $productRepository, PropertyRepositoryContract $propertyRepository ) { parent::__construct($factory, $iblockInfo); $this->productRepository = $productRepository; $this->propertyRepository = $propertyRepository; } /** * @param \Bitrix\Catalog\v2\Product\BaseProduct $product * @return \Bitrix\Catalog\v2\Sku\SkuCollection|\Bitrix\Catalog\v2\Sku\BaseSku[] */ public function getCollectionByProduct(BaseProduct $product): SkuCollection { $callback = function (array $params) use ($product) { yield from $this->getSkuIteratorForProduct($product, $params); }; return $this->factory ->createCollection() ->setIteratorCallback($callback) ; } /** * @param \Bitrix\Catalog\v2\Product\BaseProduct $product * @return \Bitrix\Catalog\v2\Sku\SkuCollection|\Bitrix\Catalog\v2\Sku\BaseSku[] */ public function loadEagerCollectionByProduct(BaseProduct $product): SkuCollection { $callback = function (array $params) use ($product) { yield from $this->getSkuIteratorEagerLoading($product, $params); }; return $this->factory ->createCollection() ->setIteratorCallback($callback) ; } public function getEntitiesBy($params): array { $sku = parent::getEntitiesBy($params); if (!empty($sku)) { $this->loadParentProducts(...$sku); } return $sku; } protected function getAdditionalFilter(): array { $filter = parent::getAdditionalFilter(); $filter['IBLOCK_ID'] = $this->iblockInfo->getSkuIblockId(); return $filter; } protected function getAdditionalProductFilter(): array { $filter = parent::getAdditionalProductFilter(); $filter['@TYPE'] = [ ProductTable::TYPE_PRODUCT, ProductTable::TYPE_OFFER, ProductTable::TYPE_FREE_OFFER, ]; return $filter; } protected function makeEntity(array $fields = []): BaseIblockElementEntity { $type = (int)($fields['TYPE'] ?? 0); if ($type === ProductTable::TYPE_OFFER || $type === ProductTable::TYPE_FREE_OFFER) { $entityClass = $this->factory::SKU; } else { $entityClass = $this->factory::SIMPLE_SKU; } return $this->factory->createEntity($entityClass); } private function loadParentProducts(BaseSku ...$skuItems): void { $skuByProductMap = $this->getSkuByProductMap($skuItems); if (!empty($skuByProductMap)) { $products = $this->productRepository->getEntitiesBy([ 'filter' => [ '=ID' => array_keys($skuByProductMap), ], ]); /** @var BaseProduct $product */ foreach ($products as $product) { $productSkuItems = $skuByProductMap[$product->getId()] ?? []; $skuCollection = $this->getCollectionByProduct($product) ->setParent($product) ->add(...$productSkuItems) ; $product->setSkuCollection($skuCollection); } } } private function getSkuByProductMap(array $skuItems): array { $skuByProductMap = []; $skuMap = []; /** @var \Bitrix\Catalog\v2\Sku\BaseSku $sku */ foreach ($skuItems as $sku) { if ($sku->getParent() === null) { $skuMap[$sku->getId()] = $sku; } } if (!empty($skuMap)) { $skuPropertyId = $this->iblockInfo->getSkuPropertyId(); $propertyValuesIterator = \CIBlockElement::GetPropertyValues( $this->iblockInfo->getSkuIblockId(), ['ID' => array_keys($skuMap)], false, ['ID' => $skuPropertyId] ); while ($propertyValues = $propertyValuesIterator->fetch()) { $productId = $propertyValues[$skuPropertyId]; $sku = $skuMap[$propertyValues['IBLOCK_ELEMENT_ID']]; $skuByProductMap[$productId][] = $sku; } } return $skuByProductMap; } private function getSkuIteratorForProduct(BaseProduct $product, array $params = []): \Generator { if ($product->isSimple()) { if ($product->getSkuCollection()->isEmpty()) { yield $this->createEntity(); } } elseif (!$product->isNew()) { $params['filter']['PROPERTY_' . $this->iblockInfo->getSkuPropertyId()] = $product->getId(); $params['order']['ID'] = 'DESC'; foreach ($this->getList($params) as $item) { yield $this->createEntity($item); } } } private function getSkuIteratorEagerLoading(BaseProduct $product, array $params = []): \Generator { if ($product->isSimple()) { if ($product->getSkuCollection()->isEmpty()) { yield $this->createEntity(); } } elseif (!$product->isNew()) { $params['filter']['PROPERTY_' . $this->iblockInfo->getSkuPropertyId()] = $product->getId(); $params['order']['ID'] = 'DESC'; $items = []; foreach ($this->getList($params) as $item) { $items[$item['ID']] = $item; } $skuIds = array_keys($items); $propertySettings = $this->propertyRepository->getPropertiesSettingsByFilter([ '=IBLOCK_ID' => $this->iblockInfo->getSkuIblockId(), ]); $propertyElementMap = $this->getPropertyMapBySkuIds($skuIds, $propertySettings); foreach ($items as $skuId => $item) { $propertyCollection = $this->propertyRepository->createCollection(); foreach ($propertySettings as $setting) { if (isset($propertyElementMap[$skuId][$setting['ID']])) { $propertyItem = $propertyElementMap[$skuId][$setting['ID']]; } else { $propertyItem = $this->propertyRepository->createEntity([], $setting); } if ($propertyItem) { $propertyCollection->add($propertyItem); } } yield $this->createEntity($item, $propertyCollection); } } } /** * @param array $skuIds * @param array $propertySettings * @return array */ private function getPropertyMapBySkuIds(array $skuIds, array $propertySettings): array { $skuPropertyFilter = [ 'filter' => [ 'IBLOCK_ID' => $this->iblockInfo->getSkuIblockId(), 'ID' => $skuIds, ], ]; $properties = $this->propertyRepository->getEntitiesBy($skuPropertyFilter, $propertySettings); $propertyElementMap = []; /** @var Property $property */ foreach ($properties as $property) { $elementId = $property->getSetting('IBLOCK_ELEMENT_ID'); if ($elementId > 0) { $propertyElementMap[$elementId] = $propertyElementMap[$elementId] ?? []; $propertyElementMap[$elementId][$property->getSetting('ID')] = $property; } } return $propertyElementMap; } protected function createEntity(array $fields = [], PropertyCollection $propertyCollection = null): BaseIblockElementEntity { $entity = parent::createEntity($fields); if ($propertyCollection) { $entity->setPropertyCollection($propertyCollection); } return $entity; } public function setDetailUrlTemplate(?string $template): BaseIblockElementRepository { if ($this->productRepository->getDetailUrlTemplate() === null) { $this->productRepository->setDetailUrlTemplate($template); } return parent::setDetailUrlTemplate($template); } } SimpleSku.php 0000644 00000004671 15134232062 0007177 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Sku; use Bitrix\Catalog\v2\BaseEntity; use Bitrix\Catalog\v2\BaseIblockElementEntity; use Bitrix\Catalog\v2\Fields\FieldStorage; use Bitrix\Catalog\v2\Image\ImageCollection; use Bitrix\Catalog\v2\Property\PropertyCollection; use Bitrix\Main\NotSupportedException; use Bitrix\Main\Result; /** * Class SimpleSku * * @package Bitrix\Catalog\v2\Sku * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ class SimpleSku extends BaseSku { /** * @return \Bitrix\Catalog\v2\BaseIblockElementEntity * @throws \Bitrix\Main\NotSupportedException */ public function getParent(): BaseEntity { $parent = parent::getParent(); if (!$parent) { throw new NotSupportedException(sprintf('{%s} must have a parent.', static::class)); } return $parent; } protected function createFieldStorage(): FieldStorage { return $this->getParent()->getFieldStorage(); } /** * @return \Bitrix\Catalog\v2\Property\PropertyCollection|\Bitrix\Catalog\v2\Property\Property[] */ protected function loadPropertyCollection(): PropertyCollection { return $this->getParent()->getPropertyCollection(); } protected function unsetPropertyCollection(): BaseIblockElementEntity { if ($parent = $this->getParent()) { $parent->unsetPropertyCollection(); } return parent::unsetPropertyCollection(); } /** * @return \Bitrix\Catalog\v2\Image\ImageCollection|\Bitrix\Catalog\v2\Image\BaseImage[] */ protected function loadImageCollection(): ImageCollection { return $this->getParent()->getImageCollection(); } protected function unsetImageCollection(): BaseIblockElementEntity { if ($parent = $this->getParent()) { $parent->unsetImageCollection(); } return parent::unsetImageCollection(); } public function setPropertyCollection(PropertyCollection $propertyCollection): BaseIblockElementEntity { // avoiding reinitialize of property collection with our simple sku parent $this->propertyCollection = $propertyCollection; return $this; } public function deleteInternal(): Result { $result = new Result(); // delete child collections without entity fields itself (it was deleted with parent product entity) foreach ($this->getChildCollections(true) as $childCollection) { $res = $childCollection->deleteInternal(); if (!$res->isSuccess()) { $result->addErrors($res->getErrors()); } } return $result; } } BaseSku.php 0000644 00000015622 15134232062 0006616 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Sku; use Bitrix\Catalog\v2\Barcode\BarcodeCollection; use Bitrix\Catalog\v2\Barcode\BarcodeRepositoryContract; use Bitrix\Catalog\v2\Barcode\HasBarcodeCollection; use Bitrix\Catalog\v2\BaseIblockElementEntity; use Bitrix\Catalog\v2\Iblock\IblockInfo; use Bitrix\Catalog\v2\Image\ImageCollection; use Bitrix\Catalog\v2\Image\ImageRepositoryContract; use Bitrix\Catalog\v2\MeasureRatio\HasMeasureRatioCollection; use Bitrix\Catalog\v2\MeasureRatio\MeasureRatioCollection; use Bitrix\Catalog\v2\MeasureRatio\MeasureRatioRepositoryContract; use Bitrix\Catalog\v2\Price\HasPriceCollection; use Bitrix\Catalog\v2\Price\PriceCollection; use Bitrix\Catalog\v2\Price\PriceRepositoryContract; use Bitrix\Catalog\v2\Property\PropertyRepositoryContract; use Bitrix\Catalog\v2\StoreProduct\StoreProductCollection; use Bitrix\Catalog\v2\StoreProduct\StoreProductRepositoryContract; use Bitrix\Catalog\v2\StoreProduct\HasStoreProductCollection; use Bitrix\Catalog\v2\StoreProduct\StoreProduct; /** * Class BaseSku * * @package Bitrix\Catalog\v2\Sku * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ abstract class BaseSku extends BaseIblockElementEntity implements HasPriceCollection, HasMeasureRatioCollection, HasBarcodeCollection, HasStoreProductCollection { /** @var \Bitrix\Catalog\v2\Price\PriceCollection|\Bitrix\Catalog\v2\Price\BasePrice[] */ protected $priceCollection; /** @var \Bitrix\Catalog\v2\Price\PriceRepositoryContract */ protected $priceRepository; /** @var \Bitrix\Catalog\v2\MeasureRatio\MeasureRatioRepositoryContract */ protected $measureRatioRepository; /** @var \Bitrix\Catalog\v2\MeasureRatio\MeasureRatioCollection|\Bitrix\Catalog\v2\MeasureRatio\BaseMeasureRatio[] */ protected $measureRatioCollection; /** @var \Bitrix\Catalog\v2\Barcode\BarcodeRepositoryContract */ protected $barcodeRepository; /** @var \Bitrix\Catalog\v2\Barcode\BarcodeCollection|\Bitrix\Catalog\v2\Barcode\Barcode[] */ protected $barcodeCollection; /** @var StoreProductRepositoryContract */ protected $storeProductRepository; /** @var StoreProductCollection|StoreProduct[] */ protected $storeProductCollection; public function __construct( IblockInfo $iblockInfo, SkuRepositoryContract $skuRepository, PropertyRepositoryContract $propertyRepository, ImageRepositoryContract $imageRepository, PriceRepositoryContract $priceRepository, MeasureRatioRepositoryContract $measureRatioRepository, BarcodeRepositoryContract $barcodeRepository, StoreProductRepositoryContract $storeProductRepository ) { parent::__construct($iblockInfo, $skuRepository, $propertyRepository, $imageRepository); $this->priceRepository = $priceRepository; $this->measureRatioRepository = $measureRatioRepository; $this->barcodeRepository = $barcodeRepository; $this->storeProductRepository = $storeProductRepository; } /** * @return ImageCollection|\Bitrix\Catalog\v2\Image\BaseImage[] */ public function getFrontImageCollection(): ImageCollection { $collection = $this->getImageCollection(); if ($collection->isEmpty() && $this->getParent()) { $parentCollection = $this->getParent()->getImageCollection(); if (!$parentCollection->isEmpty()) { return $parentCollection; } } return $collection; } /** * @return \Bitrix\Catalog\v2\Price\PriceCollection|\Bitrix\Catalog\v2\Price\BasePrice[] */ public function getPriceCollection(): PriceCollection { if ($this->priceCollection === null) { // ToDo make lazy load like sku collection with iterator callback? $this->setPriceCollection($this->loadPriceCollection()); } return $this->priceCollection; } /** * @return \Bitrix\Catalog\v2\Price\PriceCollection|\Bitrix\Catalog\v2\Price\BasePrice[] */ protected function loadPriceCollection(): PriceCollection { return $this->priceRepository->getCollectionByParent($this); } /** * @param \Bitrix\Catalog\v2\Price\PriceCollection $priceCollection * @return \Bitrix\Catalog\v2\Sku\BaseSku * * @internal */ public function setPriceCollection(PriceCollection $priceCollection): self { $priceCollection->setParent($this); $this->priceCollection = $priceCollection; return $this; } /** * @return \Bitrix\Catalog\v2\MeasureRatio\MeasureRatioCollection|\Bitrix\Catalog\v2\MeasureRatio\BaseMeasureRatio[] */ public function getMeasureRatioCollection(): MeasureRatioCollection { if ($this->measureRatioCollection === null) { $this->setMeasureRatioCollection($this->loadMeasureRatioCollection()); } return $this->measureRatioCollection; } /** * @return \Bitrix\Catalog\v2\MeasureRatio\MeasureRatioCollection|\Bitrix\Catalog\v2\MeasureRatio\BaseMeasureRatio[] */ protected function loadMeasureRatioCollection(): MeasureRatioCollection { return $this->measureRatioRepository->getCollectionByParent($this); } /** * @param \Bitrix\Catalog\v2\MeasureRatio\MeasureRatioCollection $measureRatioCollection * @return \Bitrix\Catalog\v2\Sku\BaseSku * * @internal */ public function setMeasureRatioCollection(MeasureRatioCollection $measureRatioCollection): self { $measureRatioCollection->setParent($this); $this->measureRatioCollection = $measureRatioCollection; return $this; } /** * @return \Bitrix\Catalog\v2\Barcode\BarcodeCollection|\Bitrix\Catalog\v2\Barcode\Barcode[] */ public function getBarcodeCollection(): BarcodeCollection { if ($this->barcodeCollection === null) { $this->setBarcodeCollection($this->loadBarcodeCollection()); } return $this->barcodeCollection; } /** * @return \Bitrix\Catalog\v2\Barcode\BarcodeCollection|\Bitrix\Catalog\v2\Barcode\BarcodeCollection[] */ protected function loadBarcodeCollection(): BarcodeCollection { return $this->barcodeRepository->getCollectionByParent($this); } /** * @param \Bitrix\Catalog\v2\Barcode\BarcodeCollection $barcodeCollection * @return BaseSku * * @internal */ public function setBarcodeCollection(BarcodeCollection $barcodeCollection): self { $barcodeCollection->setParent($this); $this->barcodeCollection = $barcodeCollection; return $this; } /** * @return StoreProductCollection|StoreProduct[] */ public function getStoreProductCollection(): StoreProductCollection { if ($this->storeProductCollection === null) { $this->setStoreProductCollection($this->loadStoreProductCollection()); } return $this->storeProductCollection; } /** * @return StoreProductCollection|StoreProduct[] */ protected function loadStoreProductCollection(): StoreProductCollection { return $this->storeProductRepository->getCollectionByParent($this); } /** * @param StoreProductCollection $storeProductCollection * @return BaseSku * * @internal */ public function setStoreProductCollection(StoreProductCollection $storeProductCollection): self { $storeProductCollection->setParent($this); $this->storeProductCollection = $storeProductCollection; return $this; } } SkuCollection.php 0000644 00000003767 15134232062 0010046 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Sku; use Bitrix\Catalog\v2\BaseCollection; use Bitrix\Catalog\v2\BaseEntity; use Bitrix\Catalog\v2\IoC\ContainerContract; use Bitrix\Catalog\v2\IoC\Dependency; /** * Class SkuCollection * * @package Bitrix\Catalog\v2\Sku * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ class SkuCollection extends BaseCollection { /** @var ContainerContract */ protected $container; /** @var \Bitrix\Catalog\v2\Sku\SkuFactory */ protected $factory; public function __construct(ContainerContract $container, SkuFactory $factory) { $this->container = $container; $this->factory = $factory; } public function create(): BaseSku { /** @var \Bitrix\Catalog\v2\Product\BaseProduct $parent */ $parent = $this->getParent(); if ($parent && $parent->isSimple()) { /** @var \Bitrix\Catalog\v2\Converter\ProductConverter $converter */ $converter = $this->container->get(Dependency::PRODUCT_CONVERTER); $converter->convert($parent, $converter::SKU_PRODUCT); } $sku = $this->createEntity(); $this->add($sku); if (!$sku->hasName() && $parent->hasName()) { $sku->setName($parent->getName()); } return $sku; } protected function createEntity(): BaseSku { /** @var \Bitrix\Catalog\v2\Product\BaseProduct $parent */ $parent = $this->getParent(); if ($parent && $parent->isSimple()) { $type = SkuFactory::SIMPLE_SKU; } else { $type = SkuFactory::SKU; } return $this->factory->createEntity($type); } protected function getAlreadyLoadedFilter(): array { $filter = parent::getAlreadyLoadedFilter(); foreach ($this->items as $item) { if (!$item->isNew()) { $filter['!ID'][] = $item->getId(); } } return $filter; } /** * @param callable|null $callback * @return \Bitrix\Catalog\v2\BaseEntity|\Bitrix\Catalog\v2\Sku\BaseSku|null */ public function getFirst(callable $callback = null): ?BaseEntity { return parent::getFirst($callback); } } Sku.php 0000644 00000007356 15134232062 0006030 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Sku; use Bitrix\Catalog\ProductTable; use Bitrix\Catalog\v2\Barcode\BarcodeRepositoryContract; use Bitrix\Catalog\v2\BaseCollection; use Bitrix\Catalog\v2\BaseEntity; use Bitrix\Catalog\v2\Iblock\IblockInfo; use Bitrix\Catalog\v2\Image\ImageRepositoryContract; use Bitrix\Catalog\v2\MeasureRatio\MeasureRatioRepositoryContract; use Bitrix\Catalog\v2\Price\PriceRepositoryContract; use Bitrix\Catalog\v2\Product\BaseProduct; use Bitrix\Catalog\v2\Property\Property; use Bitrix\Catalog\v2\Property\PropertyRepositoryContract; use Bitrix\Catalog\v2\StoreProduct\StoreProductRepositoryContract; use Bitrix\Main\Result; /** * Class Sku * * @package Bitrix\Catalog\v2\Sku * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ class Sku extends BaseSku { public function __construct( IblockInfo $iblockInfo, SkuRepositoryContract $skuRepository, PropertyRepositoryContract $propertyRepository, ImageRepositoryContract $imageRepository, PriceRepositoryContract $priceRepository, MeasureRatioRepositoryContract $measureRatioRepository, BarcodeRepositoryContract $barcodeRepository, StoreProductRepositoryContract $storeProductRepository ) { parent::__construct( $iblockInfo, $skuRepository, $propertyRepository, $imageRepository, $priceRepository, $measureRatioRepository, $barcodeRepository, $storeProductRepository ); $this->setIblockId($this->iblockInfo->getSkuIblockId()); $this->setType(ProductTable::TYPE_FREE_OFFER); } public function getDetailUrl(): string { $detailUrl = parent::getDetailUrl(); /** @var \Bitrix\Catalog\v2\Product\BaseProduct $product */ if (!$detailUrl && $product = $this->getParent()) { $detailUrl = $product->getDetailUrl(); } return $detailUrl; } public function setParentCollection(?BaseCollection $collection): BaseEntity { // ToDo check for correct parent iblock for iblockelemententities! parent::setParentCollection($collection); if ($this->isNew()) { $this->checkProductLink(); } return $this; } /** * @return $this * @internal */ public function checkProductLink(): self { /** @var \Bitrix\Catalog\v2\Product\BaseProduct $product */ $product = $this->getParent(); if ($product) { $this->linkProduct($product); } else { $this->unlinkProduct(); } return $this; } protected function linkProduct(BaseProduct $product): self { if (!$this->isNew()) { $this->setProductLinkProperty($product->getId()); } $this->setType(ProductTable::TYPE_OFFER); return $this; } protected function unlinkProduct(): self { $this->unsetProductLinkProperty(); $this->setType(ProductTable::TYPE_FREE_OFFER); return $this; } protected function getProductLinkProperty(): ?Property { $skuPropertyId = $this->iblockInfo->getSkuPropertyId(); if ($skuPropertyId) { return $this->getPropertyCollection()->findBySetting('ID', $skuPropertyId); } return null; } protected function setProductLinkProperty(int $productId): self { $property = $this->getProductLinkProperty(); if ($property) { // ToDo do we need property values type casting? $property->getPropertyValueCollection()->setValues((string)$productId); } return $this; } protected function unsetProductLinkProperty(): self { $property = $this->getProductLinkProperty(); if ($property) { $property->getPropertyValueCollection()->setValues(null); } return $this; } public function saveInternalEntity(): Result { $isNeedCheckProductLinkAfterSaving = $this->isNew(); $result = parent::saveInternalEntity(); if ($isNeedCheckProductLinkAfterSaving && $result->isSuccess()) { $this->checkProductLink(); } return $result; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.25 |
proxy
|
phpinfo
|
Settings