Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
location.php
1<?php
3
11
12Loc::loadMessages(__FILE__);
13
18class Location extends Base\Restriction
19{
20 public static $easeSort = 200;
21
25 public static function getClassTitle()
26 {
27 return Loc::getMessage("SALE_COMPANY_RULES_BY_LOCATION_TITLE");
28 }
29
33 public static function getClassDescription()
34 {
35 return Loc::getMessage("SALE_COMPANY_RULES_BY_LOCATION_DESC");
36 }
37
44 public static function check($params, array $restrictionParams, $serviceId = 0)
45 {
46 if ((int)$serviceId <= 0)
47 return true;
48
49 if (!$params)
50 return false;
51
52 try
53 {
54 return CompanyLocationTable::checkConnectionExists(
55 intval($serviceId),
56 $params,
57 array(
58 'LOCATION_LINK_TYPE' => 'AUTO'
59 )
60 );
61 }
62 catch (NodeNotFoundException $e)
63 {
64 return false;
65 }
66 }
67
73 protected static function extractParams(Entity $entity)
74 {
75 if ($entity instanceof CollectableEntity)
76 {
78 $order = $entity->getCollection()->getOrder();
79 }
80 elseif ($entity instanceof Order)
81 {
83 $order = $entity;
84 }
85
86 if (!$order)
87 return '';
88
89 if(!$props = $order->getPropertyCollection())
90 return '';
91
92 if(!$locationProp = $props->getDeliveryLocation())
93 return '';
94
95 if(!$locationCode = $locationProp->getValue())
96 return '';
97
98 return $locationCode;
99 }
100
106 protected static function prepareParamsForSaving(array $params = array(), $companyId = 0)
107 {
108 if($companyId > 0)
109 {
110 $arLocation = array();
111
112 if(!!\CSaleLocation::isLocationProEnabled())
113 {
114 if($params["LOCATION"]['L'] <> '')
115 {
116 $LOCATION1 = explode(':', $params["LOCATION"]['L']);
117 }
118
119 if($params["LOCATION"]['G'] <> '')
120 {
121 $LOCATION2 = explode(':', $params["LOCATION"]['G']);
122 }
123 }
124
125 if (isset($LOCATION1) && is_array($LOCATION1) && count($LOCATION1) > 0)
126 {
127 $arLocation["L"] = array();
128 $locationCount = count($LOCATION1);
129
130 for ($i = 0; $i<$locationCount; $i++)
131 if($LOCATION1[$i] <> '')
132 {
133 $arLocation["L"][] = $LOCATION1[$i];
134 }
135 }
136
137 if (isset($LOCATION2) && is_array($LOCATION2) && count($LOCATION2) > 0)
138 {
139 $arLocation["G"] = array();
140 $locationCount = count($LOCATION2);
141
142 for ($i = 0; $i<$locationCount; $i++)
143 if($LOCATION2[$i] <> '')
144 {
145 $arLocation["G"][] = $LOCATION2[$i];
146 }
147
148 }
149
150 CompanyLocationTable::resetMultipleForOwner($companyId, $arLocation);
151 }
152
153 return array();
154 }
155
160 public static function getParamsStructure($entityId = 0)
161 {
162
163 $result = array(
164 "LOCATION" => array(
165 "TYPE" => "COMPANY_LOCATION_MULTI"
166 )
167 );
168
169 if($entityId > 0 )
170 $result["LOCATION"]["COMPANY_ID"] = $entityId;
171
172 return $result;
173 }
174
180 public static function save(array $fields, $restrictionId = 0)
181 {
182 $fields["PARAMS"] = self::prepareParamsForSaving($fields["PARAMS"], $fields["SERVICE_ID"]);
183 return parent::save($fields, $restrictionId);
184 }
185
191 public static function delete($restrictionId, $entityId = 0)
192 {
193 CompanyLocationTable::resetMultipleForOwner($entityId);
194 return parent::delete($restrictionId);
195 }
196}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static prepareParamsForSaving(array $params=array(), $companyId=0)
Definition location.php:106
static check($params, array $restrictionParams, $serviceId=0)
Definition location.php:44
static save(array $fields, $restrictionId=0)
Definition location.php:180