1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
delivery_ua_post.php
См. документацию.
1<?
2/********************************************************************************
3Delivery services for Ukrainian «Nova poshta»
4http://novaposhta.ua
5Tarif: http://novaposhta.ua/docs/internet_magaziny.pdf
6Order's weight must be less or equal 100 Kg.
7********************************************************************************/
9
10IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"].'/bitrix/modules/sale/delivery/delivery_ua_post.php');
11
13{
14 private static $MAX_WEIGHT = 100000; // (g)
15
16 private static $defaultTarifs = array(
17 "BO" => 13, // Price for ordering UAH
18 "T1" => 1.65, // WARE-WARE Price for 1 kg
19 "WARE_DOOR" => array( // upper bound of weight gramm => price)
20 2000 => 20,
21 10000 => 25,
22 100000 => 40
23 ),
24
25 "DOOR_DOOR" => array( //upper bound of weight gramm => price
26 2000 => 55,
27 5000 => 65,
28 10000 => 75,
29 20000 => 95,
30 30000 => 115,
31 50000 => 140,
32 75000 => 170,
33 100000 => 205
34 ),
35 "OB_COMISS" => 0.5, // declared-value comission %
36 "OB_COMISS_MIN" => 3 // min declared value comission UAH
37 );
38
39 public static function Init()
40 {
41 return array(
42 /* Basic description */
43 'SID' => 'ua_post',
44 'NAME' => GetMessage('SALE_DH_UP_NAME'),
45 'DESCRIPTION' => GetMessage('SALE_DH_UP_DESCR1').' <a href="http://novaposhta.ua">http://novaposhta.ua</a>. '.GetMessage('SALE_DH_UP_DESCR2'),
46 'DESCRIPTION_INNER' => GetMessage('SALE_DH_UP_DESCR1').' <a href="http://novaposhta.ua">http://novaposhta.ua</a>. '.GetMessage('SALE_DH_UP_DESCR2'),
47 'BASE_CURRENCY' => 'UAH',
48 'HANDLER' => __FILE__,
49 /* Handler methods */
50 'DBGETSETTINGS' => array('CDeliveryUaPost', 'GetSettings'),
51 'DBSETSETTINGS' => array('CDeliveryUaPost', 'SetSettings'),
52 'GETCONFIG' => array('CDeliveryUaPost', 'GetConfig'),
53 'GETFEATURES' => array('CDeliveryUaPost', 'GetFeatures'),
54 'COMPABILITY' => array('CDeliveryUaPost', 'Compability'),
55 'CALCULATOR' => array('CDeliveryUaPost', 'Calculate'),
56
57 /* List of delivery profiles */
58 'PROFILES' => array(
59 'ware' => array(
60 'TITLE' => GetMessage('SALE_DH_UP_WARE_TITLE'),
61 'DESCRIPTION' => GetMessage('SALE_DH_UP_WARE_DESCR'),
62 'RESTRICTIONS_WEIGHT' => array(0, self::$MAX_WEIGHT),
63 'RESTRICTIONS_SUM' => array(0),
64 'TAX_RATE' => 0,
65 'RESTRICTIONS_MAX_SIZE' => 0,
66 'RESTRICTIONS_DIMENSIONS_SUM' => 0,
67 'RESTRICTIONS_DIMENSIONS' => 0
68 ),
69 'door' => array(
70 'TITLE' => GetMessage('SALE_DH_UP_DOOR_TITLE'),
71 'DESCRIPTION' => GetMessage('SALE_DH_UP_DOOR_DESCR'),
72 'RESTRICTIONS_WEIGHT' => array(0, self::$MAX_WEIGHT),
73 'RESTRICTIONS_SUM' => array(0),
74 'TAX_RATE' => 0,
75 'RESTRICTIONS_MAX_SIZE' => 0,
76 'RESTRICTIONS_DIMENSIONS_SUM' => 0,
77 'RESTRICTIONS_DIMENSIONS' => 0
78 )
79 )
80 );
81 }
82
83 public static function GetConfig()
84 {
85 $arConfig = array(
86 'CONFIG_GROUPS' => array(
87 'common' => GetMessage('SALE_DH_UP_GROUPS_COMMON'),
88 'ware' => GetMessage('SALE_DH_UP_GROUPS_WARE'),
89 'door' => GetMessage('SALE_DH_UP_GROUPS_DOOR')
90 ),
91 );
92
93 //common
94 $arConfig['CONFIG']['DELIVERY_TO_POST'] = array(
95 'TYPE' => 'RADIO',
96 'DEFAULT' => 'ware',
97 'TITLE' => GetMessage('SALE_DH_UP_DTP'),
98 'VALUES' => array(
99 'ware' => GetMessage('SALE_DH_UP_DTP_WARE'),
100 'door' => GetMessage('SALE_DH_UP_DTP_DOOR')
101 ),
102 'GROUP' => 'common',
103 );
104
105 $arConfig['CONFIG']['tarif_section_1'] = array(
106 'TYPE' => 'SECTION',
107 'TITLE' => GetMessage('SALE_DH_UP_TARIF_WW'),
108 'GROUP' => 'common',
109 );
110
111
112 $arConfig['CONFIG']['TARIF_BO'] = array(
113 'TYPE' => 'STRING',
114 'DEFAULT' => self::$defaultTarifs['BO'],
115 'TITLE' => GetMessage('SALE_DH_UP_TARIF_REG'),
116 'GROUP' => 'common',
117 'CHECK_FORMAT' => 'NUMBER'
118 );
119
120 $arConfig['CONFIG']['TARIF_T1'] = array(
121 'TYPE' => 'STRING',
122 'DEFAULT' => self::$defaultTarifs['T1'],
123 'TITLE' => GetMessage('SALE_DH_UP_TARIF_T1'),
124 'GROUP' => 'common',
125 'CHECK_FORMAT' => 'NUMBER'
126 );
127
128 $arConfig['CONFIG']['tarif_section_2'] = array(
129 'TYPE' => 'SECTION',
130 'TITLE' => GetMessage('SALE_DH_UP_TARIF_WD'),
131 'GROUP' => 'common',
132 );
133
134 $prevWeight = 0;
135 foreach (self::$defaultTarifs["WARE_DOOR"] as $uperWeight => $price)
136 {
137 $arConfig['CONFIG']['TARIF_WARE_DOOR_'.$uperWeight] = array(
138 'TYPE' => 'STRING',
139 'DEFAULT' => $price,
140 'TITLE' => ($prevWeight/1000).' - '.($uperWeight/1000).' '.GetMessage('SALE_DH_UP_KG').'.',
141 'GROUP' => 'common',
142 'CHECK_FORMAT' => 'NUMBER'
143 );
144
145 $prevWeight = $uperWeight;
146 }
147
148 $arConfig['CONFIG']['tarif_section_3'] = array(
149 'TYPE' => 'SECTION',
150 'TITLE' => GetMessage('SALE_DH_UP_TARIF_DD'),
151 'GROUP' => 'common',
152 );
153
154 $prevWeight = 0;
155 foreach (self::$defaultTarifs["DOOR_DOOR"] as $uperWeight => $price)
156 {
157 $arConfig['CONFIG']['TARIF_DOOR_DOOR_'.$uperWeight] = array(
158 'TYPE' => 'STRING',
159 'DEFAULT' => $price,
160 'TITLE' => ($prevWeight/1000).' - '.($uperWeight/1000).' '.GetMessage('SALE_DH_UP_KG').'.',
161 'GROUP' => 'common',
162 'CHECK_FORMAT' => 'NUMBER'
163 );
164
165 $prevWeight = $uperWeight;
166 }
167
168 $arConfig['CONFIG']['tarif_section_4'] = array(
169 'TYPE' => 'SECTION',
170 'TITLE' => GetMessage('SALE_DH_UP_TARIF_DV'),
171 'GROUP' => 'common',
172 );
173
174 $arConfig['CONFIG']['OB_COMISS'] = array(
175 'TYPE' => 'STRING',
176 'DEFAULT' => self::$defaultTarifs["OB_COMISS"],
177 'TITLE' => GetMessage('SALE_DH_UP_TARIF_DV_VALUE').' %',
178 'GROUP' => 'common',
179 'CHECK_FORMAT' => 'NUMBER'
180 );
181
182
183 $arConfig['CONFIG']['OB_COMISS_MIN'] = array(
184 'TYPE' => 'STRING',
185 'DEFAULT' => self::$defaultTarifs["OB_COMISS_MIN"],
186 'TITLE' => GetMessage('SALE_DH_UP_TARIF_DV_MIN'),
187 'GROUP' => 'common',
188 'CHECK_FORMAT' => 'NUMBER'
189 );
190
191 //ware
192 $aviableBoxes = self::getAviableBoxes();
193
194 foreach ($aviableBoxes as $boxId => $arBox)
195 CSaleDeliveryHelper::makeBoxConfig($boxId, $arBox, 'ware', $arConfig);
196
197 //door
198 foreach ($aviableBoxes as $boxId => $arBox)
199 CSaleDeliveryHelper::makeBoxConfig($boxId, $arBox, 'door', $arConfig);
200
201 return $arConfig;
202 }
203
204 public static function GetSettings($strSettings)
205 {
206 return unserialize($strSettings, ['allowed_classes' => false]);
207 }
208
209 public static function SetSettings($arSettings)
210 {
211 foreach ($arSettings as $key => $value)
212 {
213 if ($value <> '')
214 $arSettings[$key] = $value;
215 else
216 unset($arSettings[$key]);
217 }
218
219 return serialize($arSettings);
220 }
221
222 public static function GetFeatures($arConfig)
223 {
224 $arResult = array();
225
226 if ($arConfig["DELIVERY_TO_POST"]["VALUE"] == "ware")
227 $arResult[GetMessage("SALE_DH_UP_SHIPPING_HANDLING")] = GetMessage("SALE_DH_UP_DTP_WARE");
228 else
229 $arResult[GetMessage("SALE_DH_UP_SHIPPING_HANDLING")] = GetMessage("SALE_DH_UP_DTP_DOOR");
230
231 if ($arConfig["OB_COMISS"]["VALUE"] != 0 && $arConfig["OB_COMISS_MIN"]["VALUE"] != 0)
232 $arResult[GetMessage("SALE_DH_UP_FEATURE_VALUE")] = GetMessage("SALE_DH_UP_FEATURE_ENABLED");
233
234 return $arResult;
235 }
236
237 public static function Calculate($profile, $arConfig, $arOrder, $STEP, $TEMP = false)
238 {
239 $arPacks = CSaleDeliveryHelper::getBoxesFromConfig($profile, $arConfig);
240
241 $arPackagesParams = CSaleDeliveryHelper::getRequiredPacks(
242 $arOrder["ITEMS"],
243 $arPacks,
244 self::$MAX_WEIGHT);
245
246 $packageCount = count($arPackagesParams);
247
248 if(intval($packageCount) <= 0)
249 {
250 return array(
251 "RESULT" => "ERROR",
252 "TEXT" => GetMessage("SALE_DH_UP_OVERLOAD"),
253 );
254 }
255
256 $totalPrice = 0;
257
258
259 foreach ($arPackagesParams as $arPackage)
260 {
261 $totalPrice += self::calculatePackPrice($arPackage, $profile, $arConfig);
262 }
263
265 'RESULT' => 'OK',
266 'VALUE' => $totalPrice,
267 'PACKS_COUNT' => $packageCount
268 );
269 return $arResult;
270 }
271
272 public static function Compability($arOrder, $arConfig)
273 {
274 if(floatval($arOrder["WEIGHT"]) <= self::$MAX_WEIGHT)
275 $profiles = array('ware', 'door');
276 else
277 $profiles = array();
278
279 $arRes = array();
280
281 foreach ($profiles as $profile)
282 {
283 $aviableBoxes = CSaleDeliveryHelper::getBoxesFromConfig($profile, $arConfig);
284
285 foreach ($aviableBoxes as $arBox)
286 {
287 if (CSaleDeliveryHandler::checkDimensions($arOrder["MAX_DIMENSIONS"], $arBox["DIMENSIONS"]))
288 {
289 $arRes[] = $profile;
290 break;
291 }
292 }
293 }
294
295 return $arRes;
296 }
297
298 private static function getConfValue(&$arConfig, $key)
299 {
300 return CSaleDeliveryHelper::getConfValue($arConfig[$key]);
301 }
302
303 private static function getAviableBoxes()
304 {
305 return array(
306 array(
307 "NAME" => GetMessage("SALE_DH_UP_STNRD_BOX"),
308 "DIMENSIONS" => array("0", "0", "0")
309 )
310 );
311 }
312
313 private static function calculatePackPrice($arPackage, $profile, $arConfig)
314 {
315 $arDebug = array();
316 $totalPrice = 0;
317
318 $BO = floatval(self::getConfValue($arConfig, 'TARIF_BO'));
319 $arDebug[] = 'BO: '.$BO;
320
321 $T1 = floatval(self::getConfValue($arConfig, 'TARIF_T1'));
322 $arDebug[] = 'T1: '.$T1;
323
324 $weightForCalc =self::getWeightForCalc($arPackage['WEIGHT'], $arPackage['VOLUME']);
325 $arDebug[] = 'calc weight: '.$weightForCalc;
326
327 $CK = floatval(self::getConfValue($arConfig, 'OB_COMISS'))*$arPackage['PRICE']/100; //%
328 $minComiss = floatval(self::getConfValue($arConfig, 'OB_COMISS_MIN'));
329
330 if($CK < $minComiss)
331 $CK = $minComiss;
332
333 $arDebug[] = 'ccomiss: '.$CK;
334
335 $deliveeryToPost = self::getConfValue($arConfig, 'DELIVERY_TO_POST');
336
337 if($profile == 'door' && $deliveeryToPost == 'door') //door-door
338 {
339 foreach (self::$defaultTarifs["DOOR_DOOR"] as $uperWeight => $value)
340 {
341 if($uperWeight > $weightForCalc)
342 {
343 $servicePrice = self::getConfValue($arConfig, 'TARIF_DOOR_DOOR_'.$uperWeight);
344 $arDebug[] = 'Service price: '.$servicePrice;
345 break;
346 }
347 }
348 }
349 else
350 {
351 $servicePrice = $T1*ceil($weightForCalc/1000); //ware-ware
352 $arDebug[] = 'Service price: '.$servicePrice;
353
354 if($profile != $deliveeryToPost) //ware-door or door-ware
355 {
356 foreach (self::$defaultTarifs["WARE_DOOR"] as $uperWeight => $value)
357 {
358 if($uperWeight > $weightForCalc)
359 {
360 $price = self::getConfValue($arConfig, 'TARIF_WARE_DOOR_'.$uperWeight);
361 $arDebug[] = 'ware-door price: '.$price;
362 $servicePrice += $price;
363 $arDebug[] = 'Service price: '.$servicePrice;
364 break;
365 }
366 }
367 }
368 }
369
370 $totalPrice = $servicePrice+$BO+$CK;
371 $arDebug[] = 'Total value: '.$totalPrice;
372
373 return $totalPrice;
374 }
375
376 public static function calcVolumeWeightByVolume($volume)
377 {
378 return $volume/4000000;
379 }
380
381 public static function getWeightForCalc($weight, $volume)
382 {
383 $volWeight = self::calcVolumeWeightByVolume($volume);
384
385 if(floatval($weight) >= floatval($volWeight))
386 $result = $weight;
387 else
388 $result = $volWeight;
389
390 return $result;
391 }
392}
393
394AddEventHandler('sale', 'onSaleDeliveryHandlersBuildList', array('CDeliveryUaPost', 'Init'));
395
396?>
$arResult
Определения generate_coupon.php:16
static checkDimensions($arOrderDimensions, $arRestrictDimensions)
Определения delivery_handler.php:1360
Определения delivery_ua_post.php:13
static getWeightForCalc($weight, $volume)
Определения delivery_ua_post.php:381
static Compability($arOrder, $arConfig)
Определения delivery_ua_post.php:272
static Calculate($profile, $arConfig, $arOrder, $STEP, $TEMP=false)
Определения delivery_ua_post.php:237
static SetSettings($arSettings)
Определения delivery_ua_post.php:209
static GetConfig()
Определения delivery_ua_post.php:83
static GetSettings($strSettings)
Определения delivery_ua_post.php:204
static Init()
Определения delivery_ua_post.php:39
static calcVolumeWeightByVolume($volume)
Определения delivery_ua_post.php:376
static GetFeatures($arConfig)
Определения delivery_ua_post.php:222
static IncludeModule($module_name)
Определения module.php:151
static makeBoxConfig($boxId, $arBox, $group, &$arConfig)
Определения delivery_helper.php:390
static getRequiredPacks(&$arItems, $arPacks, $maxWeight, $reservedSpace=0.15)
Определения delivery_helper.php:204
static getConfValue($arField)
Определения delivery_helper.php:148
static getBoxesFromConfig($profile, &$arConfig)
Определения delivery_helper.php:447
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$STEP
Определения csv_new_setup.php:23
AddEventHandler($FROM_MODULE_ID, $MESSAGE_ID, $CALLBACK, $SORT=100, $FULL_PATH=false)
Определения tools.php:5165
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$arRes
Определения options.php:104