Bitrix-D7  20.5.0
bundlecollection.php
См. документацию.
1 <?php
2 
3 namespace Bitrix\Sale;
4 
5 use Bitrix\Main;
8 
9 /**
10  * Class BundleCollection
11  * @package Bitrix\Sale
12  */
14 {
15  /** @var null|BasketItem */
16  protected $parentBasketItem = null;
17 
18  /**
19  * @param BasketItem $basketItem
20  */
21  public function setParentBasketItem(BasketItem $basketItem)
22  {
23  $this->parentBasketItem = $basketItem;
24  }
25 
26  /**
27  * @return BasketItem|null
28  */
29  public function getParentBasketItem()
30  {
32  }
33 
34  /**
35  * @return BasketItem|null
36  */
37  protected function getEntityParent()
38  {
39  return $this->getParentBasketItem();
40  }
41 
42  /**
43  * @param CollectableEntity $item
44  * @return CollectableEntity
45  * @throws Main\ArgumentTypeException
46  */
47  public function addItem(CollectableEntity $item)
48  {
49  return parent::addItem($item);
50  }
51 
52  /**
53  * @param array $parameters
54  * @return Main\DB\Result
55  * @throws Main\ArgumentException
56  */
57  public static function getList(array $parameters)
58  {
59  $registry = Registry::getInstance(static::getRegistryType());
60 
61  /** @var Basket $basketClassName */
62  $basketClassName = $registry->getBasketClassName();
63 
64  return $basketClassName::getList($parameters);
65  }
66 
67  /**
68  * @param $index
69  * @return mixed
70  * @throws Main\ArgumentException
71  * @throws Main\ArgumentNullException
72  * @throws Main\ArgumentOutOfRangeException
73  * @throws Main\NotSupportedException
74  * @throws Main\ObjectNotFoundException
75  * @throws Main\SystemException
76  */
77  public function deleteItem($index)
78  {
79  /** @var Order $order */
80  if ($order = $this->getOrder())
81  {
82  /** @var BasketItem $item */
83  $item = $this->getItemByIndex($index);
84 
85  $order->onBeforeBasketItemDelete($item);
86  }
87 
88  return parent::deleteItem($index);
89  }
90 
91  /**
92  * @return BundleCollection
93  * @throws Main\ArgumentException
94  */
95  public static function createBundleCollectionObject()
96  {
97  $registry = Registry::getInstance(static::getRegistryType());
98  $bundleCollectionClassName = $registry->getBundleCollectionClassName();
99 
100  return new $bundleCollectionClassName();
101  }
102 
103  /**
104  * @param array $filter
105  * @return BundleCollection
106  * @throws Main\ArgumentException
107  * @throws Main\ArgumentTypeException
108  * @throws Main\NotImplementedException
109  */
110  public function loadFromDb(array $filter)
111  {
112  $select = array("ID", "LID", "MODULE", "PRODUCT_ID", "QUANTITY", "WEIGHT",
113  "DELAY", "CAN_BUY", "PRICE", "CUSTOM_PRICE", "BASE_PRICE", 'PRODUCT_PRICE_ID', "CURRENCY", 'BARCODE_MULTI',
114  "RESERVED", "RESERVE_QUANTITY", "NAME", "CATALOG_XML_ID", "VAT_RATE", "NOTES", "DISCOUNT_PRICE",
115  "PRODUCT_PROVIDER_CLASS", "CALLBACK_FUNC", "ORDER_CALLBACK_FUNC", "PAY_CALLBACK_FUNC", "CANCEL_CALLBACK_FUNC",
116  "DIMENSIONS", "TYPE", "SET_PARENT_ID", "DETAIL_PAGE_URL", "FUSER_ID", 'MEASURE_CODE', 'MEASURE_NAME', 'ORDER_ID',
117  'DATE_INSERT', 'DATE_UPDATE', 'PRODUCT_XML_ID', 'SUBSCRIBE', 'RECOMMENDATION', 'VAT_INCLUDED', 'SORT'
118  );
119 
120  $itemList = array();
121 
122  $res = static::getList(array(
123  "filter" => $filter,
124  "select" => $select,
125  "order" => array('SORT' => 'ASC', 'ID' => 'ASC'),
126  ));
127  while ($item = $res->fetch())
128  {
129  $itemList[$item['ID']] = $item;
130  }
131 
132  $this->loadFromArray($itemList);
133 
134  return $this;
135  }
136 
137  /**
138  * @internal
139  *
140  * @param \SplObjectStorage|null $cloneEntity
141  * @return BundleCollection|EntityCollection
142  * @throws Main\ArgumentException
143  * @throws Main\ArgumentNullException
144  * @throws Main\ArgumentOutOfRangeException
145  * @throws Main\ArgumentTypeException
146  * @throws Main\NotImplementedException
147  * @throws Main\ObjectException
148  * @throws Main\ObjectNotFoundException
149  * @throws \Exception
150  */
151  public function createClone(\SplObjectStorage $cloneEntity = null)
152  {
153  if ($cloneEntity === null)
154  {
155  $cloneEntity = new \SplObjectStorage();
156  }
157 
158  /** @var BundleCollection $bundleClone */
159  $bundleClone = parent::createClone($cloneEntity);
160 
161  /** @var BasketItem $parentBasketItem */
162  if ($parentBasketItem = $this->parentBasketItem)
163  {
164  if (!$cloneEntity->contains($parentBasketItem))
165  {
166  $cloneEntity[$parentBasketItem] = $parentBasketItem->createClone($cloneEntity);
167  }
168 
169  if ($cloneEntity->contains($parentBasketItem))
170  {
171  $bundleClone->parentBasketItem = $cloneEntity[$parentBasketItem];
172  }
173  }
174 
175  return $bundleClone;
176  }
177 
178  /**
179  * @return BasketBase
180  */
181  public function getBasket()
182  {
183  $collection = $this;
184 
185  while($collection && $collection instanceof BundleCollection)
186  {
187  $entityParent = $collection->getEntityParent();
188  $collection = $entityParent->getCollection();
189  }
190 
191  if ($collection instanceof BasketBase)
192  {
193  return $collection;
194  }
195 
196  return null;
197  }
198 
199  /**
200  * @return string
201  */
202  public static function getRegistryType()
203  {
205  }
206 
207  /**
208  * @param CollectableEntity $item
209  * @param null $name
210  * @param null $oldValue
211  * @param null $value
212  * @return Result
213  * @throws Main\ArgumentException
214  * @throws Main\ArgumentNullException
215  * @throws Main\ArgumentOutOfRangeException
216  * @throws Main\ArgumentTypeException
217  * @throws Main\NotImplementedException
218  * @throws Main\NotSupportedException
219  * @throws Main\ObjectNotFoundException
220  * @throws Main\SystemException
221  */
222  public function onItemModify(Internals\CollectableEntity $item, $name = null, $oldValue = null, $value = null)
223  {
224  if (!($item instanceof BasketItemBase))
225  throw new Main\ArgumentTypeException($item);
226 
227  $result = new Result();
228 
229  /** @var Order $order */
230  $order = $this->getOrder();
231  if ($order)
232  {
233  $shipmentCollection = $order->getShipmentCollection();
234  if ($shipmentCollection)
235  {
236  $r = $shipmentCollection->onBasketModify(EventActions::UPDATE, $item, $name, $oldValue, $value);
237  if (!$r->isSuccess())
238  {
239  $result->addErrors($r->getErrors());
240  }
241  }
242  }
243 
244  return $result;
245  }
246 }
Exception is thrown when the type of an argument is not accepted by function.
setParentBasketItem(BasketItem $basketItem)
static getList(array $parameters)
addItem(CollectableEntity $item)
onItemModify(Internals\CollectableEntity $item, $name=null, $oldValue=null, $value=null)
createClone(\SplObjectStorage $cloneEntity=null)