Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
configurable.php
1<?php
2
4
10
11Loc::loadMessages(__FILE__);
12
19class Configurable extends Base
20{
22 protected $handlerCode = 'BITRIX_CONFIGURABLE';
23
24 protected static $isCalculatePriceImmediately = true;
25 protected static $whetherAdminExtraServicesShow = true;
26
32 public function __construct(array $initParams)
33 {
34 parent::__construct($initParams);
35
36 if(!isset($this->config["MAIN"]["PRICE"]))
37 $this->config["MAIN"]["PRICE"] = "0";
38
39 if(!isset($initParams["CURRENCY"]))
40 $initParams["CURRENCY"] = "RUB";
41
42 if(!isset($this->config["MAIN"]["PERIOD"]) || !is_array($this->config["MAIN"]["PERIOD"]))
43 {
44 $this->config["MAIN"]["PERIOD"] = array();
45 $this->config["MAIN"]["PERIOD"]["FROM"] = "0";
46 $this->config["MAIN"]["PERIOD"]["TO"] = "0";
47 $this->config["MAIN"]["PERIOD"]["TYPE"] = "D";
48 }
49 }
50
54 public static function getClassTitle()
55 {
56 return Loc::getMessage("SALE_DLVR_HANDL_NAME");
57 }
58
62 public static function getClassDescription()
63 {
64 return Loc::getMessage("SALE_DLVR_HANDL_DESCRIPTION");
65 }
66
70 protected function getPeriodText()
71 {
72 $result = "";
73
74 if (intval($this->config["MAIN"]["PERIOD"]["FROM"]) > 0 || intval($this->config["MAIN"]["PERIOD"]["TO"]) > 0)
75 {
76 $result = "";
77
78 if(intval($this->config["MAIN"]["PERIOD"]["FROM"]) > 0)
79 $result .= " ".Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_FROM")." ".intval($this->config["MAIN"]["PERIOD"]["FROM"]);
80
81 if(intval($this->config["MAIN"]["PERIOD"]["TO"]) > 0)
82 $result .= " ".Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_TO")." ".intval($this->config["MAIN"]["PERIOD"]["TO"]);
83
84 if($this->config["MAIN"]["PERIOD"]["TYPE"] == "MIN")
85 $result .= " ".Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_MIN")." ";
86 elseif($this->config["MAIN"]["PERIOD"]["TYPE"] == "H")
87 $result .= " ".Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_HOUR")." ";
88 elseif($this->config["MAIN"]["PERIOD"]["TYPE"] == "M")
89 $result .= " ".Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_MONTH")." ";
90 else
91 $result .= " ".Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_DAY")." ";
92 }
93
94 return $result;
95 }
96
97 protected function calculateConcrete(\Bitrix\Sale\Shipment $shipment = null)
98 {
99 $result = new CalculationResult;
100 $price = $this->config["MAIN"]["PRICE"];
101
102 if($shipment && \Bitrix\Main\Loader::includeModule('currency'))
103 {
104 $rates = new \CCurrencyRates;
105 $currency = $this->currency;
106 $shipmentCurrency = $shipment->getCollection()->getOrder()->getCurrency();
107 $price = $rates->convertCurrency( $price, $currency, $shipmentCurrency);
108 }
109
110 $result->setDeliveryPrice(
111 roundEx(
112 $price,
113 SALE_VALUE_PRECISION
114 )
115 );
116
117 $result->setPeriodDescription($this->getPeriodText());
118 $result->setPeriodFrom($this->config["MAIN"]["PERIOD"]["FROM"]);
119 $result->setPeriodTo($this->config["MAIN"]["PERIOD"]["TO"]);
120 $result->setPeriodType($this->config["MAIN"]["PERIOD"]["TYPE"]);
121
122 return $result;
123 }
124
129 protected function getConfigStructure()
130 {
131 $currency = $this->currency;
132
133 if(Loader::includeModule('currency'))
134 {
135 $currencyList = Currency\CurrencyManager::getCurrencyList();
136 if (isset($currencyList[$this->currency]))
137 $currency = $currencyList[$this->currency];
138 unset($currencyList);
139 }
140
141 return array(
142
143 "MAIN" => array(
144 "TITLE" => Loc::getMessage("SALE_DLVR_HANDL_CONF_TITLE"),
145 "DESCRIPTION" => Loc::getMessage("SALE_DLVR_HANDL_CONF_DESCRIPTION"),
146 "ITEMS" => array(
147
148 "CURRENCY" => array(
149 "TYPE" => "DELIVERY_READ_ONLY",
150 "NAME" => Loc::getMessage("SALE_DLVR_HANDL_CONF_CURRENCY"),
151 "VALUE" => $this->currency,
152 "VALUE_VIEW" => htmlspecialcharsbx($currency)
153 ),
154
155 "PRICE" => array(
156 "TYPE" => "NUMBER",
157 "MIN" => 0,
158 "NAME" => Loc::getMessage("SALE_DLVR_HANDL_CONF_PRICE")
159 ),
160
161 "PERIOD" => array(
162 "TYPE" => "DELIVERY_PERIOD",
163 "NAME" => Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_DLV"),
164 "ITEMS" => array(
165 "FROM" => array(
166 "TYPE" => "NUMBER",
167 "MIN" => 0,
168 "NAME" => "" //Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_FROM"),
169 ),
170 "TO" => array(
171 "TYPE" => "NUMBER",
172 "MIN" => 0,
173 "NAME" => "&nbsp;-&nbsp;" //Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_TO"),
174 ),
175 "TYPE" => array(
176 "TYPE" => "ENUM",
177 "OPTIONS" => array(
178 "MIN" => Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_MIN"),
179 "H" => Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_HOUR"),
180 "D" => Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_DAY"),
181 "M" => Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_MONTH")
182 )
183 )
184 )
185 )
186 )
187 )
188 );
189 }
190
191 public static function getAdminFieldsList()
192 {
193 $result = parent::getAdminFieldsList();
194 $result["STORES"] = true;
195 return $result;
196 }
197
198 public function prepareFieldsForSaving(array $fields)
199 {
200 if((!isset($fields["CODE"]) || intval($fields["CODE"]) < 0) && isset($fields["ID"]) && intval($fields["ID"]) > 0)
201 $fields["CODE"] = $fields["ID"];
202
203 return parent::prepareFieldsForSaving($fields);
204 }
205
206 public static function onAfterAdd($serviceId, array $fields = array())
207 {
208 if($serviceId <= 0)
209 return false;
210
211 $res = Manager::update($serviceId, array('CODE' => $serviceId));
212 return $res->isSuccess();
213 }
214
216 {
218 }
219
220 public static function whetherAdminExtraServicesShow()
221 {
223 }
224
225 public static function isHandlerCompatible()
226 {
227 return true;
228 }
229}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
calculateConcrete(\Bitrix\Sale\Shipment $shipment=null)
static onAfterAdd($serviceId, array $fields=array())
static update($id, array $fields)
Definition manager.php:817