Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
bydimensions.php
1<?php
3
8
9Loc::loadMessages(__FILE__);
10
17{
18 public static function getClassTitle()
19 {
20 return Loc::getMessage("SALE_DLVR_RSTR_BY_DIMENSIONS_NAME");
21 }
22
23 public static function getClassDescription()
24 {
25 return Loc::getMessage("SALE_DLVR_RSTR_BY_DIMENSIONS_DESCRIPT");
26 }
27
35 public static function check($dimensionsList, array $restrictionParams, $deliveryId = 0)
36 {
37 if(empty($restrictionParams))
38 return true;
39
40 foreach($dimensionsList as $dimensions)
41 {
42 foreach($restrictionParams as $name => $value) //LENGTH, WIDTH, HEIGHT
43 {
44 if($value <=0)
45 continue;
46
47 if(!isset($dimensions[$name]))
48 continue;
49
50 if(intval($dimensions[$name]) <= 0)
51 continue;
52
53 if(intval($dimensions[$name]) > intval($value))
54 return false;
55 }
56 }
57
58 return true;
59 }
60
61 protected static function extractParams(Entity $entity)
62 {
63 $paramsToCheck = array();
64
65 if ($entity instanceof Shipment)
66 {
67 foreach($entity->getShipmentItemCollection() as $shipmentItem)
68 {
69 $basketItem = $shipmentItem->getBasketItem();
70
71 if(!$basketItem)
72 continue;
73
74 $dimensions = $basketItem->getField("DIMENSIONS");
75
76 if(is_string($dimensions))
77 $dimensions = unserialize($dimensions, ['allowed_classes' => false]);
78
79 if(!is_array($dimensions) || empty($dimensions))
80 continue;
81
82 $paramsToCheck[] = $dimensions;
83 }
84 }
85
86 return $paramsToCheck;
87 }
88
89 public static function getParamsStructure($entityId = 0)
90 {
91 return array(
92 "LENGTH" => array(
93 'TYPE' => 'NUMBER',
94 'DEFAULT' => "0",
95 'MIN' => 0,
96 'LABEL' => Loc::getMessage("SALE_DLVR_RSTR_BY_DIMENSIONS_LENGTH")
97 ),
98 "WIDTH" => array(
99 'TYPE' => 'NUMBER',
100 'DEFAULT' => "0",
101 'MIN' => 0,
102 'LABEL' => Loc::getMessage("SALE_DLVR_RSTR_BY_DIMENSIONS_WIDTH")
103 ),
104 "HEIGHT" => array(
105 'TYPE' => 'NUMBER',
106 'DEFAULT' => "0",
107 'MIN' => 0,
108 'LABEL' => Loc::getMessage("SALE_DLVR_RSTR_BY_DIMENSIONS_HEIGHT")
109 )
110 );
111 }
112}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static check($dimensionsList, array $restrictionParams, $deliveryId=0)