1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
tradebindingcollection.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale;
4
5use Bitrix\Main;
6use Bitrix\Sale\Internals\CollectableEntity;
7use Bitrix\Sale\TradingPlatform;
8
14{
15 protected $order = null;
16
20 protected function getEntityParent()
21 {
22 return $this->order;
23 }
24
28 public function getOrder()
29 {
30 return $this->order;
31 }
32
36 private static function createCollectionObject()
37 {
38 $registry = Registry::getInstance(static::getRegistryType());
39 $className = $registry->get(Registry::ENTITY_TRADE_BINDING_COLLECTION);
40
41 return new $className();
42 }
43
47 public static function getRegistryType()
48 {
50 }
51
55 public function setOrder(Order $order)
56 {
57 $this->order = $order;
58 }
59
64 public static function load(Order $order)
65 {
66 $collection = static::createCollectionObject();
67 $collection->setOrder($order);
68
69 if (!$order->isNew())
70 {
71 $registry = Registry::getInstance(static::getRegistryType());
72
75
76 $bindingList = $entity::loadForOrder($order->getId());
78 foreach ($bindingList as $item)
79 {
80 $item->setCollection($collection);
81 $collection->bindItem($item);
82 }
83 }
84
85 return $collection;
86 }
87
92 public static function getList(array $parameters = array())
93 {
94 return TradingPlatform\OrderTable::getList($parameters);
95 }
96
101 public function createItem(TradingPlatform\Platform $platform = null)
102 {
103 $registry = Registry::getInstance(static::getRegistryType());
104
106 $tradeBindingEntity = $registry->get(Registry::ENTITY_TRADE_BINDING_ENTITY);
107
108 $tradeBinding = $tradeBindingEntity::create($this, $platform);
109 $this->addItem($tradeBinding);
110
111 return $tradeBinding;
112 }
113
114 public function onItemModify(CollectableEntity $item, $name = null, $oldValue = null, $value = null)
115 {
117 $order = $this->getOrder();
118
119 if ($item instanceof TradeBindingEntity)
120 {
121 $order->onTradeBindingCollectionModify(EventActions::UPDATE, $item, $name, $oldValue, $value);
122 }
123
124 return parent::onItemModify($item, $name, $oldValue, $value);
125 }
126
131 public function addItem(Internals\CollectableEntity $item)
132 {
134 $entity = parent::addItem($item);
135
136 $order = $this->getOrder();
137 $order->onTradeBindingCollectionModify(EventActions::ADD, $entity);
138
139 return $entity;
140 }
141
143 {
144 if (!($item instanceof TradeBindingEntity))
145 {
146 throw new Main\NotSupportedException();
147 }
148
149 return parent::bindItem($item);
150 }
151
156 public function deleteItem($index)
157 {
159 $oldItem = parent::deleteItem($index);
160
161 $order = $this->getOrder();
162 $order->onTradeBindingCollectionModify(EventActions::DELETE, $oldItem);
163 }
164
170 public function save()
171 {
172 $result = new Result();
173
175 if (!$order = $this->getEntityParent())
176 {
177 throw new Main\ObjectNotFoundException('Entity "Order" not found');
178 }
179
180 if (!$order->isNew())
181 {
182 $itemsFromDbList = static::getList(
183 array(
184 "filter" => array("ORDER_ID" => $order->getId())
185 )
186 );
187
188 while ($item = $itemsFromDbList->fetch())
189 {
190 if (!$this->getItemById($item['ID']))
191 {
192 static::deleteInternal($item['ID']);
193 }
194 }
195 }
196
198 foreach ($this->collection as $entity)
199 {
200 $r = $entity->save();
201 if (!$r->isSuccess())
202 {
203 $result->addErrors($r->getErrors());
204 }
205 }
206
207 $this->clearChanged();
208
209 return $result;
210 }
211
218 public static function deleteNoDemand($idOrder)
219 {
220 $result = new Result();
221
222 $dbRes = static::getList(
223 array(
224 "filter" => array("=ORDER_ID" => $idOrder),
225 "select" => array("ID")
226 )
227 );
228
229 while ($entity = $dbRes->fetch())
230 {
231 $r = static::deleteInternal($entity['ID']);
232 if (!$r->isSuccess())
233 {
234 $result->addErrors($r->getErrors());
235 }
236 }
237
238 return $result;
239 }
240
245 protected static function deleteInternal($primary)
246 {
247 return TradingPlatform\OrderTable::delete($primary);
248 }
249
256 public function createClone(\SplObjectStorage $cloneEntity)
257 {
258 if ($this->isClone() && $cloneEntity->contains($this))
259 {
260 return $cloneEntity[$this];
261 }
262
264 $tradeBindingCollection = parent::createClone($cloneEntity);
265
266 if ($this->order)
267 {
268 if ($cloneEntity->contains($this->order))
269 {
270 $tradeBindingCollection->order = $cloneEntity[$this->order];
271 }
272 }
273
274 return $tradeBindingCollection;
275 }
276
284 public function hasTradingPlatform(string $platformCode, string $type = null): bool
285 {
286 return $this->getTradingPlatform($platformCode, $type) ? true : false;
287 }
288
296 public function getTradingPlatform(string $platformCode, string $type = null)
297 {
298 foreach ($this->collection as $item)
299 {
300 $tradingPlatform = $item->getTradePlatform();
301 if (!$tradingPlatform || $tradingPlatform::TRADING_PLATFORM_CODE !== $platformCode)
302 {
303 continue;
304 }
305
306 if (!is_null($type) && !$tradingPlatform->isOfType($type))
307 {
308 continue;
309 }
310
311 return $tradingPlatform;
312 }
313
314 return null;
315 }
316
317 public function getTradingPlatformIdList() : array
318 {
319 $result = [];
320
321 foreach ($this->collection as $item)
322 {
323 $result[] = $item->getField('TRADING_PLATFORM_ID');
324 }
325
326 return $result;
327 }
328}
$type
Определения options.php:106
const ADD
Определения eventactions.php:8
const DELETE
Определения eventactions.php:10
const UPDATE
Определения eventactions.php:9
const ENTITY_TRADE_BINDING_COLLECTION
Определения registry.php:55
static getInstance($type)
Определения registry.php:183
const REGISTRY_TYPE_ORDER
Определения registry.php:16
const ENTITY_TRADE_BINDING_ENTITY
Определения registry.php:56
static getList(array $parameters=array())
Определения tradebindingcollection.php:92
hasTradingPlatform(string $platformCode, string $type=null)
Определения tradebindingcollection.php:284
static deleteNoDemand($idOrder)
Определения tradebindingcollection.php:218
bindItem(CollectableEntity $item)
Определения tradebindingcollection.php:142
getTradingPlatform(string $platformCode, string $type=null)
Определения tradebindingcollection.php:296
static deleteInternal($primary)
Определения tradebindingcollection.php:245
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$entity
$name
Определения menu_edit.php:35
$platform
Определения settings.php:7
$order
Определения payment.php:8
$dbRes
Определения yandex_detail.php:168