Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
byprice.php
1<?php
3
4use \Bitrix\Main\Localization\Loc;
10
11Loc::loadMessages(__FILE__);
12
18class ByPrice extends Base
19{
20 public static function getClassTitle()
21 {
22 return Loc::getMessage("SALE_DLVR_RSTR_BY_PRICE_NAME");
23 }
24
25 public static function getClassDescription()
26 {
27 return Loc::getMessage("SALE_DLVR_RSTR_BY_PRICE_DESCRIPT");
28 }
29
30 public static function check($price, array $restrictionParams, $deliveryId = 0)
31 {
32 if(empty($restrictionParams))
33 return true;
34
35 if($price < 0)
36 return true;
37
38 $price = floatval($price);
39
40 if(floatval($restrictionParams["MIN_PRICE"]) > 0 && $price < floatval($restrictionParams["MIN_PRICE"]))
41 $result = false;
42 elseif(floatval($restrictionParams["MAX_PRICE"]) > 0 && $price > floatval($restrictionParams["MAX_PRICE"]))
43 $result = false;
44 else
45 $result = true;
46
47 return $result;
48 }
49
50
51 public static function checkByEntity(Entity $shipment, array $restrictionParams, $mode, $deliveryId = 0)
52 {
53 $severity = self::getSeverity($mode);
54
57
58 $price = self::extractParams($shipment);
59 $sCurrency = $shipment->getCurrency();
60
61 if (!empty($sCurrency) && !empty($restrictionParams["CURRENCY"]) && \Bitrix\Main\Loader::includeModule('currency'))
62 {
63 $price = \CCurrencyRates::convertCurrency(
64 $price,
65 $sCurrency,
66 $restrictionParams["CURRENCY"]
67 );
68 }
69
70 $res = self::check($price, $restrictionParams, $deliveryId);
71 return $res ? RestrictionManager::SEVERITY_NONE : $severity;
72 }
73
74 protected static function extractParams(Entity $entity)
75 {
76 if ($entity instanceof Shipment)
77 {
78 if(!$itemCollection = $entity->getShipmentItemCollection())
79 return -1;
80 }
81 else
82 {
83 return -1;
84 }
85
86 return $itemCollection->getPrice();
87 }
88
89 public static function getParamsStructure($entityId = 0)
90 {
91 return array(
92 "MIN_PRICE" => array(
93 "TYPE" => "NUMBER",
94 "DEFAULT" => "0",
95 'MIN' => 0,
96 "LABEL" => Loc::getMessage("SALE_DLVR_RSTR_BY_PRICE_MIN_PRICE")
97 ),
98
99 "MAX_PRICE" => array(
100 "TYPE" => "NUMBER",
101 "DEFAULT" => "0",
102 'MIN' => 0,
103 "LABEL" => Loc::getMessage("SALE_DLVR_RSTR_BY_PRICE_MAX_PRICE")
104 ),
105
106 "CURRENCY" => array(
107 "TYPE" => "ENUM",
108 "DEFAULT" => "RUB",
109 "LABEL" => Loc::getMessage("SALE_DLVR_RSTR_BY_PRICE_CURRECY"),
111 )
112 );
113 }
114}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static extractParams(Entity $entity)
Definition byprice.php:74
static check($price, array $restrictionParams, $deliveryId=0)
Definition byprice.php:30
static checkByEntity(Entity $shipment, array $restrictionParams, $mode, $deliveryId=0)
Definition byprice.php:51