1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
delivery_rus_post.php
См. документацию.
1<?
2/********************************************************************************
3Delivery services for Russian Post Service (http://www.russianpost.ru/)
4Calculations based on RP rates:
5http://www.russianpost.ru/rp/servise/ru/home/postuslug/bookpostandparcel/local#parcel
6********************************************************************************/
8
9IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"].'/bitrix/modules/sale/delivery/delivery_rus_post.php');
10
11define('DELIVERY_RP_CSV_PATH', $_SERVER['DOCUMENT_ROOT'].BX_ROOT.'/modules/sale/ru/delivery/rus_post'); //where we can found csv files
12
15
17{
18 private static $MAX_WEIGHT_HEAVY = 20000; // (g)
19 private static $MAX_WEIGHT = 10000; // (g)
20 private static $ZONES_COUNT = 5; // Tarif zones count
21 private static $BASE_WEIGHT = 500; // Base weight gram
22
23
24 //1.1 zone_number => tarif_number
25 private static $TARIF_LESS_500 = array(
26 1 => 1,
27 2 => 2,
28 3 => 3,
29 4 => 4,
30 5 => 5
31 );
32
33 private static $TARIF_MORE_500 = array(
34 1 => 6,
35 2 => 7,
36 3 => 8,
37 4 => 9,
38 5 => 10
39 );
40
41 private static $TARIF_HEAVY_WEIGHT = 11; //1.2
42 private static $TARIF_FRAGILE = 14; //1.5
43 private static $TARIF_DECLARED_VAL = 20; //4.
44 private static $TARIF_AVIA_STANDART = 15; //2.1
45 private static $TARIF_AVIA_HEAVY = 16; //2.2
46
47 private static $MAX_DIMENSIONS = array("425", "265", "380");
48
49 const LOCATION_CODE_RUSSIA = "0000028023";
50
51 public static function Init()
52 {
53 return array(
54 /* Basic description */
55 'SID' => 'rus_post',
56 'MULTISITE_CONFIG' => "Y",
57 'NAME' => GetMessage('SALE_DH_RP_NAME'),
58 'DESCRIPTION' => GetMessage('SALE_DH_RP_DESCRIPTION').' <a href="http://www.russianpost.ru">http://www.russianpost.ru</a>',
59 'DESCRIPTION_INNER' => GetMessage('SALE_DH_RP_DESCRIPTION_INNER'),
60 'BASE_CURRENCY' => 'RUB',
61
62 'HANDLER' => __FILE__,
63
64 /* Handler methods */
65 'DBGETSETTINGS' => array('CDeliveryRusPost', 'GetSettings'),
66 'DBSETSETTINGS' => array('CDeliveryRusPost', 'SetSettings'),
67 'GETCONFIG' => array('CDeliveryRusPost', 'GetConfig'),
68 'GETFEATURES' => array('CDeliveryRusPost', 'GetFeatures'),
69
70 'COMPABILITY' => array('CDeliveryRusPost', 'Compability'),
71 'CALCULATOR' => array('CDeliveryRusPost', 'Calculate'),
72 'TRACKING_CLASS_NAME' => '\Bitrix\Sale\Delivery\Tracking\RusPost',
73 'IS_HANDLER_COMPATIBLE' => array('CDeliveryRusPost', 'isHandlerCompatible'),
74
75 /* List of delivery profiles */
76 'PROFILES' => array(
77 'land' => array(
78 'TITLE' => GetMessage('SALE_DH_RP_LAND_TITLE'),
79 'DESCRIPTION' => GetMessage('SALE_H_RP_LAND_DESCRIPTION'),
80 'RESTRICTIONS_WEIGHT' => array(0, self::$MAX_WEIGHT_HEAVY),
81 'RESTRICTIONS_SUM' => array(0),
82 'TAX_RATE' => 0,
83 'RESTRICTIONS_DIMENSIONS' => self::$MAX_DIMENSIONS
84 ),
85
86 'avia' => array(
87 'TITLE' => GetMessage('SALE_DH_RP_AVIA_TITLE'),
88 'DESCRIPTION' => GetMessage('SALE_DH_RP_AVIA_DESCRIPTION'),
89 'RESTRICTIONS_WEIGHT' => array(0, self::$MAX_WEIGHT_HEAVY),
90 'RESTRICTIONS_SUM' => array(0),
91 'TAX_RATE' => 0,
92 'RESTRICTIONS_DIMENSIONS' => self::$MAX_DIMENSIONS
93 )
94 )
95 );
96 }
97
98 public static function GetConfig($siteId = false)
99 {
100 $shopLocationId = CSaleHelper::getShopLocationId($siteId);
101 $arShopLocation = \CSaleHelper::getLocationByIdHitCached($shopLocationId);
102
103 if(!$arShopLocation)
104 $arShopLocation = array();
105
106 if(isset($_REQUEST["RESET_HANDLER_SETTINGS"]) && $_REQUEST["RESET_HANDLER_SETTINGS"] == "Y" && !isset($_REQUEST["apply"]))
107 {
108 Option::delete('sale', array('name' => 'delivery_rus_post_prev_loc', 'site_id' => $siteId));
109 Option::delete('sale', array('name' => 'delivery_rus_post_prev_loc'));
110 }
111
112 if(isset($_REQUEST["RESET_TARIF_SETTINGS"]) && $_REQUEST["RESET_TARIF_SETTINGS"] == "Y" && !isset($_REQUEST["apply"]))
113 {
114 Option::delete('sale', array('name' => 'delivery_rus_post_tarifs', 'site_id' => $siteId));
115 Option::delete('sale', array('name' => 'delivery_rus_post_tarifs'));
116 }
117
118 $shopPrevLocationId = Option::get('sale', 'delivery_rus_post_prev_loc', "", $siteId);
119
120 /* if shop's location was changed */
121 if($shopPrevLocationId == '' || $shopPrevLocationId != $shopLocationId)
122 {
123 Option::set('sale', 'delivery_rus_post_prev_loc', $shopLocationId, $siteId);
124 Option::delete('sale', array('name' => 'delivery_regs_to_zones', 'site_id' => $siteId));
125 Option::delete('sale', array('name' => 'delivery_rus_post_tarifs', 'site_id' => $siteId));
126 }
127
128 $arConfig = array(
129 'CONFIG_GROUPS' => array(
130 'zones' => GetMessage('SALE_DH_RP_CONFIG_GROUP_ZONES'),
131 'tarifs' => GetMessage('SALE_DH_RP_CONFIG_GROUP_TARIFS'),
132 'land' => GetMessage('SALE_DH_RP_CONFIG_GROUP_LAND'),
133 'avia' => GetMessage('SALE_DH_RP_CONFIG_GROUP_AVIA'),
134 )
135 );
136
137 // Zones tab
139 $arZones = array();
140 $arZones[0] = GetMessage('SALE_DH_RP_CONFIG_ZONES_EMPTY');
141
142 for ($i = 1; $i <= self::$ZONES_COUNT; $i++)
143 $arZones[$i] = GetMessage('SALE_DH_RP_CONFIG_ZONE').' '.$i;
144
146 'delivery_regs_to_zones',
147 array('CDeliveryRusPost', 'importZonesFromCsv'),
148 array($arShopLocation),
149 $siteId
150 );
151
152 $arConfig['CONFIG']['RESET_HANDLER_SETTINGS'] = array(
153 'TYPE' => 'CUSTOM',
154 'TITLE' => GetMessage('SALE_DH_RP_SET_DEFAULT_TARIF_ZONES'),
155 'GROUP' => 'zones',
156 'DEFAULT' => '<a href="javascript:void(0);" onclick="BX.Sale.Delivery.resetRusPostSettings();">'.GetMessage('SALE_DH_RP_SET_DEFAULT_TARIF_ZONES_SET').'</a>'
157 );
158
159 foreach ($arRegions as $regId => $regName)
160 {
161 $codeByName = self::getRegionCodeByOldName($regName); // old location
162 $code = $codeByName <> '' ? $codeByName : $regId;
163
164 if(isset($arRegsToZones[$code]))
165 {
166 $arConfig['CONFIG']['REG_'.$code] = array(
167 'TYPE' => 'DROPDOWN',
168 'DEFAULT' => isset($arRegsToZones[$code]) ? $arRegsToZones[$code] : '0',
169 'TITLE' => $regName,
170 'GROUP' => 'zones',
171 'VALUES'=> $arZones
172 );
173 }
174 }
175
176 /*
177 tarifs tab
178 1. land
179 1.1. Base Price
180 */
181
182 $arConfig['CONFIG']['RESET_TARIF_SETTINGS'] = array(
183 'TYPE' => 'CUSTOM',
184 'TITLE' => GetMessage('SALE_DH_RP_SET_DEFAULT_TARIF'),
185 'GROUP' => 'tarifs',
186 'DEFAULT' => '<a href="javascript:void(0);" onclick="BX.Sale.Delivery.resetRusPostTarifSettings();">'.GetMessage('SALE_DH_RP_SET_DEFAULT_TARIF_SET').'</a>'
187 );
188
189 $arConfig['CONFIG']['tarif_section_1'] = array(
190 'TYPE' => 'SECTION',
191 'TITLE' => GetMessage('SALE_DH_RP_WEIGHT_LESS'),
192 'GROUP' => 'tarifs',
193 );
194
196 'delivery_rus_post_tarifs',
197 array('CDeliveryRusPost', 'getTarifsByRegionFromCsv'),
198 array($arShopLocation),
199 $siteId
200 );
201
202 foreach ($arZones as $zoneId => $zoneName)
203 {
204 if($zoneId <= 0)
205 continue;
206
207 $tarifId = self::$TARIF_LESS_500[$zoneId];
208 $arConfig['CONFIG']['ZONE_RATE_MAIN_'.$zoneId] = array(
209 'TYPE' => 'STRING',
210 'DEFAULT' => isset($arTarifs[$tarifId]) ? $arTarifs[$tarifId] : '0',
211 'TITLE' => $zoneName,
212 'GROUP' => 'tarifs',
213 );
214 }
215
216 $arConfig['CONFIG']['tarif_section_2'] = array(
217 'TYPE' => 'SECTION',
218 'TITLE' => GetMessage('SALE_DH_RP_WEIGHT_MORE'),
219 'GROUP' => 'tarifs',
220 );
221
222 foreach ($arZones as $zoneId => $zoneName)
223 {
224 if($zoneId <= 0)
225 continue;
226
227 $tarifId = self::$TARIF_MORE_500[$zoneId];
228
229 $arConfig['CONFIG']['ZONE_RATE_ADD_'.$zoneId] = array(
230 'TYPE' => 'STRING',
231 'DEFAULT' => isset($arTarifs[$tarifId]) ? $arTarifs[$tarifId] : '0',
232 'TITLE' => $zoneName,
233 'GROUP' => 'tarifs',
234 );
235 }
236
237 /* Additional services */
238 $arConfig['CONFIG']['tarif_add_services'] = array(
239 'TYPE' => 'SECTION',
240 'TITLE' => GetMessage('SALE_DH_RP_ADD_SRV'),
241 'GROUP' => 'tarifs',
242 );
243
244 /* 1.2 Service heavy weight 10 - 20 kg */
245 $tarifId = self::$TARIF_HEAVY_WEIGHT;
246 $arConfig['CONFIG']['service_'.$tarifId.'_enabled'] = array(
247 'TYPE' => 'CHECKBOX',
248 'TITLE' => GetMessage('SALE_DH_RP_SRV_HEAVY'),
249 'GROUP' => 'tarifs',
250 'DEFAULT' => 'Y',
251 'HIDE_BY_NAMES' => array('service_'.$tarifId.'_value')
252 );
253
254 $arConfig['CONFIG']['service_'.$tarifId.'_value'] = array(
255 'TYPE' => 'STRING',
256 'TITLE' => GetMessage('SALE_DH_RP_SRV_HEAVY_VAL').' %',
257 'GROUP' => 'tarifs',
258 'DEFAULT' => isset($arTarifs[$tarifId]) ? $arTarifs[$tarifId] : '0',
259 );
260
261 /* 1.5 Service fragile */
262 $tarifId = self::$TARIF_FRAGILE;
263 $arConfig['CONFIG']['service_'.$tarifId.'_enabled'] = array(
264 'TYPE' => 'CHECKBOX',
265 'TITLE' => GetMessage('SALE_DH_RP_SRV_FRGL'),
266 'GROUP' => 'tarifs',
267 'DEFAULT' => 'Y',
268 'HIDE_BY_NAMES' => array('service_'.$tarifId.'_value'),
269 'TOP_LINE' => 'Y'
270 );
271
272 $arConfig['CONFIG']['service_'.$tarifId.'_value'] = array(
273 'TYPE' => 'STRING',
274 'TITLE' => GetMessage('SALE_DH_RP_SRV_FRGL_VAL').' %',
275 'GROUP' => 'tarifs',
276 'DEFAULT' => isset($arTarifs[$tarifId]) ? $arTarifs[$tarifId] : '0'
277 );
278
279 /* 4. Service declared value */
280 $tarifId = self::$TARIF_DECLARED_VAL;
281 $arConfig['CONFIG']['service_'.$tarifId.'_enabled'] = array(
282 'TYPE' => 'CHECKBOX',
283 'TITLE' => GetMessage('SALE_DH_RP_SRV_DECL'),
284 'GROUP' => 'tarifs',
285 'DEFAULT' => 'Y',
286 'HIDE_BY_NAMES' => array('service_'.$tarifId.'_value'),
287 'TOP_LINE' => 'Y'
288 );
289
290 $arConfig['CONFIG']['service_'.$tarifId.'_value'] = array(
291 'TYPE' => 'STRING',
292 'TITLE' => GetMessage('SALE_DH_RP_SRV_DECL_VAL'),
293 'GROUP' => 'tarifs',
294 'DEFAULT' => isset($arTarifs[$tarifId]) ? $arTarifs[$tarifId] : '0',
295 );
296
297 // land tab
298 $aviableBoxes = self::getAviableBoxes();
299
300 foreach ($aviableBoxes as $boxId => $arBox)
301 CSaleDeliveryHelper::makeBoxConfig($boxId, $arBox, 'land', $arConfig);
302
303 /* 2.1 avia tab*/
304
305 foreach ($aviableBoxes as $boxId => $arBox)
306 CSaleDeliveryHelper::makeBoxConfig($boxId, $arBox, 'avia', $arConfig);
307
308 $tarifId = self::$TARIF_AVIA_STANDART;
309 $arConfig['CONFIG']['tarif_avia_services'] = array(
310 'TYPE' => 'SECTION',
311 'TITLE' => GetMessage('SALE_DH_RP_TARIFS_AVIA'),
312 'GROUP' => 'avia',
313 );
314
315 $arConfig['CONFIG']['tarif_avia_'.$tarifId.'_value'] = array(
316 'TYPE' => 'STRING',
317 'TITLE' => GetMessage('SALE_DH_RP_TARIF_AVIA_STNDRT'),
318 'GROUP' => 'avia',
319 'DEFAULT' => isset($arTarifs[$tarifId]) ? $arTarifs[$tarifId] : '0',
320 );
321
322 $tarifId = self::$TARIF_AVIA_HEAVY;
323 $arConfig['CONFIG']['tarif_avia_'.$tarifId.'_value'] = array(
324 'TYPE' => 'STRING',
325 'TITLE' => GetMessage('SALE_DH_RP_TARIF_AVIA_HEAVY'),
326 'GROUP' => 'avia',
327 'DEFAULT' => isset($arTarifs[$tarifId]) ? $arTarifs[$tarifId] : '0',
328 );
329
330 return $arConfig;
331 }
332
333 public static function GetSettings($strSettings)
334 {
335 $result = unserialize($strSettings, ['allowed_classes' => false]);
336
337 if(isset($result['RESET_HANDLER_SETTINGS']))
338 unset($result['RESET_HANDLER_SETTINGS']);
339
340 if(isset($result['SET_DEFAULT_TARIF_ZONES']))
341 unset($result['SET_DEFAULT_TARIF_ZONES']);
342
343 if(isset($result['RESET_TARIF_SETTINGS']))
344 unset($result['RESET_TARIF_SETTINGS']);
345
346 if(isset($_REQUEST["RESET_HANDLER_SETTINGS"]) && $_REQUEST["RESET_HANDLER_SETTINGS"] == "Y" && !isset($_REQUEST["apply"]))
347 {
348 foreach($result as $key => $value)
349 if(mb_substr($key, 0, 4) == 'REG_')
350 unset($result[$key]);
351 }
352
353 if(isset($_REQUEST["RESET_TARIF_SETTINGS"]) && $_REQUEST["RESET_TARIF_SETTINGS"] == "Y" && !isset($_REQUEST["apply"]))
354 {
355 foreach($result as $key => $value)
356 if(mb_substr($key, 0, 5) == 'ZONE_' || mb_substr($key, 0, 6) == 'tarif_' || mb_substr($key, 0, 8) == 'service_')
357 unset($result[$key]);
358 }
359
360 return $result;
361 }
362
363 public static function SetSettings($arSettings)
364 {
365 if(isset($arSettings['RESET_HANDLER_SETTINGS']))
366 unset($arSettings['RESET_HANDLER_SETTINGS']);
367
368 if(isset($arSettings['SET_DEFAULT_TARIF_ZONES']))
369 unset($arSettings['SET_DEFAULT_TARIF_ZONES']);
370
371 if(isset($arSettings['RESET_TARIF_SETTINGS']))
372 unset($arSettings['RESET_TARIF_SETTINGS']);
373
374
375 foreach ($arSettings as $key => $value)
376 {
377 if ($value <> '' && (mb_substr($key, 0, 4) != 'REG_' || $value != '0'))
378 $arSettings[$key] = $value;
379 else
380 unset($arSettings[$key]);
381 }
382
383 return serialize($arSettings);
384 }
385
386 public static function GetFeatures($arConfig)
387 {
388 $arResult = array();
389
390 if ($arConfig["service_".self::$TARIF_FRAGILE."_enabled"]["VALUE"] == "Y")
391 $arResult[GetMessage("SALE_DH_RP_FEATURE_MARK")] = GetMessage("SALE_DH_RP_FEATURE_MARKED");
392
393 if ($arConfig["service_".self::$TARIF_DECLARED_VAL."_enabled"]["VALUE"] == "Y")
394 $arResult[GetMessage("SALE_DH_RP_FEATURE_VALUE")] = GetMessage("SALE_DH_RP_FEATURE_ENABLED");
395
396 return $arResult;
397 }
398
399 public static function Calculate($profile, $arConfig, $arOrder, $STEP, $TEMP = false)
400 {
401 $maxWeight = self::isHeavyEnabled($arConfig) ? self::$MAX_WEIGHT_HEAVY : self::$MAX_WEIGHT;
402
403 $arPacks = CSaleDeliveryHelper::getBoxesFromConfig($profile, $arConfig);
404
405 $arPackagesParams = CSaleDeliveryHelper::getRequiredPacks(
406 $arOrder["ITEMS"],
407 $arPacks,
408 $maxWeight);
409
410 $packageCount = count($arPackagesParams);
411
412 if(intval($packageCount) <= 0)
413 {
414 return array(
415 "RESULT" => "ERROR",
416 "TEXT" => GetMessage("SALE_DH_RP_OVERLOAD"),
417 );
418 }
419
420 $totalPrice = 0;
421 $arLocationTo = \CSaleHelper::getLocationByIdHitCached($arOrder['LOCATION_TO']);
422
423 try
424 {
425 foreach ($arPackagesParams as $arPackage)
426 $totalPrice += self::calculatePackPrice($arPackage, $profile, $arConfig, $arLocationTo);
427 }
428 catch(\Bitrix\Main\SystemException $e)
429 {
430 return array(
431 "RESULT" => "ERROR",
432 "TEXT" => $e->getMessage()
433 );
434 }
435
437 'RESULT' => 'OK',
438 'VALUE' => $totalPrice,
439 'PACKS_COUNT' => $packageCount
440 );
441 return $arResult;
442 }
443
444 public static function Compability($arOrder, $arConfig)
445 {
446 $profiles = array('land', 'avia');
447
448 $bHevyWeightEnabled = self::isConfCheckedVal($arConfig, 'service_'.self::$TARIF_HEAVY_WEIGHT.'_enabled');
449
450 $maxWeight = $bHevyWeightEnabled ? self::$MAX_WEIGHT_HEAVY : self::$MAX_WEIGHT;
451
452 if (!empty($arOrder["ITEMS"]) && is_array($arOrder["ITEMS"]))
453 {
454 foreach ($arOrder["ITEMS"] as $arItem)
455 {
456 if ((float)($arItem['WEIGHT'] ?? 0) > $maxWeight)
457 {
458 $profiles = array();
459 break;
460 }
461 }
462 }
463
464 $locationToCode = CSaleHelper::getLocationByIdHitCached($arOrder['LOCATION_TO']);
465
466 if(self::getLocationToCode($locationToCode) == '')
467 $profiles = array();
468
469 $arRes = array();
470
471 foreach ($profiles as $profile)
472 {
473 $aviableBoxes = CSaleDeliveryHelper::getBoxesFromConfig($profile, $arConfig);
474
475 foreach ($aviableBoxes as $arBox)
476 {
477 if (CSaleDeliveryHandler::checkDimensions($arOrder["MAX_DIMENSIONS"], $arBox["DIMENSIONS"]))
478 {
479 $arRes[] = $profile;
480 break;
481 }
482 }
483 }
484
485 return $arRes;
486 }
487
488 /* Particular services helper functions*/
489
490 public static function importZonesFromCsv(array $arShopLocation)
491 {
492 if(empty($arShopLocation) || !isset($arShopLocation["REGION_ID"]) || !isset($arShopLocation['REGION_NAME_LANG']))
493 return array();
494
495 $regionCodeFromCode = $regionCodeFromName = "";
496
497 $dbRes = Location\LocationTable::getList(array(
498 'filter' => array(
499 '=TYPE.CODE' => 'REGION',
500 '=REGION_ID' => intval($arShopLocation["REGION_ID"]),
501 '=CITY_ID' => false
502 ),
503 'select' => array(
504 'ID', 'CODE'
505 )
506 ));
507
508 if($locReg = $dbRes->fetch())
509 $regionCodeFromCode = $locReg["CODE"];
510
511 $regionCodeFromName = self::getRegionCodeByOldName($arShopLocation['REGION_NAME_LANG']);
512
513 $COL_REG_CODE = 0;
514 $csvFile = CSaleHelper::getCsvObject(DELIVERY_RP_CSV_PATH.'/zones.csv');
515 $arRegsTo = $csvFile->Fetch();
516 $arRegionsZones = array();
517
518 while ($arRes = $csvFile->Fetch())
519 {
520 if(isset($arRes[$COL_REG_CODE])
521 && (
522 $regionCodeFromCode == $arRes[$COL_REG_CODE]
523 || $regionCodeFromName == $arRes[$COL_REG_CODE]
524 )
525 )
526 {
527 for ($i = 1, $l = count($arRes) - 1; $i <= $l; $i++)
528 {
529 if(isset($arRegsTo[$i])
530 &&
531 isset($arRes[$i])
532 )
533 {
534 $arRegionsZones[$arRegsTo[$i]] = $arRes[$i];
535 }
536 }
537
538 break;
539 }
540 }
541
542 return $arRegionsZones;
543 }
544
550 public static function importZonesFromZipCsv()
551 {
552 $COL_ZIP = 0;
553 $COL_ZONE = 1;
554 $csvFile = CSaleHelper::getCsvObject(DELIVERY_RP_CSV_PATH.'/zip_zones.csv');
555 $arRes = $csvFile->Fetch();
556
558 $arRegionsZones = array();
559
560 while ($arRes = $csvFile->Fetch())
561 {
563
564 if($location === false)
565 continue;
566
567 if(isset($arRegions[$location['REGION_ID']]))
568 $arRegionsZones[$location['REGION_ID']] = $arRes[$COL_ZONE];
569
570 unset($arRegions[$location['REGION_ID']]);
571
572 if(empty($arRegions))
573 break;
574 }
575
576 return $arRegionsZones;
577 }
578
579 public static function getTarifNumFromCsv(array $arShopLocation)
580 {
581 if(empty($arShopLocation) || !isset($arShopLocation['REGION_NAME_LANG'], $arShopLocation["ID"]))
582 return false;
583
584 $regionCodeFromCode = $regionCodeFromName = "";
585
586 $loc = \CSaleHelper::getLocationByIdHitCached($arShopLocation["ID"]);
587
588 $res = \Bitrix\Sale\Location\LocationTable::getList(array(
589 'filter' => array('=ID' => $loc["REGION_ID"]),
590 'select' => array('CODE')
591 ));
592
593 if($locReg = $res->fetch())
594 {
595 $regionCodeFromCode = $locReg["CODE"];
596 }
597
598 $regionCodeFromName = self::getRegionCodeByOldName($arShopLocation['REGION_NAME_LANG']);
599 $csvFile = CSaleHelper::getCsvObject(DELIVERY_RP_CSV_PATH.'/tarif_regions.csv');
600 $tarifNumber = false;
601 $COL_TARIF_NUM = 0;
602
603 while ($arRes = $csvFile->Fetch())
604 {
605 if(
606 ($regionCodeFromCode <> '' && in_array($regionCodeFromCode, $arRes))
607 || ($regionCodeFromName <> '' && in_array($regionCodeFromName, $arRes))
608 )
609 {
610 $tarifNumber = $arRes[$COL_TARIF_NUM];
611 break;
612 }
613 }
614 return $tarifNumber;
615 }
616
617 public static function getTarifsByRegionFromCsv(array $arShopLocation)
618 {
619 $tarifNumber = self::getTarifNumFromCsv($arShopLocation);
620
621 if($tarifNumber === false)
622 return false;
623
624 $csvFile = CSaleHelper::getCsvObject(DELIVERY_RP_CSV_PATH.'/tarif_data.csv');
625 $COL_TARIF_ITEMS = 0;
626 $arTarifs = array();
627 $arRes = $csvFile->Fetch();
628 while ($arRes = $csvFile->Fetch())
629 {
630 if(!isset($arRes[$tarifNumber]))
631 break;
632
633 $arTarifs[$arRes[$COL_TARIF_ITEMS]] = $arRes[$tarifNumber];
634 }
635
636 return $arTarifs;
637 }
638
639 private static function getConfValue(&$arConfig, $key)
640 {
641 return CSaleDeliveryHelper::getConfValue($arConfig[$key] ?? null);
642 }
643
644 private static function isConfCheckedVal(&$arConfig, $key)
645 {
646 return $arConfig[$key]['VALUE'] == 'Y'
647 ||(
648 !isset($arConfig[$key]['VALUE'])
649 && $arConfig[$key]['DEFAULT'] == 'Y'
650 );
651 }
652
653 private static function isHeavyEnabled(&$arConfig)
654 {
655 return self::isConfCheckedVal($arConfig, 'service_'.self::$TARIF_HEAVY_WEIGHT.'_enabled');
656 }
657
658 private static function getAviableBoxes()
659 {
660 return array(
661 array(
662 "NAME" => GetMessage("SALE_DH_RP_STNDRD_BOX"),
663 "DIMENSIONS" => array("425", "265", "380")
664 )
665 );
666 }
667
668 private static function getLocationToCode($arLocationTo)
669 {
670 if (!is_array($arLocationTo))
671 {
672 return '';
673 }
674 $code = (string)self::getRegionCodeByOldName($arLocationTo['REGION_NAME_LANG'] ?? ''); // old location
675
677 {
678 $dbRes = Location\LocationTable::getList([
679 'filter' => [
680 '=TYPE.CODE' => 'REGION',
681 '=REGION_ID' => (int)($arLocationTo["REGION_ID"] ?? 0),
682 '=CITY_ID' => false,
683 ],
684 'select' => [
685 'ID',
686 'CODE',
687 'NAME',
688 ],
689 ]);
690
691 $locReg = $dbRes->fetch();
692 unset($dbRes);
693 $code = $locReg["CODE"] ?? '';
694 }
695
696 return $code;
697 }
698
699 private static function calculatePackPrice($arPackage, $profile, $arConfig, $arLocationTo)
700 {
701 $arDebug = array();
702
703 /*1 Land price
704 1.1 Base Price less 10 kg*/
705
706 $code = self::getLocationToCode($arLocationTo);
707
708 if($code == '')
709 throw new \Bitrix\Main\SystemException(GetMessage("SALE_DH_RP_ERROR_LOCATION_NOT_FOUND"));
710
711 $zoneTo = self::getConfValue($arConfig, 'REG_'.$code);
712 $basePrice = floatval(self::getConfValue($arConfig, 'ZONE_RATE_MAIN_'.$zoneTo));
713
714 if($basePrice <=0)
715 throw new \Bitrix\Main\SystemException(GetMessage("SALE_DH_RP_CALCULATE_ERROR"));
716
717 $arDebug[] = 'Base Price less 500 g: '.$basePrice;
718
719 if($arPackage['WEIGHT'] > self::$BASE_WEIGHT)
720 {
721 $addWeight = ceil($arPackage['WEIGHT'] / self::$BASE_WEIGHT - 1);
722 $addPrice = floatval(self::getConfValue($arConfig, 'ZONE_RATE_ADD_'.$zoneTo));
723 $arDebug[] = 'Price for additional weight more than 500 g: '.$addWeight * $addPrice;
724 $basePrice += $addWeight * $addPrice;
725 }
726
727 $totalPrice = $basePrice;
728
729 /* 1.2 Service "heavy weight" 10 - 20 kg*/
730 $hwPrice = 0;
731 if($arPackage['WEIGHT'] >= self::$MAX_WEIGHT)
732 {
733 $hwTarif = floatval(self::getConfValue($arConfig, 'service_'.self::$TARIF_HEAVY_WEIGHT.'_value'));
734 $hwPrice += $totalPrice*$hwTarif/100;
735 $arDebug[] = 'Heavy weight: '.$hwPrice;
736 $totalPrice += $hwPrice;
737 }
738
739 /* 1.5 Service "fragile" */
740 $fPrice = 0;
741 if(self::isConfCheckedVal($arConfig, 'service_'.self::$TARIF_FRAGILE.'_enabled'))
742 {
743 $fTarif = floatval(self::getConfValue($arConfig, 'service_'.self::$TARIF_FRAGILE.'_value'));
744 $fPrice += $totalPrice*$fTarif/100;
745 $arDebug[] = 'Fragile: '.$fPrice;
746 $totalPrice += $fPrice;
747 }
748
749 /* 4. Service "declared value" */
750 $dvPrice = 0;
751 if(self::isConfCheckedVal($arConfig, 'service_'.self::$TARIF_DECLARED_VAL.'_enabled'))
752 {
753 $dvTarif = floatval(self::getConfValue($arConfig, 'service_'.self::$TARIF_DECLARED_VAL.'_value'));
754 $dvPrice += ($arPackage['PRICE'])*$dvTarif;
755 $arDebug[] = 'Declared value: '.$dvPrice;
756 $totalPrice += $dvPrice;
757 }
758
759 if($profile == 'avia')
760 {
761 $aviaPrice = 0;
762 $aviaPrice = floatval(self::getConfValue($arConfig, 'tarif_avia_'.self::$TARIF_AVIA_STANDART.'_value'));
763 $arDebug[] = 'avia price: '.$aviaPrice;
764 $totalPrice += $aviaPrice;
765
766 $aviaHeavyPrice = 0;
767 if($arPackage['WEIGHT'] > self::$MAX_WEIGHT)
768 {
769 $aviaHeavyPrice = floatval(self::getConfValue($arConfig, 'tarif_avia_'.self::$TARIF_AVIA_HEAVY.'_value'));
770 $arDebug[] = 'avia heavy price: '.$aviaHeavyPrice;
771 $totalPrice += $aviaHeavyPrice;
772 }
773 }
774
775 return $totalPrice;
776 }
777
778 protected static function getRegionCodeByOldName($regionLangName)
779 {
780 if($regionLangName == '')
781 return "";
782
783 static $data = array();
784
785 if(empty($data))
786 {
787 require_once(__DIR__.'/rus_post/old_loc_to_codes.php');
790 }
791
792 return $data[$regionLangName] ?? "";
793 }
794
801 public static function isHandlerCompatible(): bool
802 {
803 return \Bitrix\Sale\Delivery\Helper::getPortalZone() !== 'ua';
804 }
805}
806
807AddEventHandler('sale', 'onSaleDeliveryHandlersBuildList', array('CDeliveryRusPost', 'Init'));
808?>
const BX_ROOT
Определения bx_root.php:3
$arResult
Определения generate_coupon.php:16
static delete($moduleId, array $filter=array())
Определения option.php:388
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
static set($moduleId, $name, $value="", $siteId="")
Определения option.php:261
static checkDimensions($arOrderDimensions, $arRestrictDimensions)
Определения delivery_handler.php:1360
static GetByZIP($zip)
Определения location.php:2794
static isLocationProMigrated()
Определения location.php:58
Определения delivery_rus_post.php:17
static Compability($arOrder, $arConfig)
Определения delivery_rus_post.php:444
static GetConfig($siteId=false)
Определения delivery_rus_post.php:98
static Calculate($profile, $arConfig, $arOrder, $STEP, $TEMP=false)
Определения delivery_rus_post.php:399
static importZonesFromZipCsv()
Определения delivery_rus_post.php:550
static importZonesFromCsv(array $arShopLocation)
Определения delivery_rus_post.php:490
static SetSettings($arSettings)
Определения delivery_rus_post.php:363
static getTarifsByRegionFromCsv(array $arShopLocation)
Определения delivery_rus_post.php:617
const LOCATION_CODE_RUSSIA
Определения delivery_rus_post.php:49
static GetSettings($strSettings)
Определения delivery_rus_post.php:333
static Init()
Определения delivery_rus_post.php:51
static isHandlerCompatible()
Определения delivery_rus_post.php:801
static getTarifNumFromCsv(array $arShopLocation)
Определения delivery_rus_post.php:579
static GetFeatures($arConfig)
Определения delivery_rus_post.php:386
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 getRegionsList($countryId=0, $bFlip=false)
Определения delivery_helper.php:17
static getConfValue($arField)
Определения delivery_helper.php:148
static getBoxesFromConfig($profile, &$arConfig)
Определения delivery_helper.php:447
static getCsvObject($filePath)
Определения helper.php:379
static getLocationByIdHitCached($id)
Определения helper.php:462
static getShopLocationId($siteId)
Определения helper.php:334
static getOptionOrImportValues($optName, $importFuncName=false, $arFuncParams=array(), $siteId="")
Определения helper.php:261
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
$result
Определения get_property_values.php:14
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$STEP
Определения csv_new_setup.php:23
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$l
Определения options.php:783
$siteId
Определения ajax.php:8
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
const DELIVERY_RP_CSV_PATH
Определения delivery_rus_post.php:11
$i
Определения factura.php:643
</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
$locToCode
Определения old_loc_to_codes.php:2
$location
Определения options.php:2729
$arRes
Определения options.php:104
$dbRes
Определения yandex_detail.php:168