/** * This function should accept only location CODE, not ID, being a part of modern API */ public static function check($locationCode, array $restrictionParams, $deliveryId = 0) { try { return DeliveryLocationTable::checkConnectionExists(intval($deliveryId), $locationCode, array('LOCATION_LINK_TYPE' => 'AUTO')); } catch (\Bitrix\Sale\Location\Tree\NodeNotFoundException $e) { return false; } }
/** * @param array $restriction * @param array $filter * @return bool * @throws \Bitrix\Main\ArgumentNullException */ protected static function checkRestrictionFilter(array $restriction, array $filter) { $result = true; switch ($restriction["CLASS_NAME"]) { case '\\Bitrix\\Sale\\Delivery\\Restrictions\\BySite': $fieldInFilter = self::isFieldInFilter2("LID", $filter); $value = self::getFilterValue("LID", $filter); if (!$fieldInFilter) { break; } if (is_array($restriction["PARAMS"]["SITE_ID"])) { $result = in_array($value, $restriction["PARAMS"]["SITE_ID"]); } else { $result = $value == $restriction["PARAMS"]["SITE_ID"]; } break; case '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByWeight': $result = !(self::isFieldInFilter2("WEIGHT_FROM", $filter) && floatval(self::getFilterValue("WEIGHT_FROM", $filter)) < floatval($restriction["PARAMS"]["MIN_WEIGHT"])); $result = $result && !(self::isFieldInFilter2("WEIGHT_TO", $filter) && floatval(self::getFilterValue("WEIGHT_TO", $filter)) > floatval($restriction["PARAMS"]["MAX_WEIGHT"])); break; case '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByPrice': $fieldInFilter = self::isFieldInFilter2("ORDER_PRICE_FROM", $filter); $value = self::getFilterValue("ORDER_PRICE_FROM", $filter); $value = floatval($value); if ($fieldInFilter && $value > 0 && floatval($restriction["PARAMS"]["MIN_PRICE"]) > 0) { $result = floatval($value) > floatval($restriction["PARAMS"]["MIN_PRICE"]); if (!$result) { break; } } $fieldInFilter = self::isFieldInFilter2("ORDER_PRICE_TO", $filter); $value = self::getFilterValue("ORDER_PRICE_TO", $filter); $value = floatval($value); if ($fieldInFilter && $value > 0 && floatval($restriction["PARAMS"]["MAX_PRICE"]) > 0) { $result = floatval($value) < floatval($restriction["PARAMS"]["MAX_PRICE"]); if (!$result) { break; } } $fieldInFilter = self::isFieldInFilter2("ORDER_CURRENCY", $filter); $value = self::getFilterValue("ORDER_CURRENCY", $filter); if ($fieldInFilter && strlen($value) > 0 && strlen($restriction["PARAMS"]["CURRENCY"]) > 0) { $result = $value == $restriction["PARAMS"]["CURRENCY"]; if (!$result) { break; } } break; case '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByLocation': $fieldInFilter = self::isFieldInFilter2("LOCATION", $filter); $value = self::getFilterValue("LOCATION", $filter); if ($fieldInFilter && strlen($value) > 0 && $restriction['SERVICE_ID'] > 0) { try { $result = \Bitrix\Sale\Delivery\DeliveryLocationTable::checkConnectionExists(intval($restriction['SERVICE_ID']), $value, array('LOCATION_LINK_TYPE' => 'CODE')); } catch (\Bitrix\Sale\Location\Tree\NodeNotFoundException $e) { $result = false; } if ($result) { return true; } try { return \Bitrix\Sale\Delivery\DeliveryLocationTable::checkConnectionExists(intval($restriction['SERVICE_ID']), $value, array('LOCATION_LINK_TYPE' => 'ID')); } catch (\Bitrix\Sale\Location\Tree\NodeNotFoundException $e) { $result = false; } } break; default: break; } return $result; }