Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basket.php
1<?php
9
10use Bitrix\Main;
15
16Loc::loadMessages(__FILE__);
17
34class BasketTable extends Main\Entity\DataManager
35{
36
42 public static function deleteBundle($id)
43 {
44 $id = intval($id);
45 if ($id <= 0)
46 throw new Main\ArgumentNullException("id");
47
48 $itemsFromDbList = BasketTable::getList(
49 array(
50 "filter" => array(
51 'SET_PARENT_ID' => $id,
52 ),
53 "select" => array("ID")
54 )
55 );
56 while ($itemsFromDbItem = $itemsFromDbList->fetch())
57 BasketTable::deleteWithItems($itemsFromDbItem['ID']);
58
59 return BasketTable::deleteWithItems($id);
60 }
61
68 public static function deleteWithItems($id)
69 {
70 $id = intval($id);
71 if ($id <= 0)
72 {
73 throw new Main\ArgumentNullException("id");
74 }
75
76 $dbRes = BasketPropertyTable::getList([
77 "select" => ["ID"],
78 "filter" => ["BASKET_ID" => $id],
79 ]);
80 while ($item = $dbRes->fetch())
81 {
82 BasketPropertyTable::delete($item["ID"]);
83 }
84
86 $service = ServiceLocator::getInstance()->get('sale.basketReservation');
88 "select" => ["ID"],
89 "filter" => ["BASKET_ID" => $id],
90 ]);
91 while ($item = $dbRes->fetch())
92 {
93 $service->delete($item["ID"]);
94 }
95
96 return BasketTable::delete($id);
97 }
98
102 public static function getTableName()
103 {
104 return 'b_sale_basket';
105 }
106
110 public static function getMap()
111 {
112 global $DB;
113
114 $connection = Main\Application::getConnection();
115 $helper = $connection->getSqlHelper();
116
117 return array(
118 'ID' => array(
119 'data_type' => 'integer',
120 'primary' => true,
121 'autocomplete' => true,
122 ),
123 'LID' => array(
124 'data_type' => 'string',
125 'required' => true,
126 'validation' => array(__CLASS__, 'validateLid'),
127 ),
128 'FUSER_ID' => array(
129 'data_type' => 'integer',
130 'required' => true,
131 ),
132
133 new Main\Entity\ReferenceField(
134 'FUSER',
135 'Bitrix\Sale\Internals\Fuser',
136 array('=this.FUSER_ID' => 'ref.ID'),
137 array('join_type' => 'INNER')
138 ),
139
140 new Main\Entity\ReferenceField(
141 'USER',
142 'Bitrix\Main\User',
143 array('=ref.ID' => 'this.FUSER.USER_ID')
144 ),
145
146 'ORDER_ID' => array(
147 'data_type' => 'integer'
148 ),
149
150 new Main\Entity\ReferenceField(
151 'ORDER',
152 'Bitrix\Sale\Internals\Order',
153 array('=this.ORDER_ID' => 'ref.ID')
154 ),
155
156 'PRODUCT_ID' => array(
157 'data_type' => 'integer',
158 'required' => true,
159 ),
160 'PRODUCT' => array(
161 'data_type' => 'Product',
162 'reference' => array(
163 '=this.PRODUCT_ID' => 'ref.ID'
164 )
165 ),
166 'PRODUCT_PRICE_ID' => array(
167 'data_type' => 'integer'
168 ),
169 'PRICE_TYPE_ID' => array(
170 'data_type' => 'integer'
171 ),
172 'NAME' => array(
173 'data_type' => 'string'
174 ),
175
176 new Main\Entity\ExpressionField(
177 'NAME_WITH_IDENT',
178 $helper->getConcatFunction("%s", "' ['", "%s", "']'"),
179 array('NAME', 'PRODUCT_ID')
180 ),
181
182 new Main\Entity\FloatField(
183 'PRICE'
184 ),
185
186 'CURRENCY' => array(
187 'data_type' => 'string',
188 'required' => true,
189 'validation' => array(__CLASS__, 'validateCurrency'),
190 ),
191
192 new Main\Entity\FloatField(
193 'BASE_PRICE'
194 ),
195
196 'VAT_INCLUDED' => array(
197 'data_type' => 'boolean',
198 'values' => array('Y','N')
199 ),
200
201 'DATE_INSERT' => array(
202 'data_type' => 'datetime'
203 ),
204 new Main\Entity\ExpressionField(
205 'DATE_INS',
206 $DB->datetimeToDateFunction('%s'),
207 array('DATE_INSERT'),
208 array('data_type' => 'datetime')
209 ),
210
211 'DATE_UPDATE' => array(
212 'data_type' => 'datetime'
213 ),
214 new Main\Entity\ExpressionField(
215 'DATE_UPD',
216 $DB->datetimeToDateFunction('%s'),
217 array('DATE_UPDATE'),
218 array('data_type' => 'datetime')
219 ),
220
221 'DATE_REFRESH' => array(
222 'data_type' => 'datetime'
223 ),
224 new Main\Entity\ExpressionField(
225 'DATE_REF',
226 $DB->datetimeToDateFunction('%s'),
227 array('DATE_REFRESH'),
228 array('data_type' => 'datetime')
229 ),
230
231 new Main\Entity\FloatField(
232 'WEIGHT'
233 ),
234
235 new Main\Entity\FloatField(
236 'QUANTITY',
237 array(
238 'required' => true
239 )
240 ),
241
242 'DELAY' => array(
243 'data_type' => 'boolean',
244 'values' => array('N','Y')
245 ),
246
247 'SUMMARY_PRICE' => array(
248 'data_type' => 'float',
249 'expression' => array(
250 '(%s * %s)', 'QUANTITY', 'PRICE'
251 )
252 ),
253
254 'CAN_BUY' => array(
255 'data_type' => 'boolean',
256 'values' => array('N','Y')
257 ),
258
259 'MARKING_CODE_GROUP' => array(
260 'data_type' => 'string',
261 ),
262
263 'MODULE' => array(
264 'data_type' => 'string'
265 ),
266
267 'PRODUCT_PROVIDER_CLASS' => array(
268 'data_type' => 'string'
269 ),
270
271 'NOTES' => array(
272 'data_type' => 'string'
273 ),
274
275 'DETAIL_PAGE_URL' => array(
276 'data_type' => 'string'
277 ),
278
279 new Main\Entity\FloatField(
280 'DISCOUNT_PRICE',
281 array(
282 'default_value' => '0.00'
283 )
284 ),
285
286 'CATALOG_XML_ID' => array(
287 'data_type' => 'string'
288 ),
289
290 'PRODUCT_XML_ID' => array(
291 'data_type' => 'string'
292 ),
293
294 'DISCOUNT_NAME' => array(
295 'data_type' => 'string',
296 'validation' => array(__CLASS__, 'validateDiscountName'),
297 ),
298
299 'DISCOUNT_VALUE' => array(
300 'data_type' => 'string',
301 'validation' => array(__CLASS__, 'validateDiscountValue'),
302 ),
303
304 'DISCOUNT_COUPON' => array(
305 'data_type' => 'string',
306 'validation' => array(__CLASS__, 'validateDiscountCoupon'),
307 ),
308
309 new Main\Entity\FloatField(
310 'VAT_RATE'
311 ),
312
313 new Main\Entity\ExpressionField(
314 'VAT_RATE_PRC',
315 '100 * %s',
316 array('VAT_RATE')
317 ),
318
319 'SUBSCRIBE' => array(
320 'data_type' => 'boolean',
321 'values' => array('N','Y')
322 ),
323 'N_SUBSCRIBE' => array(
324 'data_type' => 'integer',
325 'expression' => array(
326 'CASE WHEN %s = \'Y\' THEN 1 ELSE 0 END', 'SUBSCRIBE'
327 )
328 ),
329
330 'RESERVED' => array(
331 'data_type' => 'boolean',
332 'values' => array('N', 'Y'),
333 ),
334
335 new Main\Entity\FloatField(
336 'RESERVE_QUANTITY'
337 ),
338
339 'BARCODE_MULTI' => array(
340 'data_type' => 'boolean',
341 'values' => array('N','Y')
342 ),
343
344 'CUSTOM_PRICE' => array(
345 'data_type' => 'boolean',
346 'values' => array('N','Y')
347 ),
348
349 'DIMENSIONS' => array(
350 'serialized' => true,
351 'data_type' => 'string'
352 ),
353
354 new Main\Entity\IntegerField(
355 'TYPE'
356 ),
357 new Main\Entity\IntegerField(
358 'SET_PARENT_ID'
359 ),
360 new Main\Entity\IntegerField(
361 'MEASURE_CODE'
362 ),
363
364 'MEASURE_NAME' => array(
365 'data_type' => 'string'
366 ),
367
368 'CALLBACK_FUNC' => array(
369 'data_type' => 'string'
370 ),
371
372 'ORDER_CALLBACK_FUNC' => array(
373 'data_type' => 'string'
374 ),
375
376 'CANCEL_CALLBACK_FUNC' => array(
377 'data_type' => 'string'
378 ),
379
380 'PAY_CALLBACK_FUNC' => array(
381 'data_type' => 'string'
382 ),
383
384 'RECOMMENDATION' => array(
385 'data_type' => 'string'
386 ),
387
388
389 'ALL_PRICE' => array(
390 'data_type' => 'float',
391 'expression' => array(
392 '(%s + %s)', 'PRICE', 'DISCOUNT_PRICE'
393 )
394 ),
395
396 'SUMMARY_PURCHASING_PRICE' => array(
397 'data_type' => 'float',
398 'expression' => array(
399 '(%s) * %s', 'PRODUCT.PURCHASING_PRICE_IN_SITE_CURRENCY', 'QUANTITY'
400 )
401 ),
402 'GROSS_PROFIT' => array(
403 'data_type' => 'float',
404 'expression' => array(
405 '(%s) - (%s)', 'SUMMARY_PRICE', 'SUMMARY_PURCHASING_PRICE'
406 )
407 ),
408 'PROFITABILITY' => array(
409 'data_type' => 'float',
410 'expression' => array(
411 'CASE WHEN %s is NULL OR %s=0 THEN NULL ELSE (%s) * 100 / (%s) END',
412 'SUMMARY_PURCHASING_PRICE', 'SUMMARY_PURCHASING_PRICE', 'GROSS_PROFIT', 'SUMMARY_PURCHASING_PRICE'
413 )
414 ),
415
416 'SHIPMENT_ITEM' => array(
417 'data_type' => 'ShipmentItem',
418 'reference' => array(
419 '=ref.BASKET_ID' => 'this.ID',
420 )
421 ),
422 'SHIPMENT' => array(
423 'data_type' => 'Shipment',
424 'reference' => array(
425 '=ref.ID' => 'this.SHIPMENT_ITEM.ORDER_DELIVERY_ID',
426 )
427 ),
428
429 'PAYMENT' => array(
430 'data_type' => 'Payment',
431 'reference' => array(
432 '=ref.ORDER_ID' => 'this.ORDER_ID',
433 )
434 ),
435
436 new Main\Entity\IntegerField(
437 'SORT',
438 array(
439 'default' => '100'
440 )
441 ),
442
443 'XML_ID' => array(
444 'data_type' => 'string'
445 ),
446 );
447 }
448
454 public static function validateCurrency()
455 {
456 return array(
457 new Main\Entity\Validator\Length(null, 3),
458 );
459 }
460
466 public static function validateLid()
467 {
468 return array(
469 new Main\Entity\Validator\Length(null, 2),
470 );
471 }
472
478 public static function validateDiscountName()
479 {
480 return array(
481 new Main\Entity\Validator\Length(null, 255),
482 );
483 }
484
490 public static function validateDiscountValue()
491 {
492 return array(
493 new Main\Entity\Validator\Length(null, 32),
494 );
495 }
496
502 public static function validateDiscountCoupon()
503 {
504 return array(
505 new Main\Entity\Validator\Length(null, 32),
506 );
507 }
508
509
510}
static loadMessages($file)
Definition loc.php:64
static getList(array $parameters=array())