Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
configurable.php
1
<?php
2
3
namespace
Bitrix\Sale\Delivery\Services
;
4
5
use
Bitrix\Main\Loader
;
6
use
Bitrix\Main\SystemException
;
7
use
Bitrix\Main\Localization\Loc
;
8
use
Bitrix\Sale\Delivery\CalculationResult
;
9
use
Bitrix\Currency
;
10
11
Loc::loadMessages
(__FILE__);
12
19
class
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"
=>
" - "
//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
215
public
function
isCalculatePriceImmediately
()
216
{
217
return
self::$isCalculatePriceImmediately
;
218
}
219
220
public
static
function
whetherAdminExtraServicesShow
()
221
{
222
return
self::$whetherAdminExtraServicesShow
;
223
}
224
225
public
static
function
isHandlerCompatible
()
226
{
227
return
true
;
228
}
229
}
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Sale\Delivery\CalculationResult
Definition
calculationresult.php:12
Bitrix\Sale\Delivery\CalculationResult\setDeliveryPrice
setDeliveryPrice($price)
Definition
calculationresult.php:48
Bitrix\Sale\Delivery\ExtraServices\Base
Definition
base.php:10
Bitrix\Sale\Delivery\Services\Configurable
Definition
configurable.php:20
Bitrix\Sale\Delivery\Services\Configurable\getPeriodText
getPeriodText()
Definition
configurable.php:70
Bitrix\Sale\Delivery\Services\Configurable\getClassTitle
static getClassTitle()
Definition
configurable.php:54
Bitrix\Sale\Delivery\Services\Configurable\calculateConcrete
calculateConcrete(\Bitrix\Sale\Shipment $shipment=null)
Definition
configurable.php:97
Bitrix\Sale\Delivery\Services\Configurable\whetherAdminExtraServicesShow
static whetherAdminExtraServicesShow()
Definition
configurable.php:220
Bitrix\Sale\Delivery\Services\Configurable\$isCalculatePriceImmediately
static $isCalculatePriceImmediately
Definition
configurable.php:24
Bitrix\Sale\Delivery\Services\Configurable\getClassDescription
static getClassDescription()
Definition
configurable.php:62
Bitrix\Sale\Delivery\Services\Configurable\getAdminFieldsList
static getAdminFieldsList()
Definition
configurable.php:191
Bitrix\Sale\Delivery\Services\Configurable\__construct
__construct(array $initParams)
Definition
configurable.php:32
Bitrix\Sale\Delivery\Services\Configurable\prepareFieldsForSaving
prepareFieldsForSaving(array $fields)
Definition
configurable.php:198
Bitrix\Sale\Delivery\Services\Configurable\$whetherAdminExtraServicesShow
static $whetherAdminExtraServicesShow
Definition
configurable.php:25
Bitrix\Sale\Delivery\Services\Configurable\getConfigStructure
getConfigStructure()
Definition
configurable.php:129
Bitrix\Sale\Delivery\Services\Configurable\onAfterAdd
static onAfterAdd($serviceId, array $fields=array())
Definition
configurable.php:206
Bitrix\Sale\Delivery\Services\Configurable\isHandlerCompatible
static isHandlerCompatible()
Definition
configurable.php:225
Bitrix\Sale\Delivery\Services\Configurable\$handlerCode
$handlerCode
Definition
configurable.php:22
Bitrix\Sale\Delivery\Services\Configurable\isCalculatePriceImmediately
isCalculatePriceImmediately()
Definition
configurable.php:215
Bitrix\Sale\Delivery\Services\Manager\update
static update($id, array $fields)
Definition
manager.php:817
Bitrix\Sale\Shipment
Definition
shipment.php:21
Bitrix\Currency
Bitrix\Sale\Delivery\Services
Definition
automatic.php:3
Bitrix
Sale
modules
sale
lib
delivery
services
configurable.php
Создано системой
1.10.0