38 public static function check($params, array $restrictionParams, $serviceId = 0)
40 if ((
int)$serviceId <= 0)
46 $deliveryIds = self::getDeliveryByCompanyId($serviceId);
48 if (empty($deliveryIds))
51 $diff = array_diff($params, $deliveryIds);
61 protected static function extractParams(
Sale\Internals\
Entity $entity)
66 $shipmentCollection =
null;
70 $shipmentCollection = $entity->getCollection();
75 $paymentCollection = $entity->getCollection();
76 if ($paymentCollection)
79 $order = $paymentCollection->getOrder();
81 $shipmentCollection = $order->getShipmentCollection();
86 $shipmentCollection = $entity->getShipmentCollection();
89 if ($shipmentCollection !==
null)
92 foreach ($shipmentCollection as $shipment)
94 if ($shipment->isSystem())
99 if ($deliveryId = $shipment->getDeliveryId())
101 $result[] = $deliveryId;
116 $serviceList = array();
117 $dbRes = Sale\Delivery\Services\Table::getList(array(
'select' => array(
'ID',
'NAME',
'PARENT_ID')));
118 while ($service = $dbRes->fetch())
119 $serviceList[$service[
'ID']] = $service;
121 foreach ($serviceList as $service)
123 if ((
int)$service[
'PARENT_ID'] > 0)
124 $name = $serviceList[$service[
'PARENT_ID']][
'NAME'].
': '.$service[
'NAME'].
' ['.$service[
'ID'].
']';
126 $name = $service[
'NAME'].
' ['.$service[
'ID'].
']';
128 $result[$service[
'ID']] = $name;
145 "OPTIONS" => self::getDeliveryList()
163 $dbRes = CompanyServiceTable::getList(
165 'select' => array(
'SERVICE_ID'),
167 'COMPANY_ID' => $companyId,
168 'SERVICE_TYPE' =>
Sale\Services\Company\Restrictions\Manager::SERVICE_TYPE_SHIPMENT)
172 while ($data = $dbRes->fetch())
173 $result[] = $data[
'SERVICE_ID'];
183 public static function save(array $fields, $restrictionId = 0)
185 $serviceIds = $fields[
"PARAMS"];
186 $fields[
"PARAMS"] = array();
188 if ($restrictionId > 0)
190 $dbRes = CompanyServiceTable::getList(
192 'select' => array(
'SERVICE_ID'),
194 'SERVICE_TYPE' =>
Sale\Services\Company\Restrictions\Manager::SERVICE_TYPE_SHIPMENT,
195 'COMPANY_ID' => $fields[
'SERVICE_ID']
200 while($data = $dbRes->fetch())
202 $key = array_search($data[
'SERVICE_ID'], $serviceIds[
'DELIVERY']);
205 CompanyServiceTable::delete(array(
'COMPANY_ID' => $fields[
'SERVICE_ID'],
'SERVICE_ID' => $data[
'SERVICE_ID'],
'SERVICE_TYPE' =>
Sale\Services\Company\Restrictions\Manager::SERVICE_TYPE_SHIPMENT));
209 unset($serviceIds[
'DELIVERY'][$key]);
214 $result = parent::save($fields, $restrictionId);
216 $addFields = array(
'COMPANY_ID' => $fields[
'SERVICE_ID'],
'SERVICE_TYPE' =>
Sale\Services\Company\Restrictions\Manager::SERVICE_TYPE_SHIPMENT);
217 foreach ($serviceIds[
'DELIVERY'] as $id)
219 $addFields[
'SERVICE_ID'] = $id;
220 CompanyServiceTable::add($addFields);
233 return array(
"DELIVERY" => self::getDeliveryByCompanyId($entityId));
242 public static function delete($restrictionId, $entityId = 0)
244 $dbRes = CompanyServiceTable::getList(
246 'select' => array(
'SERVICE_ID'),
248 'SERVICE_TYPE' =>
Sale\Services\Company\Restrictions\Manager::SERVICE_TYPE_SHIPMENT,
249 'COMPANY_ID' => $entityId
254 while ($data = $dbRes->fetch())
256 CompanyServiceTable::delete(array(
'COMPANY_ID' => $entityId,
'SERVICE_ID' => $data[
'SERVICE_ID'],
'SERVICE_TYPE' =>
Sale\Services\Company\Restrictions\Manager::SERVICE_TYPE_SHIPMENT));
259 return parent::delete($restrictionId);
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)