Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basket.php
1<?php
8namespace Bitrix\Sale;
9
12use Bitrix\Main;
13
14Loc::loadMessages(__FILE__);
15
20class Basket extends BasketBase
21{
22 const BASKET_DELETE_LIMIT = 2000;
23
27 public static function getRegistryType()
28 {
30 }
31
37 public static function getList(array $parameters = array())
38 {
39 return Internals\BasketTable::getList($parameters);
40 }
41
49 public static function deleteNoDemand($idOrder)
50 {
51 $result = new Result();
52
53 $itemsDataList = static::getList(
54 array(
55 "filter" => array("=ORDER_ID" => $idOrder),
56 "select" => array("ID", "TYPE")
57 )
58 );
59
61 $itemClassName = static::getItemCollectionClassName();
62 while ($item = $itemsDataList->fetch())
63 {
64 if ($item['TYPE'] === $itemClassName::TYPE_SET)
65 {
66 $r = Internals\BasketTable::deleteBundle($item['ID']);
67 }
68 else
69 {
70 $r = Internals\BasketTable::deleteWithItems($item['ID']);
71 }
72
73 if (!$r->isSuccess())
74 {
75 $result->addErrors($r->getErrors());
76 }
77 }
78
79 return $result;
80 }
81
87 public static function deleteOld($days)
88 {
89 $expired = new Main\Type\DateTime();
90 $expired->add('-'.$days.' days');
91 $expiredValue = $expired->format('Y-m-d H:i:s');
92
94 $connection = Main\Application::getConnection();
96 $sqlHelper = $connection->getSqlHelper();
97
98 $sqlExpiredDate = $sqlHelper->getDateToCharFunction("'" . $expiredValue . "'");
99
100 $query = "DELETE FROM b_sale_basket WHERE
101 FUSER_ID IN (
102 SELECT b_sale_fuser.id FROM b_sale_fuser WHERE
103 b_sale_fuser.DATE_UPDATE < ".$sqlExpiredDate."
104 AND b_sale_fuser.USER_ID IS NULL
105 ) AND ORDER_ID IS NULL LIMIT ". static::BASKET_DELETE_LIMIT;
106
107 $connection->queryExecute($query);
108 $affectRows = $connection->getAffectedRowsCount();
109
110 $query = "DELETE FROM b_sale_basket
111 WHERE
112 FUSER_ID NOT IN (SELECT b_sale_fuser.id FROM b_sale_fuser)
113 AND
114 ORDER_ID IS NULL
115 LIMIT ". static::BASKET_DELETE_LIMIT;
116
117 $connection->queryExecute($query);
118 $affectRows = max($affectRows, $connection->getAffectedRowsCount());
119
120 $query = "
121 DELETE
122 FROM b_sale_basket_props
123 WHERE b_sale_basket_props.BASKET_ID NOT IN (
124 SELECT b_sale_basket.ID FROM b_sale_basket
125 )
126 LIMIT ".static::BASKET_DELETE_LIMIT;
127
128 $connection->queryExecute($query);
129
130 return max($affectRows, $connection->getAffectedRowsCount());
131 }
132
140 public static function deleteOldAgent($days, $speed = 0)
141 {
142 if (!isset($GLOBALS["USER"]) || !is_object($GLOBALS["USER"]))
143 {
144 $tmpUser = True;
145 $GLOBALS["USER"] = new \CUser();
146 }
147
148 $affectRows = static::deleteOld($days);
149 Fuser::deleteOld($days);
150
151 $days = intval(Main\Config\Option::get("sale", "delete_after", "30"));
152 $result = "\Bitrix\Sale\Basket::deleteOldAgent(".$days.");";
153
154 if ($affectRows === static::BASKET_DELETE_LIMIT)
155 {
156 global $pPERIOD;
157 $pPERIOD = 300;
158 }
159
160 if (isset($tmpUser))
161 {
162 unset($GLOBALS["USER"]);
163 }
164
165 return $result;
166 }
167
174 // must be moved to notify
175 public function getListOfFormatText()
176 {
177 $list = array();
178
180 $basketItemClassName = static::getItemCollectionClassName();
181
183 foreach ($this->collection as $basketItem)
184 {
185 $basketItemData = $basketItem->getField("NAME");
186
188 if ($basketPropertyCollection = $basketItem->getPropertyCollection())
189 {
190 $basketItemDataProperty = "";
192 foreach ($basketPropertyCollection as $basketPropertyItem)
193 {
194 if ($basketPropertyItem->getField('CODE') == "PRODUCT.XML_ID"
195 || $basketPropertyItem->getField('CODE') == "CATALOG.XML_ID"
196 || $basketPropertyItem->getField('CODE') == "SUM_OF_CHARGE"
197 )
198 {
199 continue;
200 }
201
202 if (strval(trim($basketPropertyItem->getField('VALUE'))) == "")
203 continue;
204
205
206 $basketItemDataProperty .= (!empty($basketItemDataProperty) ? "; " : "").trim($basketPropertyItem->getField('NAME')).": ".trim($basketPropertyItem->getField('VALUE'));
207 }
208
209 if (!empty($basketItemDataProperty))
210 $basketItemData .= " [".$basketItemDataProperty."]";
211 }
212
213 $measure = (strval($basketItem->getField("MEASURE_NAME")) != '') ? $basketItem->getField("MEASURE_NAME") : Loc::getMessage("SOA_SHT");
214 $list[$basketItem->getBasketCode()] = $basketItemData." - ".$basketItemClassName::formatQuantity($basketItem->getQuantity())." ".$measure." x ".SaleFormatCurrency($basketItem->getPrice(), $basketItem->getCurrency());
215
216 }
217
218 return !empty($list) ? $list : false;
219 }
220
226 public function save()
227 {
228 $result = parent::save();
229
230 $orderId = $this->getOrderId();
231 if ($orderId > 0)
232 {
233 $registry = Registry::getInstance(static::getRegistryType());
234
236 $orderHistory = $registry->getOrderHistoryClassName();
237 $orderHistory::collectEntityFields('BASKET', $orderId);
238 }
239
240 return $result;
241 }
242
250 protected function deleteInternal(array $itemValues)
251 {
252 $result = new Result();
253
255 $itemClassName = static::getItemCollectionClassName();
256 if ($itemValues['TYPE'] == $itemClassName::TYPE_SET)
257 {
258 $r = Internals\BasketTable::deleteBundle($itemValues['ID']);
259 }
260 else
261 {
262 $r = Internals\BasketTable::deleteWithItems($itemValues['ID']);
263 }
264
265 if (!$r->isSuccess())
266 {
267 $result->addErrors($r->getErrors());
268 }
269
270 $orderId = $this->getOrderId();
271 if ($orderId > 0)
272 {
273 $registry = Registry::getInstance(static::getRegistryType());
274
276 $orderHistory = $registry->getOrderHistoryClassName();
277 $orderHistory::addLog(
278 'BASKET',
279 $orderId,
280 'BASKET_ITEM_DELETED',
281 $itemValues['ID'],
282 null,
283 array(
284 "PRODUCT_ID" => $itemValues["PRODUCT_ID"],
285 "NAME" => $itemValues["NAME"],
286 "QUANTITY" => $itemValues["QUANTITY"],
287 ),
288 $orderHistory::SALE_ORDER_HISTORY_LOG_LEVEL_1
289 );
290 }
291
292 return $result;
293 }
294
300 protected function callEventOnSaleBasketItemDeleted($itemValues)
301 {
302 parent::callEventOnSaleBasketItemDeleted($itemValues);
303
304 $orderId = $this->getOrderId();
305 if ($orderId > 0)
306 {
307 $registry = Registry::getInstance(static::getRegistryType());
308
310 $orderHistory = $registry->getOrderHistoryClassName();
311 $orderHistory::addAction(
312 'BASKET',
313 $orderId,
314 'BASKET_REMOVED',
315 $itemValues['ID'],
316 null,
317 array(
318 'NAME' => $itemValues['NAME'],
319 'QUANTITY' => $itemValues['QUANTITY'],
320 'PRODUCT_ID' => $itemValues['PRODUCT_ID'],
321 )
322 );
323
325 $entityMarker = $registry->getEntityMarkerClassName();
326 $entityMarker::deleteByFilter(array(
327 '=ORDER_ID' => $orderId,
328 '=ENTITY_TYPE' => $entityMarker::ENTITY_TYPE_BASKET_ITEM,
329 '=ENTITY_ID' => $itemValues['ID'],
330 ));
331 }
332 }
333
346 public function deleteItem($index)
347 {
349 if ($order = $this->getOrder())
350 {
352 $item = $this->getItemByIndex($index);
353
354 $order->onBeforeBasketItemDelete($item);
355 }
356
357 return parent::deleteItem($index);
358 }
359
360}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
deleteInternal(array $itemValues)
callEventOnSaleBasketItemDeleted($itemValues)
const BASKET_DELETE_LIMIT
Definition basket.php:22
static getList(array $parameters=array())
Definition basket.php:37
static deleteOldAgent($days, $speed=0)
Definition basket.php:140
static getRegistryType()
Definition basket.php:27
static getInstance($type)
Definition registry.php:183
$GLOBALS['____1444769544']
Definition license.php:1