46 if ($type != self::TYPE_SIMPLE)
48 if (empty($data) || !is_array($data))
51 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
56 case self::TYPE_SIMPLE:
57 if (empty($data) || !is_string($data))
60 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
65 'TYPE' => self::TYPE_SIMPLE,
70 case self::TYPE_LIMIT_VALUE:
71 case self::TYPE_VALUE:
72 if ($type == self::TYPE_LIMIT_VALUE)
76 if (!isset($data[
'LIMIT_TYPE']) || !isset($data[
'LIMIT_VALUE']) || !isset($data[
'LIMIT_UNIT']))
79 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
81 elseif ($data[
'LIMIT_TYPE'] != self::LIMIT_MAX && $data[
'LIMIT_TYPE'] != self::LIMIT_MIN)
84 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
89 if ($data[
'VALUE_TYPE'] != self::VALUE_TYPE_PERCENT)
92 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
97 $result[
'LIMIT_TYPE'] = $data[
'LIMIT_TYPE'];
98 $result[
'LIMIT_VALUE'] = $data[
'LIMIT_VALUE'];
99 $result[
'LIMIT_UNIT'] = $data[
'LIMIT_UNIT'];
104 if (!isset($data[
'VALUE']) || !isset($data[
'VALUE_TYPE']))
107 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
113 $data[
'VALUE_TYPE'] != self::VALUE_TYPE_PERCENT
114 && $data[
'VALUE_TYPE'] != self::VALUE_TYPE_CURRENCY
115 && $data[
'VALUE_TYPE'] != self::VALUE_TYPE_SUMM
116 && $data[
'VALUE_TYPE'] != self::VALUE_TYPE_SUMM_BASKET
120 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
123 $data[
'VALUE_TYPE'] == self::VALUE_TYPE_CURRENCY
124 || $data[
'VALUE_TYPE'] == self::VALUE_TYPE_SUMM
125 || $data[
'VALUE_TYPE'] == self::VALUE_TYPE_SUMM_BASKET
128 if (!isset($data[
'VALUE_UNIT']))
131 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
137 if (!isset($data[
'VALUE_ACTION']))
138 $data[
'VALUE_ACTION'] = self::VALUE_ACTION_DISCOUNT;
140 $data[
'VALUE_ACTION'] != self::VALUE_ACTION_DISCOUNT
141 && $data[
'VALUE_ACTION'] != self::VALUE_ACTION_EXTRA
142 && $data[
'VALUE_ACTION'] != self::VALUE_ACTION_CUMULATIVE
146 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
151 $result[
'TYPE'] = $type;
152 $result[
'VALUE'] = $data[
'VALUE'];
153 $result[
'VALUE_TYPE'] = $data[
'VALUE_TYPE'];
154 $result[
'VALUE_ACTION'] = $data[
'VALUE_ACTION'];
157 $data[
'VALUE_TYPE'] == self::VALUE_TYPE_CURRENCY
158 || $data[
'VALUE_TYPE'] == self::VALUE_TYPE_SUMM
159 || $data[
'VALUE_TYPE'] == self::VALUE_TYPE_SUMM_BASKET
161 $result[
'VALUE_UNIT'] = $data[
'VALUE_UNIT'];
162 if (isset($data[
'RESULT_VALUE']) && isset($data[
'RESULT_UNIT']))
164 $result[
'RESULT_VALUE'] = (string)$data[
'RESULT_VALUE'];
165 $result[
'RESULT_UNIT'] = $data[
'RESULT_UNIT'];
169 case self::TYPE_FIXED:
172 if (!isset($data[
'VALUE']) || !isset($data[
'VALUE_UNIT']))
175 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
182 'VALUE' => $data[
'VALUE'],
183 'VALUE_UNIT' => $data[
'VALUE_UNIT']
187 case self::TYPE_MAX_BOUND:
190 if (!isset($data[
'VALUE']) || !isset($data[
'VALUE_UNIT']))
193 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
200 'VALUE' => $data[
'VALUE'],
201 'VALUE_UNIT' => $data[
'VALUE_UNIT']
203 if (isset($data[
'RESULT_VALUE']) && isset($data[
'RESULT_UNIT']))
205 $result[
'RESULT_VALUE'] = (string)$data[
'RESULT_VALUE'];
206 $result[
'RESULT_UNIT'] = $data[
'RESULT_UNIT'];
210 case self::TYPE_SIMPLE_GIFT:
212 'TYPE' => self::TYPE_SIMPLE_GIFT
217 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_DESCR_BAD'));
221 return ($process ? $result :
null);
234 if (!isset($action[
'TYPE']))
236 self::addError(
Loc::getMessage(
'SALE_DISCOUNT_FORMATTER_ERR_FORMAT_TYPE_BAD'));
240 switch ($action[
'TYPE'])
242 case self::TYPE_SIMPLE:
243 $result = $action[
'DESCR'];
245 case self::TYPE_VALUE:
246 if ($action[
'VALUE_TYPE'] == self::VALUE_TYPE_PERCENT)
248 $value = $action[
'VALUE'].
'%';
249 if (isset($action[
'RESULT_VALUE']) && isset($action[
'RESULT_UNIT']))
250 $value .=
' ('.\CCurrencyLang::CurrencyFormat($action[
'RESULT_VALUE'], $action[
'RESULT_UNIT'],
true).
')';
254 if ($action[
'VALUE_TYPE'] == self::VALUE_TYPE_CURRENCY)
256 $value = \CCurrencyLang::CurrencyFormat($action[
'VALUE'], $action[
'VALUE_UNIT'],
true);
261 $action[
'VALUE_TYPE'] == self::VALUE_TYPE_SUMM
262 ?
'SALE_DISCOUNT_FORMATTER_MESS_SUMM_FORMAT'
263 :
'SALE_DISCOUNT_FORMATTER_MESS_SUMM_BASKET_FORMAT'
267 array(
'#VALUE#' => \CCurrencyLang::CurrencyFormat($action[
'VALUE'], $action[
'VALUE_UNIT'],
true))
269 unset($subMessageID);
271 if (isset($action[
'RESULT_VALUE']) && isset($action[
'RESULT_UNIT']) && $action[
'VALUE_UNIT'] != $action[
'RESULT_UNIT'])
272 $value .=
' ('.\CCurrencyLang::CurrencyFormat($action[
'RESULT_VALUE'], $action[
'RESULT_UNIT'],
true).
')';
274 $messageId =
'SALE_DISCOUNT_FORMATTER_MESS_TYPE_DISCOUNT';
275 if (isset($action[
'VALUE_ACTION']))
277 switch ($action[
'VALUE_ACTION'])
279 case self::VALUE_ACTION_EXTRA:
280 $messageId =
'SALE_DISCOUNT_FORMATTER_MESS_TYPE_EXTRA';
282 case self::VALUE_ACTION_CUMULATIVE:
283 $messageId =
'SALE_DISCOUNT_FORMATTER_MESS_TYPE_CUMULATIVE';
288 unset($value, $messageId);
290 case self::TYPE_LIMIT_VALUE:
292 isset($action[
'LIMIT_TYPE']) && $action[
'LIMIT_TYPE'] == self::LIMIT_MIN
293 ?
'SALE_DISCOUNT_FORMATTER_MESS_LIMIT_MIN_FORMAT'
294 :
'SALE_DISCOUNT_FORMATTER_MESS_LIMIT_MAX_FORMAT'
299 '#PERCENT#' => $action[
'VALUE'].
'%',
300 '#LIMIT#' => \CCurrencyLang::CurrencyFormat($action[
'LIMIT_VALUE'], $action[
'LIMIT_UNIT'],
true)
303 if (isset($action[
'RESULT_VALUE']) && isset($action[
'RESULT_UNIT']))
304 $value .=
' ('.\CCurrencyLang::CurrencyFormat($action[
'RESULT_VALUE'], $action[
'RESULT_UNIT'],
true).
')';
306 isset($action[
'VALUE_ACTION']) && $action[
'VALUE_ACTION'] == self::VALUE_ACTION_EXTRA
307 ?
'SALE_DISCOUNT_FORMATTER_MESS_TYPE_EXTRA'
308 :
'SALE_DISCOUNT_FORMATTER_MESS_TYPE_DISCOUNT'
311 unset($value, $messageId);
313 case self::TYPE_FIXED:
315 'SALE_DISCOUNT_FORMATTER_MESS_FIXED_FORMAT',
316 array(
'#VALUE#' => \CCurrencyLang::CurrencyFormat($action[
'VALUE'], $action[
'VALUE_UNIT'],
true))
319 case self::TYPE_MAX_BOUND:
320 $value = \CCurrencyLang::CurrencyFormat($action[
'VALUE'], $action[
'VALUE_UNIT'],
true);
321 if (isset($action[
'RESULT_VALUE']) && isset($action[
'RESULT_UNIT']))
322 $value .=
' ('.\CCurrencyLang::CurrencyFormat($action[
'RESULT_VALUE'], $action[
'RESULT_UNIT'],
true).
')';
324 $value .=
' ('.$value.
')';
326 'SALE_DISCOUNT_FORMATTER_MESS_MAX_BOUND_FORMAT',
327 array(
'#VALUE#' => $value)
331 case self::TYPE_SIMPLE_GIFT: