Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
price.php
1<?php
2
4
12
13Loc::loadMessages(__FILE__);
14
15class Price extends Base\Restriction
16{
23 public static function check($params, array $restrictionParams, $serviceId = 0)
24 {
25 $maxValue = static::getPrice($params, $restrictionParams['MAX_VALUE']);
26 $minValue = static::getPrice($params, $restrictionParams['MIN_VALUE']);
27 $price = (float)$params['PRICE_PAYMENT'];
28
29 if ($maxValue > 0 && $minValue > 0)
30 {
31 return ($maxValue >= $price) && ($minValue <= $price);
32 }
33
34 if ($maxValue > 0)
35 {
36 return $maxValue >= $price;
37 }
38
39 if ($minValue >= 0)
40 {
41 return $minValue <= $price;
42 }
43
44 return false;
45 }
46
51 protected static function extractParams(Entity $entity)
52 {
53 $orderPrice = null;
54 $paymentPrice = null;
55
56 if ($entity instanceof Payment)
57 {
59 $collection = $entity->getCollection();
61 $order = $collection->getOrder();
62
63 $orderPrice = $order->getPrice();
64 $paymentPrice = $entity->getField('SUM');
65 }
66
67 return array(
68 'PRICE_PAYMENT' => $paymentPrice,
69 'PRICE_ORDER' => $orderPrice,
70 );
71 }
72
78 protected static function getPrice($entityParams, $paramValue)
79 {
80 return (float)$paramValue;
81 }
82
86 public static function getClassTitle()
87 {
88 return Loc::getMessage('SALE_PS_RESTRICTIONS_BY_PRICE');
89 }
90
94 public static function getClassDescription()
95 {
96 return Loc::getMessage('SALE_PS_RESTRICTIONS_BY_PRICE_DESC');
97 }
98
99 public static function getOnApplyErrorMessage(): string
100 {
101 return Loc::getMessage('SALE_PS_RESTRICTIONS_BY_PRICE_ON_APPLY_ERROR_MSG');
102 }
103
109 public static function getParamsStructure($entityId = 0)
110 {
111 return array(
112 "MIN_VALUE" => array(
113 'TYPE' => 'NUMBER',
114 'DEFAULT' => 0,
115 'LABEL' => Loc::getMessage("SALE_PS_RESTRICTIONS_BY_PRICE_TYPE_MORE")
116 ),
117 "MAX_VALUE" => array(
118 'TYPE' => 'NUMBER',
119 'DEFAULT' => 0,
120 'LABEL' => Loc::getMessage("SALE_PS_RESTRICTIONS_BY_PRICE_TYPE_LESS")
121 )
122 );
123 }
124
131 public static function getRange(Payment $payment, $params)
132 {
133 if ($payment instanceof Payment)
134 {
135 $p = static::extractParams($payment);
136 return array(
137 'MAX' => static::getPrice($p, $params['MAX_VALUE']),
138 'MIN' => static::getPrice($p, $params['MIN_VALUE']),
139 );
140 }
141
142 throw new ArgumentTypeException('');
143 }
144
149 public static function getSeverity($mode)
150 {
151 return Manager::SEVERITY_SOFT;
152 }
153}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static check($params, array $restrictionParams, $serviceId=0)
Definition price.php:23
static getPrice($entityParams, $paramValue)
Definition price.php:78
static getRange(Payment $payment, $params)
Definition price.php:131