Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
orderdiscountmanager.php
1<?php
2namespace Bitrix\Sale;
3
6
7Loc::loadMessages(__FILE__);
8
17{
19 const DESCR_TYPE_SIMPLE = Discount\Formatter::TYPE_SIMPLE;
21 const DESCR_TYPE_VALUE = Discount\Formatter::TYPE_VALUE;
23 const DESCR_TYPE_LIMIT_VALUE = Discount\Formatter::TYPE_LIMIT_VALUE;
25 const DESCR_TYPE_FIXED = Discount\Formatter::TYPE_FIXED;
27 const DESCR_TYPE_MAX_BOUND = Discount\Formatter::TYPE_MAX_BOUND;
28
30 const DESCR_VALUE_TYPE_PERCENT = Discount\Formatter::VALUE_TYPE_PERCENT;
32 const DESCR_VALUE_TYPE_CURRENCY = Discount\Formatter::VALUE_TYPE_CURRENCY;
34 const DESCR_VALUE_TYPE_SUMM = Discount\Formatter::VALUE_TYPE_SUMM;
36 const DESCR_VALUE_TYPE_SUMM_BASKET = Discount\Formatter::VALUE_TYPE_SUMM_BASKET;
37
39 const DESCR_VALUE_ACTION_DISCOUNT = Discount\Formatter::VALUE_ACTION_DISCOUNT;
41 const DESCR_VALUE_ACTION_EXTRA = Discount\Formatter::VALUE_ACTION_EXTRA;
43 const DESCR_VALUE_ACTION_ACCUMULATE = Discount\Formatter::VALUE_ACTION_CUMULATIVE;
45 const DESCR_VALUE_ACTION_CUMULATIVE = Discount\Formatter::VALUE_ACTION_CUMULATIVE;
46
48 const DESCR_LIMIT_MAX = Discount\Formatter::LIMIT_MAX;
50 const DESCR_LIMIT_MIN = Discount\Formatter::LIMIT_MIN;
51
63 public static function loadResultFromDatabase($order, $extendedMode = false, $basketList = false, $basketData = array())
64 {
65 if (!is_array($basketList))
66 $basketList = [];
67 if (!is_array($basketData))
68 $basketData = [];
69 $result = parent::loadResultFromDb($order, $basketList, $basketData);
70
71 /* for compatibility only */
72 $data = $result->getData();
73
74 $data['BASKET'] = [];
75 $data['ORDER'] = [];
76 $data['DISCOUNT_MODULES'] = [];
77 $data['DATA'] = [];
78 if (isset($data['APPLY_BLOCKS'][0]))
79 {
80 $data['BASKET'] = $data['APPLY_BLOCKS'][0]['BASKET'];
81 $data['ORDER'] = $data['APPLY_BLOCKS'][0]['ORDER'];
82 }
83 if (!empty($data['DISCOUNT_LIST']))
84 {
85 foreach (array_keys($data['DISCOUNT_LIST']) as $index)
86 {
87 if (empty($data['DISCOUNT_LIST'][$index]['MODULES']))
88 continue;
89 $data['DISCOUNT_MODULES'][$index] = $data['DISCOUNT_LIST'][$index]['MODULES'];
90 }
91 unset($index);
92 }
93 $data['DATA']['STORED_ACTION_DATA'] = $data['STORED_ACTION_DATA'];
94 unset($data['STORED_ACTION_DATA']);
95
96 $result->setData($data);
97
98 return $result;
99 }
100
111 public static function prepareDiscountDescription($type, $data)
112 {
113 $result = new Result();
114
115 $config = static::getManagerConfig();
116
117 $type = (int)$type;
118 switch ($type)
119 {
120 case Discount\Formatter::TYPE_LIMIT_VALUE:
121 if (!is_array($data))
122 $data = array();
123 if (!isset($data['LIMIT_UNIT']) && isset($config['CURRENCY']))
124 $data['LIMIT_UNIT'] = $config['CURRENCY'];
125 if (!isset($data['VALUE_UNIT']) && isset($config['CURRENCY']))
126 $data['VALUE_UNIT'] = $config['CURRENCY'];
127 break;
128 case Discount\Formatter::TYPE_VALUE:
129 case Discount\Formatter::TYPE_FIXED:
130 case Discount\Formatter::TYPE_MAX_BOUND:
131 if (!is_array($data))
132 $data = array();
133 if (!isset($data['VALUE_UNIT']) && isset($config['CURRENCY']))
134 $data['VALUE_UNIT'] = $config['CURRENCY'];
135 break;
136 }
137
138 $description = Discount\Formatter::prepareRow($type, $data);
139 if ($description !== null)
140 {
141 $result->setData($description);
142 }
143 else
144 {
145 self::transferFormatterErrors($result);
146 }
147
148 return $result;
149 }
150
160 public static function formatDiscountDescription($data)
161 {
162 $result = new Result();
163
164 if (!is_array($data))
165 $data = array();
166
167 $description = Discount\Formatter::formatRow($data);
168 if ($description !== null)
169 {
170 $result->setData(array('DESCRIPTION' => $description));
171 }
172 else
173 {
174 self::transferFormatterErrors($result);
175 }
176
177 return $result;
178 }
179
189 public static function formatDescription($data)
190 {
191 $result = false;
192 if (!is_array($data))
193 $data = array();
194 $description = Discount\Formatter::formatRow($data);
195 if ($description !== null)
196 $result = $description;
197
198 return $result;
199 }
200
210 public static function formatArrayDescription($data)
211 {
212 $result = array();
213 if (!empty($data) && is_array($data))
214 {
215 $description = Discount\Formatter::formatList($data);
216 if ($description !== null)
217 $result = $description;
218 }
219
220 return (empty($result) ? false: $result);
221 }
222
234 public static function createSimpleDescription($newPrice, $oldPrice, $currency)
235 {
236 return Discount\Result\CompatibleFormat::createResultDescription($newPrice, $oldPrice, $currency);
237 }
238
248 protected static function getBasketCodeByRule(array $rule, $translate, $basketList)
249 {
250 $translate = ($translate === true);
251 $index = '';
252 if ($translate)
253 {
254 if (is_array($basketList) && isset($basketList[$rule['ENTITY_ID']]))
255 $index = $basketList[$rule['ENTITY_ID']];
256 }
257 else
258 {
259 $index = $rule['ENTITY_ID'];
260 }
261 return $index;
262 }
263
270 private static function transferFormatterErrors(Result $result)
271 {
272 $errors = Discount\Formatter::getErrors();
273 Discount\Formatter::clearErrors();
274 $result->addWarning(new Main\Error(
275 implode('. ', $errors),
276 self::ERROR_ID
277 ));
278 }
279}
static loadMessages($file)
Definition loc.php:64
static createSimpleDescription($newPrice, $oldPrice, $currency)
static prepareDiscountDescription($type, $data)
static loadResultFromDatabase($order, $extendedMode=false, $basketList=false, $basketData=array())
static getBasketCodeByRule(array $rule, $translate, $basketList)