Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
SkuFactory.php
1<?php
2
4
9
19{
20 public const SIMPLE_SKU = SimpleSku::class;
21 public const SKU = Sku::class;
22 public const SKU_COLLECTION = SkuCollection::class;
23
29 public function createEntity(string $entityClass = null): BaseIblockElementEntity
30 {
31 if ($entityClass === null)
32 {
33 $entityClass = $this->iblockInfo->canHaveSku() ? self::SKU : self::SIMPLE_SKU;
34 }
35
36 if ($entityClass === self::SKU && !$this->iblockInfo->canHaveSku())
37 {
38 throw new NotSupportedException(sprintf(
39 'Product catalog {%s} does not support {%s} type.',
40 $this->iblockInfo->getProductIblockId(), $entityClass
41 ));
42 }
43
44 if (!is_subclass_of($entityClass, BaseSku::class))
45 {
46 throw new NotSupportedException(sprintf(
47 'Entity with type {%s} must be an instance of {%s}.',
48 $entityClass, BaseSku::class
49 ));
50 }
51
52 return $this->makeEntity($entityClass);
53 }
54
59 {
60 return $this->container->make(self::SKU_COLLECTION, [
61 Dependency::IBLOCK_INFO => $this->iblockInfo,
62 ]);
63 }
64}
createEntity(string $entityClass=null)