executeS($sql); Cache::store($cache_id, $carriers); } else { $carriers = Cache::retrieve($cache_id); } foreach ($carriers as $key => $carrier) { if (Module::isEnabled('postaldeliv') && $postcode != false && $id_country != false) { $postcode = Tools::strtoupper($postcode); $rules = Db::getInstance()->executeS(' SELECT * FROM `'._DB_PREFIX_.'postaldeliv` a LEFT JOIN `'._DB_PREFIX_.'postaldeliv_shop` b ON (b.`id_postaldeliv` = a.`id_postaldeliv`) WHERE a.`id_carrier`='.(int)$carrier['id_carrier'].' AND b.`id_shop`='.(int)Context::getContext()->shop->id); if ($rules) { $available_rules = array(); foreach ($rules as $rule) { $countries = explode(',', $rule['country']); if (in_array(0, $countries) || in_array($id_country, $countries)) { $available_rules[] = $rule; } } foreach ($available_rules as $rule) { $countries = explode(',', $rule['country']); if (in_array(0, $countries) || in_array($id_country, $countries)) { $in_postcode = in_array($postcode, explode(',', Tools::strtoupper($rule['postcode']))); $starts_with = Carrier::__startsWith( $postcode, explode(',', Tools::strtoupper($rule['county'])) ); $in_range = false; if ($ranges = unserialize($rule['range'])) { foreach ($ranges as $range) { if ($postcode >= $range[0] && $postcode <= $range[1]) { $in_range = true; } } } if (($rule['available'] == '0' && ($in_postcode || $starts_with || $in_range)) || ($rule['available'] == '1' && !$in_postcode && !$starts_with && !$in_range)) { unset($carriers[$key]['id_carrier']); } elseif ($carrier['name'] == '0') { $carriers[$key]['name'] = Carrier::getCarrierNameFromShopName(); } } else { if ($rule['available'] == '1') { unset($carriers[$key]['id_carrier']); } } } } } } return $carriers; } /** * Get available Carriers for Order * * @param int $id_zone Zone ID * @param array $groups Group of the Customer * @param Cart|null $cart Optional Cart object * @param array &$error Contains an error message if an error occurs * * @return array Carriers for the order * Modified for Postal Deliv */ /* * module: postaldeliv * date: 2019-09-16 16:20:11 * version: 2.1.10 */ public static function getCarriersForOrder($id_zone, $groups = null, $cart = null, &$error = array()) { $context = Context::getContext(); $id_lang = $context->language->id; if (is_null($cart)) { $cart = $context->cart; } if (isset($context->currency)) { $id_currency = $context->currency->id; } $postcode = ''; if (isset($context->cookie->postcode)) { $postcode = $context->cookie->postcode; $id_country = $context->cookie->id_country; } elseif (Tools::getIsset('id_address_delivery')) { $id_address = Tools::getValue('id_address_delivery'); $address = new Address((int)$id_address); $postcode = $address->postcode; $id_country = $address->id_country; } else { $id_address = $cart->id_address_delivery; $address = new Address((int)$id_address); $postcode = $address->postcode; $id_country = $address->id_country; } if (is_array($groups) && !empty($groups)) { $result = Carrier::getCarriers2( $id_lang, true, false, (int)$id_zone, $groups, self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE, $postcode, $id_country ); } else { $result = Carrier::getCarriers2( $id_lang, true, false, (int)$id_zone, array(Configuration::get('PS_UNIDENTIFIED_GROUP')), self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE, $postcode, $id_country ); } $results_array = array(); foreach ($result as $k => $row) { if (isset($row['id_carrier'])) { $carrier = new Carrier((int)$row['id_carrier']); $shipping_method = $carrier->getShippingMethod(); if ($shipping_method != Carrier::SHIPPING_METHOD_FREE) { if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false)) { $error[$carrier->id] = Carrier::SHIPPING_WEIGHT_EXCEPTION; unset($result[$k]); continue; } if (($shipping_method == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false)) { $error[$carrier->id] = Carrier::SHIPPING_PRICE_EXCEPTION; unset($result[$k]); continue; } if ($row['range_behavior']) { if (!$id_zone) { $id_zone = (int)Country::getIdZone(Country::getDefaultCountryId()); } if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && (!Carrier::checkDeliveryPriceByWeight( $row['id_carrier'], $cart->getTotalWeight(), $id_zone ))) { $error[$carrier->id] = Carrier::SHIPPING_WEIGHT_EXCEPTION; unset($result[$k]); continue; } if ($shipping_method == Carrier::SHIPPING_METHOD_PRICE && (!Carrier::checkDeliveryPriceByPrice( $row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $id_currency ))) { $error[$carrier->id] = Carrier::SHIPPING_PRICE_EXCEPTION; unset($result[$k]); continue; } } } $row['name'] = ((string)$row['name'] != '0' ? $row['name'] : Carrier::getCarrierNameFromShopName()); $row['price'] = (($shipping_method == Carrier::SHIPPING_METHOD_FREE) ? 0 : $cart->getPackageShippingCost((int)$row['id_carrier'], true, null, null, $id_zone)); $row['price_tax_exc'] = (($shipping_method == Carrier::SHIPPING_METHOD_FREE) ? 0 : $cart->getPackageShippingCost((int)$row['id_carrier'], false, null, null, $id_zone)); $row['img'] = file_exists(_PS_SHIP_IMG_DIR_.(int)$row['id_carrier'].'.jpg') ? _THEME_SHIP_DIR_.(int)$row['id_carrier'].'.jpg' : ''; if ($row['price'] === false) { unset($result[$k]); continue; } $results_array[] = $row; } } $prices = array(); if (Configuration::get('PS_CARRIER_DEFAULT_SORT') == Carrier::SORT_BY_PRICE) { foreach ($results_array as $r) { $prices[] = $r['price']; } if (Configuration::get('PS_CARRIER_DEFAULT_ORDER') == Carrier::SORT_BY_ASC) { array_multisort($prices, SORT_ASC, SORT_NUMERIC, $results_array); } else { array_multisort($prices, SORT_DESC, SORT_NUMERIC, $results_array); } } return $results_array; } }