1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
basketitemcollection.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale;
4
5use Bitrix\Currency;
6use Bitrix\Main\Engine\CurrentUser;
7use Bitrix\Main\Loader;
8use Bitrix\Main\Localization\Loc;
9use Bitrix\Main\NotImplementedException;
10use Bitrix\Sale\Internals;
11
12Loc::loadMessages(__FILE__);
13
19{
29 public function createItem($moduleId, $productId, $basketCode = null)
30 {
31 $basketItem = static::createItemInternal($this, $moduleId, $productId, $basketCode);
32
33 $basketItem->setCollection($this);
34 $this->addItem($basketItem);
35
36 return $basketItem;
37 }
38
48 protected static function createItemInternal(BasketItemCollection $basket, $moduleId, $productId, $basketCode = null)
49 {
51 $basketItemClassName = static::getItemCollectionClassName();
52 return $basketItemClassName::create($basket, $moduleId, $productId, $basketCode);
53 }
54
58 public function getOrder()
59 {
60 $basket = $this->getBasket();
61 if ($basket)
62 return $basket->getOrder();
63
64 return null;
65 }
66
70 abstract public function getBasket();
71
75 public function loadFromArray(array $itemList)
76 {
78 $itemClassName = static::getItemCollectionClassName();
79
80 foreach ($itemList as $item)
81 {
82 $basketItem = $itemClassName::load($this, $item);
83 $this->bindItem($basketItem);
84 }
85
87 $controller->initializeCollection($this);
88 }
89
95 protected static function getItemCollectionClassName()
96 {
97 $registry = Registry::getInstance(static::getRegistryType());
98 return $registry->getBasketItemClassName();
99 }
100
106 public function getItemByBasketCode($code)
107 {
109 foreach ($this->collection as $basketItem)
110 {
111 $basketItem = $basketItem->findItemByBasketCode($code);
112 if ($basketItem != null)
113 {
114 return $basketItem;
115 }
116 }
117
118 return null;
119 }
120
127 public function getItemByXmlId($xmlId)
128 {
130 foreach ($this->collection as $basketItem)
131 {
132 $basketItem = $basketItem->findItemByXmlId($xmlId);
133 if ($basketItem != null)
134 {
135 return $basketItem;
136 }
137 }
138
139 return null;
140 }
141
147 public function getItemById($id)
148 {
149 $id = (int)$id;
150
151 if ($id <= 0)
152 {
153 return null;
154 }
155
157 foreach ($this->collection as $basketItem)
158 {
159 $item = $basketItem->findItemById($id);
160 if ($item !== null)
161 {
162 return $item;
163 }
164 }
165
166 return null;
167 }
168
172 public function getBasketItems()
173 {
174 return $this->collection;
175 }
176
187 public function getExistsItems(string $moduleId, int $productId, ?array $properties = [])
188 {
189 $result = [];
190
191 foreach ($this->getBasketItems() as $basketItem)
192 {
193 if ((int)$basketItem->getField('PRODUCT_ID') === $productId && $basketItem->getField('MODULE') === $moduleId)
194 {
195 // skip check properties
196 if (is_null($properties))
197 {
198 $result[] = $basketItem;
199 continue;
200 }
201
203 $basketPropertyCollection = $basketItem->getPropertyCollection();
204 if ($properties)
205 {
206 if ($basketPropertyCollection->isPropertyAlreadyExists($properties))
207 {
208 $result[] = $basketItem;
209 }
210 }
211 elseif (count($basketPropertyCollection) === 0)
212 {
213 $result[] = $basketItem;
214 }
215 }
216 }
217
218 return $result;
219 }
220
224 public function getOrderId()
225 {
226 $order = $this->getOrder();
227 if ($order)
228 return $order->getId();
229
230 return 0;
231 }
232
238 public function getContext()
239 {
240 global $USER;
241 $context = array();
242
244 $basketItem = $this->rewind();
245 if ($basketItem)
246 {
247 $siteId = $basketItem->getField('LID');
248 $fuserId = $basketItem->getFUserId();
249
250 $userId = Fuser::getUserIdById($fuserId);
251
252 if (empty($context['SITE_ID']))
253 {
254 $context['SITE_ID'] = $siteId;
255 }
256
257 if (empty($context['USER_ID']) && $userId > 0)
258 {
259 $context['USER_ID'] = $userId;
260 }
261 }
262
263 if (empty($context['SITE_ID']))
264 {
265 $context['SITE_ID'] = SITE_ID;
266 }
267
268 if (empty($context['USER_ID']))
269 {
270 $context['USER_ID'] = isset($USER) && $USER instanceof \CUser ? (int)$USER->GetID() : 0;
271 }
272
273 if (Loader::includeModule('currency'))
274 {
275 if (!empty($context['SITE_ID']))
276 {
277 $currency = Internals\SiteCurrencyTable::getSiteCurrency($context['SITE_ID']);
278 }
279
280 if (empty($currency))
281 {
282 $currency = Currency\CurrencyManager::getBaseCurrency();
283 }
284
285 if (!empty($currency) && Currency\CurrencyManager::checkCurrencyID($currency))
286 {
287 $context['CURRENCY'] = $currency;
288 }
289 }
290
291 return $context;
292 }
293
307 public function getExistsItem($moduleId, $productId, array $properties = array())
308 {
309 return current($this->getExistsItems($moduleId, $productId, $properties)) ?: null;
310 }
311}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
createItem($moduleId, $productId, $basketCode=null)
Определения basketitemcollection.php:29
static getItemCollectionClassName()
Определения basketitemcollection.php:95
getExistsItem($moduleId, $productId, array $properties=array())
Определения basketitemcollection.php:307
static getUserIdById($fuserId)
Определения fuser.php:177
static getInstance($type)
Определения registry.php:183
</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
$moduleId
global $USER
Определения csv_new_run.php:40
$context
Определения csv_new_setup.php:223
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$siteId
Определения ajax.php:8
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$currency
Определения template.php:266
const SITE_ID
Определения sonet_set_content_view.php:12