Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?
3
5
7{
8 protected static $classNames = null;
9
13 protected static function getServiceType()
14 {
15 return self::SERVICE_TYPE_SHIPMENT;
16 }
17
21 protected static function getBuildInRestrictions()
22 {
23 return array(
24 '\Bitrix\Sale\Delivery\Restrictions\BySite' => 'lib/delivery/restrictions/bysite.php',
25 '\Bitrix\Sale\Delivery\Restrictions\ByPrice' => 'lib/delivery/restrictions/byprice.php',
26 '\Bitrix\Sale\Delivery\Restrictions\ByWeight' => 'lib/delivery/restrictions/byweight.php',
27 '\Bitrix\Sale\Delivery\Restrictions\ByMaxSize' => 'lib/delivery/restrictions/bymaxsize.php',
28 '\Bitrix\Sale\Delivery\Restrictions\ByLocation' => 'lib/delivery/restrictions/bylocation.php',
29 '\Bitrix\Sale\Delivery\Restrictions\ByUserGroup' => 'lib/delivery/restrictions/byusergroup.php',
30 '\Bitrix\Sale\Delivery\Restrictions\ByPaySystem' => 'lib/delivery/restrictions/bypaysystem.php',
31 '\Bitrix\Sale\Delivery\Restrictions\ByPersonType' => 'lib/delivery/restrictions/bypersontype.php',
32 '\Bitrix\Sale\Delivery\Restrictions\ByDimensions' => 'lib/delivery/restrictions/bydimensions.php',
33 '\Bitrix\Sale\Delivery\Restrictions\ByPublicMode' => 'lib/delivery/restrictions/bypublicmode.php',
34 '\Bitrix\Sale\Delivery\Restrictions\ByTradeBinding' => 'lib/delivery/restrictions/bytradebinding.php',
35 '\Bitrix\Sale\Delivery\Restrictions\ExcludeLocation' => 'lib/delivery/restrictions/excludelocation.php',
36 '\Bitrix\Sale\Delivery\Restrictions\ByProductCategory' => 'lib/delivery/restrictions/byproductcategory.php',
37 '\Bitrix\Sale\Delivery\Restrictions\ByConcreteProduct' => 'lib/delivery/restrictions/byconcreteproduct.php',
38 );
39 }
40
44 public static function getEventName()
45 {
46 class_alias('Bitrix\Sale\Delivery\Restrictions\ByPersonType', 'Bitrix\Sale\Delivery\Restrictions\PersonType');
47 return 'onSaleDeliveryRestrictionsClassNamesBuildList';
48 }
49
54 public static function deleteByDeliveryIdClassName($deliveryId, $className)
55 {
56 $con = \Bitrix\Main\Application::getConnection();
57 $sqlHelper = $con->getSqlHelper();
58 $strSql = "DELETE FROM ".ServiceRestrictionTable::getTableName().
59 " WHERE SERVICE_ID=".$sqlHelper->forSql($deliveryId).
60 " AND SERVICE_TYPE=".$sqlHelper->forSql(Manager::SERVICE_TYPE_SHIPMENT).
61 " AND CLASS_NAME='".$sqlHelper->forSql($className)."'";
62
63 $con->queryExecute($strSql);
64 }
65
74 public static function getRestrictedIds(\Bitrix\Sale\Shipment $shipment = null, $restrictionMode)
75 {
76 $result = array();
77
78 static $dataPrepared = false;
79 static $idsGrouppedByRestrictions = array(); //performance
80 static $supportGroupFiltering = array(); //
81
82 if($dataPrepared === false)
83 {
84 self::init();
85 $filter = array(
86 'DELIVERY_SERVICE.ACTIVE' => 'Y'
87 );
88
89 $dbRes = ServiceRestrictionTable::getList(array(
90 'runtime' => array(
91 new \Bitrix\Main\Entity\ReferenceField(
92 'DELIVERY_SERVICE',
93 '\Bitrix\Sale\Delivery\Services\Table',
94 array(
95 '=this.SERVICE_ID' => 'ref.ID',
96 '=this.SERVICE_TYPE' => array('?', self::SERVICE_TYPE_SHIPMENT)
97 ),
98 array('join_type' => 'inner')
99 )
100 ),
101 'filter' => $filter,
102 'order' => array('SORT' =>'ASC')
103 ));
104
105 $data = array();
106 $checkedGroupFiltering = array();
107
108 while($rstr = $dbRes->fetch())
109 {
110 if(!isset($data[$rstr["SERVICE_ID"]]))
111 $data[$rstr["SERVICE_ID"]] = array();
112
113 $data[$rstr["SERVICE_ID"]][$rstr['ID']] = $rstr;
114
115 if(!in_array($rstr['CLASS_NAME'], $checkedGroupFiltering))
116 {
117 $checkedGroupFiltering[] = $rstr['CLASS_NAME'];
118
119 if(method_exists($rstr['CLASS_NAME'], 'filterServicesArray'))
120 $supportGroupFiltering[] = $rstr['CLASS_NAME'];
121 }
122
123 if(in_array($rstr['CLASS_NAME'], $supportGroupFiltering))
124 {
125 if (!isset($idsGrouppedByRestrictions[$rstr['CLASS_NAME']]))
126 {
127 $idsGrouppedByRestrictions[$rstr['CLASS_NAME']] = [];
128 }
129
130 if (!in_array($rstr["SERVICE_ID"], $idsGrouppedByRestrictions[$rstr['CLASS_NAME']]))
131 {
132 $idsGrouppedByRestrictions[$rstr['CLASS_NAME']][$rstr["SERVICE_ID"]] = $rstr;
133 }
134 }
135 }
136
137 self::prepareData(array_keys($data), $data);
138 $dataPrepared = true;
139 }
140 else
141 {
142 $data = self::getCache(0, self::getServiceType());
143 }
144
145 $filterResult = array();
146
147 foreach($supportGroupFiltering as $rstrClass)
148 {
149 $passedServicesIds = $rstrClass::filterServicesArray($shipment, $idsGrouppedByRestrictions[$rstrClass]);
150 $notPassed = array_diff_key($idsGrouppedByRestrictions[$rstrClass], array_flip($passedServicesIds));
151
152 if($restrictionMode == self::MODE_MANAGER)
153 foreach($notPassed as $srvId => $rstr)
154 $filterResult[$srvId] = $rstrClass::getSeverity($restrictionMode);
155
156 $data = array_diff_key($data, $notPassed);
157 }
158
159 foreach($data as $serviceId => $serviceRestrictions)
160 {
161 $srvRes = self::SEVERITY_NONE;
162
163 if($shipment != null)
164 {
165 foreach($serviceRestrictions as $restrictionId => $rstr)
166 {
167 if(in_array($rstr['CLASS_NAME'], $supportGroupFiltering))
168 continue;
169
170 if(!self::isClassValid($rstr['CLASS_NAME']))
171 continue;
172
173 if(!$rstr['PARAMS'])
174 $rstr['PARAMS'] = array();
175
176 $res = $rstr['CLASS_NAME']::checkByEntity(
177 $shipment,
178 $rstr['PARAMS'],
179 $restrictionMode,
180 $serviceId
181 );
182
183 if($res == self::SEVERITY_STRICT)
184 continue 2;
185
186 if($res == self::SEVERITY_SOFT && $restrictionMode == self::MODE_CLIENT)
187 continue 2;
188
189 if($res == self::SEVERITY_SOFT && $srvRes == self::SEVERITY_NONE)
190 $srvRes = self::SEVERITY_SOFT;
191 }
192 }
193
194 $result[$serviceId] = $srvRes;
195 }
196
197 return $filterResult + $result;
198 }
199
200 protected function isClassSupportGroupFiltering($className)
201 {
202 if(!self::isClassValid($className))
203 return false;
204
205 return method_exists($className, 'filterServicesArray');
206 }
207
208 protected static function isClassValid($className)
209 {
210 if(empty($className))
211 return false;
212
213 if(!class_exists($className))
214 return false;
215
216 if(!is_subclass_of($className, 'Bitrix\Sale\Services\Base\Restriction'))
217 return false;
218
219 return true;
220 }
221}
static getRestrictedIds(\Bitrix\Sale\Shipment $shipment=null, $restrictionMode)
Definition manager.php:74
static deleteByDeliveryIdClassName($deliveryId, $className)
Definition manager.php:54