Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
SkuCollection.php
1<?php
2
4
9
19{
21 protected $container;
23 protected $factory;
24
26 {
27 $this->container = $container;
28 $this->factory = $factory;
29 }
30
31 public function create(): BaseSku
32 {
34 $parent = $this->getParent();
35
36 if ($parent && $parent->isSimple())
37 {
39 $converter = $this->container->get(Dependency::PRODUCT_CONVERTER);
40 $converter->convert($parent, $converter::SKU_PRODUCT);
41 }
42
43 $sku = $this->createEntity();
44 $this->add($sku);
45
46 if (!$sku->hasName() && $parent->hasName())
47 {
48 $sku->setName($parent->getName());
49 }
50
51 return $sku;
52 }
53
54 protected function createEntity(): BaseSku
55 {
57 $parent = $this->getParent();
58
59 if ($parent && $parent->isSimple())
60 {
62 }
63 else
64 {
65 $type = SkuFactory::SKU;
66 }
67
68 return $this->factory->createEntity($type);
69 }
70
71 protected function getAlreadyLoadedFilter(): array
72 {
73 $filter = parent::getAlreadyLoadedFilter();
74
75 foreach ($this->items as $item)
76 {
77 if (!$item->isNew())
78 {
79 $filter['!ID'][] = $item->getId();
80 }
81 }
82
83 return $filter;
84 }
85
90 public function getFirst(callable $callback = null): ?BaseEntity
91 {
92 return parent::getFirst($callback);
93 }
94}
getFirst(callable $callback=null)
__construct(ContainerContract $container, SkuFactory $factory)