29 public function createItem($moduleId, $productId, $basketCode =
null)
31 $basketItem = static::createItemInternal($this, $moduleId, $productId, $basketCode);
33 $basketItem->setCollection($this);
34 $this->addItem($basketItem);
48 protected static function createItemInternal(
BasketItemCollection $basket, $moduleId, $productId, $basketCode =
null)
51 $basketItemClassName = static::getItemCollectionClassName();
52 return $basketItemClassName::create($basket, $moduleId, $productId, $basketCode);
62 return $basket->getOrder();
78 public function loadFromArray(array $itemList)
81 $itemClassName = static::getItemCollectionClassName();
83 foreach ($itemList as $item)
85 $basketItem = $itemClassName::load($this, $item);
86 $this->addItem($basketItem);
89 $controller = Internals\CustomFieldsController::getInstance();
90 $controller->initializeCollection($this);
101 return $registry->getBasketItemClassName();
109 public function getItemByBasketCode($code)
112 foreach ($this->collection as $basketItem)
114 $basketItem = $basketItem->findItemByBasketCode($code);
115 if ($basketItem !=
null)
130 public function getItemByXmlId($xmlId)
133 foreach ($this->collection as $basketItem)
135 $basketItem = $basketItem->findItemByXmlId($xmlId);
136 if ($basketItem !=
null)
160 foreach ($this->collection as $basketItem)
162 $item = $basketItem->findItemById($id);
190 public function getExistsItems(
string $moduleId,
int $productId, ?array $properties = [])
196 if ((
int)$basketItem->getField(
'PRODUCT_ID') === $productId && $basketItem->getField(
'MODULE') === $moduleId)
199 if (is_null($properties))
201 $result[] = $basketItem;
206 $basketPropertyCollection = $basketItem->getPropertyCollection();
209 if ($basketPropertyCollection->isPropertyAlreadyExists($properties))
211 $result[] = $basketItem;
214 elseif (
count($basketPropertyCollection) === 0)
216 $result[] = $basketItem;
231 return $order->getId();
241 public function getContext()
247 $basketItem = $this->
rewind();
250 $siteId = $basketItem->getField(
'LID');
251 $fuserId = $basketItem->getFUserId();
255 if (empty($context[
'SITE_ID']))
257 $context[
'SITE_ID'] = $siteId;
260 if (empty($context[
'USER_ID']) && $userId > 0)
262 $context[
'USER_ID'] = $userId;
266 if (empty($context[
'SITE_ID']))
268 $context[
'SITE_ID'] = SITE_ID;
271 if (empty($context[
'USER_ID']))
273 $context[
'USER_ID'] = isset($USER) && $USER instanceof \CUser ? (int)$USER->GetID() : 0;
276 if (Loader::includeModule(
'currency'))
278 if (!empty($context[
'SITE_ID']))
280 $currency = Internals\SiteCurrencyTable::getSiteCurrency($context[
'SITE_ID']);
283 if (empty($currency))
285 $currency = Currency\CurrencyManager::getBaseCurrency();
288 if (!empty($currency) && Currency\CurrencyManager::checkCurrencyID($currency))
290 $context[
'CURRENCY'] = $currency;
310 public function getExistsItem($moduleId, $productId, array $properties = array())
312 return current($this->getExistsItems($moduleId, $productId, $properties)) ?:
null;
static loadMessages($file)