Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
orderdiscount.php
1<?php
2namespace Bitrix\Sale;
3
7
8Loc::loadMessages(__FILE__);
9
11{
18 public static function deleteByOrder($order)
19 {
20 $order = (int)$order;
21 if ($order <= 0)
22 return;
23 Internals\OrderRulesTable::clearByOrder($order);
24 Internals\OrderDiscountDataTable::clearByOrder($order);
25 Internals\OrderRoundTable::clearByOrder($order);
26 }
27
34 public static function getRegistryType()
35 {
37 }
38
45 protected static function validateCoupon(array $fields)
46 {
47 if ($fields['TYPE'] == Internals\DiscountCouponTable::TYPE_ARCHIVED)
48 return new Result();;
49
50 return parent::validateCoupon($fields);
51 }
52
53 /* discounts */
54
61 protected static function getDiscountIterator(array $parameters)
62 {
63 return Internals\DiscountTable::getList($parameters);
64 }
65
66 /* discounts end */
67
68 /* coupons */
69
76 protected static function isValidCouponTypeInternal($type)
77 {
78 return Internals\DiscountCouponTable::isValidCouponType($type);
79 }
80
81 /* coupons end */
82
83 /* order discounts */
84
91 protected static function getOrderDiscountIterator(array $parameters)
92 {
93 return Internals\OrderDiscountTable::getList($parameters);
94 }
95
102 protected static function addOrderDiscountInternal(array $fields)
103 {
104 return Internals\OrderDiscountTable::add($fields);
105 }
106
113 protected static function checkRequiredOrderDiscountFields(array $fields)
114 {
115 return Internals\OrderDiscountTable::getEmptyFields($fields);
116 }
117
124 protected static function normalizeOrderDiscountFieldsInternal(array $rawFields)
125 {
126 $result = Internals\OrderDiscountTable::prepareDiscountData($rawFields);
127 return (is_array($result) ? $result : null);
128 }
129
136 protected static function calculateOrderDiscountHashInternal(array $fields)
137 {
138 $hash = Internals\OrderDiscountTable::calculateHash($fields);
139 return ($hash === false ? null : $hash);
140 }
141
142 /* order discounts end */
143
144 /* order coupons */
145
152 public static function getOrderCouponIterator(array $parameters)
153 {
154 return Internals\OrderCouponsTable::getList($parameters);
155 }
156
163 protected static function addOrderCouponInternal(array $fields)
164 {
165 return Internals\OrderCouponsTable::add($fields);
166 }
167
168 /* order coupons end */
169
170 /* order discount modules */
171
176 protected static function getOrderDiscountModuleIterator(array $parameters)
177 {
178 return Internals\OrderModulesTable::getList($parameters);
179 }
180
188 protected static function saveOrderDiscountModulesInternal($orderDiscountId, array $modules)
189 {
190 $result = true;
191
192 $resultModule = Internals\OrderModulesTable::saveOrderDiscountModules(
193 $orderDiscountId,
194 $modules
195 );
196 if (!$resultModule)
197 {
198 Internals\OrderDiscountTable::clearList($orderDiscountId);
199 $result = false;
200 }
201 unset($resultModule);
202
203 return $result;
204 }
205
206 /* discount results */
207
214 protected static function getResultEntityInternal($entity)
215 {
216 $result = null;
217
219 $discountClassName = static::getDiscountClassName();
220
221 switch ($entity)
222 {
223 case $discountClassName::ENTITY_BASKET_ITEM:
224 $result = Internals\OrderRulesTable::ENTITY_TYPE_BASKET_ITEM;
225 break;
226 case $discountClassName::ENTITY_DELIVERY:
227 $result = Internals\OrderRulesTable::ENTITY_TYPE_DELIVERY;
228 break;
229 }
230
231 unset($discountClassName);
232
233 return $result;
234 }
235
242 protected static function getResultEntityFromInternal($entity)
243 {
244 $result = null;
245
247 $discountClassName = static::getDiscountClassName();
248
249 switch ($entity)
250 {
251 case Internals\OrderRulesTable::ENTITY_TYPE_BASKET_ITEM:
252 $result = $discountClassName::ENTITY_BASKET_ITEM;
253 break;
254 case Internals\OrderRulesTable::ENTITY_TYPE_DELIVERY:
255 $result = $discountClassName::ENTITY_DELIVERY;
256 break;
257 }
258
259 unset($discountClassName);
260
261 return $result;
262 }
263
268 protected static function getResultIterator(array $parameters)
269 {
270 if (!isset($parameters['select']))
271 $parameters['select'] = ['*', 'RULE_DESCR' => 'DESCR.DESCR', 'RULE_DESCR_ID' => 'DESCR.ID'];
272 if (!isset($parameters['order']))
273 $parameters['order'] = ['ID' => 'ASC'];
274 return Internals\OrderRulesTable::getList($parameters);
275 }
276
281 protected static function getResultDescriptionIterator(array $parameters)
282 {
283 return Internals\OrderRulesDescrTable::getList($parameters);
284 }
285
291 protected static function getResultTableNameInternal()
292 {
293 return Internals\OrderRulesTable::getTableName();
294 }
295
301 protected static function getResultDescriptionTableNameInternal()
302 {
303 return Internals\OrderRulesDescrTable::getTableName();
304 }
305
312 protected static function checkResultTableWhiteList(array $fields)
313 {
314 $fields = array_intersect_key($fields, Internals\OrderRulesTable::getEntity()->getScalarFields());
315 return (!empty($fields) ? $fields : null);
316 }
317
324 protected static function checkResultDescriptionTableWhiteList(array $fields)
325 {
326 $fields = array_intersect_key($fields, Internals\OrderRulesDescrTable::getEntity()->getScalarFields());
327 return (!empty($fields) ? $fields : null);
328 }
329
336 protected static function addResultInternal(array $fields)
337 {
338 return Internals\OrderRulesTable::add($fields);
339 }
340
347 protected static function addResultDescriptionInternal(array $fields)
348 {
349 return Internals\OrderRulesDescrTable::add($fields);
350 }
351
359 protected static function updateResultInternal($id, array $fields)
360 {
361 return Internals\OrderRulesTable::update($id, $fields);
362 }
363
371 protected static function updateResultDescriptionInternal($id, array $fields)
372 {
373 return Internals\OrderRulesDescrTable::update($id, $fields);
374 }
375
376 /* discount results end */
377
378 /* round result */
379
386 protected static function getRoundEntityInternal($entity)
387 {
388 $result = null;
389
391 $discountClassName = static::getDiscountClassName();
392
393 switch ($entity)
394 {
395 case $discountClassName::ENTITY_BASKET_ITEM:
396 $result = Internals\OrderRoundTable::ENTITY_TYPE_BASKET_ITEM;
397 break;
398 }
399
400 unset($discountClassName);
401
402 return $result;
403 }
404
411 protected static function getRoundEntityFromInternal($entity)
412 {
413 $result = null;
414
416 $discountClassName = static::getDiscountClassName();
417
418 switch ($entity)
419 {
420 case Internals\OrderRoundTable::ENTITY_TYPE_BASKET_ITEM:
421 $result = $discountClassName::ENTITY_BASKET_ITEM;
422 break;
423 }
424
425 unset($discountClassName);
426
427 return $result;
428 }
429
434 protected static function getRoundResultIterator(array $parameters)
435 {
436 if (empty($parameters['select']))
437 $parameters['select'] = ['*'];
438 return Internals\OrderRoundTable::getList($parameters);
439 }
440
447 protected static function addRoundResultInternal(array $fields)
448 {
449 return Internals\OrderRoundTable::add($fields);
450 }
451
459 protected static function updateRoundResultInternal($id, array $fields)
460 {
461 return Internals\OrderRoundTable::update($id, $fields);
462 }
463
469 protected static function getRoundTableNameInternal()
470 {
471 return Internals\OrderRoundTable::getTableName();
472 }
473
474 /* round result end */
475
476 /* data storage */
477
484 protected static function getStorageTypeInternal($storageType)
485 {
486 $result = null;
487
488 switch ($storageType)
489 {
491 $result = Internals\OrderDiscountDataTable::ENTITY_TYPE_DISCOUNT_STORED_DATA;
492 break;
494 $result = Internals\OrderDiscountDataTable::ENTITY_TYPE_ORDER;
495 break;
497 $result = Internals\OrderDiscountDataTable::ENTITY_TYPE_ROUND;
498 break;
500 $result = Internals\OrderDiscountDataTable::ENTITY_TYPE_BASKET_ITEM;
501 }
502
503 return $result;
504 }
505
510 protected static function getStoredDataIterator(array $parameters)
511 {
512 return Internals\OrderDiscountDataTable::getList($parameters);
513 }
514
521 protected static function addStoredDataInternal(array $fields)
522 {
523 return Internals\OrderDiscountDataTable::add($fields);
524 }
525
533 protected static function updateStoredDataInternal($id, array $fields)
534 {
535 return Internals\OrderDiscountDataTable::update($id, $fields);
536 }
537
543 protected static function getStoredDataTableInternal()
544 {
545 return Internals\OrderDiscountDataTable::getTableName();
546 }
547
548 /* data storage end */
549}
static loadMessages($file)
Definition loc.php:64
static addRoundResultInternal(array $fields)
static getOrderDiscountIterator(array $parameters)
static getResultIterator(array $parameters)
static getRoundResultIterator(array $parameters)
static addResultInternal(array $fields)
static getOrderDiscountModuleIterator(array $parameters)
static updateResultInternal($id, array $fields)
static addResultDescriptionInternal(array $fields)
static getResultDescriptionTableNameInternal()
static getDiscountIterator(array $parameters)
static addStoredDataInternal(array $fields)
static addOrderDiscountInternal(array $fields)
static checkResultTableWhiteList(array $fields)
static getOrderCouponIterator(array $parameters)
static checkRequiredOrderDiscountFields(array $fields)
static isValidCouponTypeInternal($type)
static updateResultDescriptionInternal($id, array $fields)
static calculateOrderDiscountHashInternal(array $fields)
static updateStoredDataInternal($id, array $fields)
static updateRoundResultInternal($id, array $fields)
static getStorageTypeInternal($storageType)
static checkResultDescriptionTableWhiteList(array $fields)
static validateCoupon(array $fields)
static getResultDescriptionIterator(array $parameters)
static saveOrderDiscountModulesInternal($orderDiscountId, array $modules)
static addOrderCouponInternal(array $fields)
static getStoredDataIterator(array $parameters)
static normalizeOrderDiscountFieldsInternal(array $rawFields)