コード例 #1
0
 public function run()
 {
     $this->init();
     $this->preProcess();
     if (Tools::getValue('ajax') == 'true') {
         if (Tools::getIsset('summary')) {
             if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) {
                 if (self::$cookie->id_customer) {
                     $customer = new Customer((int) self::$cookie->id_customer);
                     $groups = $customer->getGroups();
                 } else {
                     $groups = array(1);
                 }
                 if ((int) self::$cart->id_address_delivery) {
                     $deliveryAddress = new Address((int) self::$cart->id_address_delivery);
                 }
                 $result = array('carriers' => Carrier::getCarriersForOrder((int) Country::getIdZone((isset($deliveryAddress) and (int) $deliveryAddress->id) ? (int) $deliveryAddress->id_country : (int) Configuration::get('PS_COUNTRY_DEFAULT')), $groups));
             }
             $result['summary'] = self::$cart->getSummaryDetails();
             $result['customizedDatas'] = Product::getAllCustomizedDatas((int) self::$cart->id);
             $result['HOOK_SHOPPING_CART'] = Module::hookExec('shoppingCart', $result['summary']);
             $result['HOOK_SHOPPING_CART_EXTRA'] = Module::hookExec('shoppingCartExtra', $result['summary']);
             die(Tools::jsonEncode($result));
         } else {
             $this->includeCartModule();
         }
     } else {
         $this->setMedia();
         $this->displayHeader();
         $this->process();
         $this->displayContent();
         $this->displayFooter();
     }
 }
コード例 #2
0
 protected function _assignCarrier()
 {
     if (!$this->isLogged) {
         $carriers = Carrier::getCarriersForOrder(Country::getIdZone((int) Configuration::get('PS_COUNTRY_DEFAULT')));
         self::$smarty->assign(array('checked' => $this->_setDefaultCarrierSelection($carriers), 'carriers' => $carriers, 'default_carrier' => (int) Configuration::get('PS_CARRIER_DEFAULT'), 'HOOK_EXTRACARRIER' => NULL, 'HOOK_BEFORECARRIER' => Module::hookExec('beforeCarrier', array('carriers' => $carriers))));
     } else {
         parent::_assignCarrier();
     }
 }
コード例 #3
0
 public function getOrderShippingCostExternal($cart)
 {
     if (!$this->soapClientExists() || !$this->checkModuleAvailability()) {
         return false;
     }
     $disabled_countries_ids = DpdPolandCountry::getDisabledCountriesIDs();
     $id_country = (int) Tools::getValue('id_country');
     if (!$id_country) {
         $country = Address::getCountryAndState((int) $cart->id_address_delivery);
         $id_country = $country['id_country'];
     }
     if (!($id_method = self::getMethodIdByCarrierId($this->id_carrier))) {
         self::$carriers[$this->id_carrier] = false;
         return false;
     }
     if (!$id_country || in_array($id_country, $disabled_countries_ids) && $id_method == _DPDPOLAND_CLASSIC_ID_) {
         return false;
     }
     if ($id_country) {
         $zone = Country::getIdZone($id_country);
     } else {
         return false;
     }
     if (!$this->id_carrier) {
         return false;
     }
     if ($id_country == Country::getByIso(self::POLAND_ISO_CODE) && $id_method == _DPDPOLAND_CLASSIC_ID_ || $id_country != Country::getByIso(self::POLAND_ISO_CODE) && $id_method == _DPDPOLAND_STANDARD_COD_ID_ || $id_country != Country::getByIso(self::POLAND_ISO_CODE) && $id_method == _DPDPOLAND_STANDARD_ID_) {
         return false;
     }
     if (isset(self::$carriers[$this->id_carrier])) {
         return self::$carriers[$this->id_carrier];
     }
     $total_weight = self::convertWeight($cart->getTotalWeight());
     if (Configuration::get(DpdPolandConfiguration::PRICE_CALCULATION_TYPE) == DpdPolandConfiguration::PRICE_CALCULATION_PRESTASHOP) {
         $carrier = new Carrier($this->id_carrier);
         $price = $carrier->getDeliveryPriceByWeight($total_weight, $zone);
         self::$carriers[$this->id_carrier] = $price;
         return self::$carriers[$this->id_carrier];
     }
     $price = DpdPolandCSV::getPrice($total_weight, $id_method, $cart);
     if ($price === false) {
         return false;
     }
     $id_currency_pl = Currency::getIdByIsoCode(_DPDPOLAND_CURRENCY_ISO_, (int) $this->context->shop->id);
     $currency_from = new Currency((int) $id_currency_pl);
     $currency_to = $this->context->currency;
     self::$carriers[$this->id_carrier] = Tools::convertPriceFull($price, $currency_from, $currency_to);
     return self::$carriers[$this->id_carrier];
 }
コード例 #4
0
 protected function _processCarrier()
 {
     self::$cart->recyclable = (int) Tools::getValue('recyclable');
     self::$cart->gift = (int) Tools::getValue('gift');
     if ((int) Tools::getValue('gift')) {
         if (!Validate::isMessage($_POST['gift_message'])) {
             $this->errors[] = Tools::displayError('Invalid gift message');
         } else {
             self::$cart->gift_message = strip_tags($_POST['gift_message']);
         }
     }
     if (isset(self::$cookie->id_customer) and self::$cookie->id_customer) {
         $address = new Address((int) self::$cart->id_address_delivery);
         if (!($id_zone = Address::getZoneById($address->id))) {
             $this->errors[] = Tools::displayError('No zone match with your address');
         }
     } else {
         $id_zone = Country::getIdZone((int) Configuration::get('PS_COUNTRY_DEFAULT'));
     }
     if (Validate::isInt(Tools::getValue('id_carrier')) and sizeof(Carrier::checkCarrierZone((int) Tools::getValue('id_carrier'), (int) $id_zone))) {
         self::$cart->id_carrier = (int) Tools::getValue('id_carrier');
     } elseif (!self::$cart->isVirtualCart() and (int) Tools::getValue('id_carrier') != 0) {
         $this->errors[] = Tools::displayError('Invalid carrier or no carrier selected');
     }
     Module::hookExec('processCarrier', array('cart' => self::$cart));
     return self::$cart->update();
 }
コード例 #5
0
 public function getCarriersListByIdZone($id_country, $id_state = 0, $zipcode = 0)
 {
     global $cart, $smarty, $cookie;
     // cookie saving/updating
     $cookie->id_country = $id_country;
     if ($id_state != 0) {
         $cookie->id_state = $id_state;
     }
     if ($zipcode != 0) {
         $cookie->postcode = $zipcode;
     }
     $id_zone = 0;
     if ($id_state != 0) {
         $id_zone = State::getIdZone($id_state);
     }
     if (!$id_zone) {
         $id_zone = Country::getIdZone($id_country);
     }
     $carriers = Carrier::getCarriersForOrder((int) $id_zone);
     return sizeof($carriers) ? $carriers : array();
 }
コード例 #6
0
 /**
  * creates of a dejala carrier corresponding to $dejalaProduct
  */
 public static function createDejalaCarrier($dejalaConfig)
 {
     // MFR091130 - get id zone from the country used in the module (if the store zones were customized) - default is 1 (Europe)
     $id_zone = 1;
     $moduleCountryIsoCode = strtoupper($dejalaConfig->country);
     $countryID = Country::getByIso($moduleCountryIsoCode);
     if ((int) $countryID) {
         $id_zone = Country::getIdZone($countryID);
     }
     //TODO Will have to review this and apply proper code.
     $trg_id = 1;
     /*$vatRate = "19.6";
     		// MFR091130 - get or create the tax & attach it to our zone if needed
     		$id_tax = Tax::getTaxIdByRate((float)$vatRate);
     		$trg_id = 0;
     		if (!$id_tax)
     		{
     			$tax = new Tax();
     			$tax->rate = $vatRate;
     			$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
     			$tax->name[$defaultLanguage] = $tax->rate . '%';
     			$tax->add();
     			$id_tax = $tax->id;
     
     			$trg = new TaxRulesGroup();
     			$trg->name = 'Dejala '.$tax->name[$defaultLanguage];
     			$trg->active = 1;
     			if ($trg->save())
     			{
     				$trg_id = $trg->id;
     
     				$tr = new TaxRule();
     				$tr->id_tax_rules_group = $trg_id;
     				$tr->id_country = (int) $countryID;
     				$tr->id_state = 0;
     				$tr->id_tax = (int)$tax->id;				
     				$tr->state_behavior = 0;
     				$tr->save();
     			}
     		}*/
     $carrier = new Carrier();
     $carrier->name = 'dejala';
     $carrier->id_tax_rules_group = (int) $trg_id;
     $carrier->url = 'http://tracking.dejala.' . $dejalaConfig->country . '/tracker/@';
     $carrier->active = true;
     $carrier->deleted = 0;
     $carrier->shipping_handling = false;
     $carrier->range_behavior = 0;
     $carrier->is_module = 1;
     $carrier->external_module_name = 'dejala';
     $carrier->shipping_external = 1;
     $carrier->need_range = 0;
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         $carrier->delay[$language['id_lang']] = 'Dejala';
     }
     $carrier->add();
     $carrier->addZone((int) $id_zone);
     /*$sql = 'INSERT INTO `'._DB_PREFIX_.'carrier_zone` (`id_carrier` , `id_zone`) VALUES ('.(int)($carrier->id).', ' . (int)($id_zone) . ')';
     		Db::getInstance()->Execute($sql);
     
     		$rangeW = new RangeWeight();
     		$rangeW->id_carrier = $carrier->id;
     		$rangeW->delimiter1 = 0;
     		$rangeW->delimiter2 = $dejalaProduct['max_weight'];
     		$rangeW->add();
     		$vat_factor = (1+ ($dejalaProduct['vat'] / 100));
     		$priceTTC = round(($dejalaProduct['price']*$vat_factor) + $dejalaProduct['margin'], 2);
     		$priceHT = round($priceTTC/$vat_factor, 2);
     		$priceList = '(NULL'.','.$rangeW->id.','.$carrier->id.','.$id_zone.','.$priceHT.')';
     		$carrier->addDeliveryPrice($priceList);*/
     return true;
 }
コード例 #7
0
ファイル: Tax.php プロジェクト: Bruno-2M/prestashop
 public static function getApplicableTax($id_tax, $productTax, $id_address_delivery = NULL)
 {
     global $cart, $cookie, $defaultCountry;
     if (!$id_address_delivery) {
         $id_address_delivery = intval((Validate::isLoadedObject($cart) and $cart->id_address_delivery) ? $cart->id_address_delivery : (isset($cookie->id_address_delivery) ? $cookie->id_address_delivery : 0));
     }
     /* If customer has an address (implies that he is registered and logged) */
     if ($id_address_delivery and $address_ids = Address::getCountryAndState($id_address_delivery)) {
         $id_zone_country = Country::getIdZone(intval($address_ids['id_country']));
         /* If customer's invoice address is inside a state */
         if ($address_ids['id_state']) {
             $state = new State(intval($address_ids['id_state']));
             if (!Validate::isLoadedObject($state)) {
                 die(Tools::displayError());
             }
             /* Return tax value depending to the tax behavior */
             $tax_behavior = intval($state->tax_behavior);
             if ($tax_behavior == PS_PRODUCT_TAX) {
                 return $productTax * Tax::zoneHasTax(intval($id_tax), intval($id_zone_country));
             }
             if ($tax_behavior == PS_STATE_TAX) {
                 return Tax::getRateByState(intval($address_ids['id_state']));
             }
             if ($tax_behavior == PS_BOTH_TAX) {
                 return $productTax * Tax::zoneHasTax(intval($id_tax), intval($id_zone_country)) + Tax::getRateByState(intval($address_ids['id_state']));
             }
             /* Unknown behavior */
             die(Tools::displayError('Unknown tax behavior!'));
         }
         /* Else getting country zone tax */
         if (!($id_zone = Address::getZoneById($id_address_delivery))) {
             die(Tools::displayError());
         }
         return $productTax * Tax::zoneHasTax(intval($id_tax), intval($id_zone));
     }
     /* Default tax application */
     if (!Validate::isLoadedObject($defaultCountry)) {
         die(Tools::displayError());
     }
     return $productTax * Tax::zoneHasTax(intval($id_tax), intval($defaultCountry->id_zone));
 }
コード例 #8
0
ファイル: dpdgroup.php プロジェクト: remixaz/dpdgroup
 public function getOrderShippingCostExternal($cart, $products = array())
 {
     if (!$this->id_carrier || !$cart instanceof Cart) {
         return false;
     }
     $cache_key = $this->getCacheKey($cart, $products);
     if (isset(self::$carriers[$this->id_carrier][$cache_key])) {
         return self::$carriers[$this->id_carrier][$cache_key];
     }
     $id_address_delivery = empty($products) ? (int) $cart->id_address_delivery : (int) $this->getIdAddressDeliveryByProducts($products);
     $id_customer_country = (int) Tools::getValue('id_country');
     if (!$id_customer_country) {
         $customer_country = Address::getCountryAndState((int) $id_address_delivery);
         $id_customer_country = (int) $customer_country['id_country'];
     }
     $zone = $id_customer_country ? Country::getIdZone((int) $id_customer_country) : Address::getZoneById((int) $id_address_delivery);
     if (!($id_method = self::getMethodIdByCarrierId($this->id_carrier))) {
         self::$carriers[$this->id_carrier][$cache_key] = false;
         return false;
     }
     $carrier = new Carrier((int) $this->id_carrier);
     if (!Validate::isLoadedObject($carrier)) {
         return false;
     }
     $configuration = new DpdGroupConfiguration();
     $is_cod_method = $this->isCODCarrier((int) $this->id_carrier);
     if ($is_cod_method && !$this->isCODCarrierAvailable($cart, $configuration, (int) $id_customer_country)) {
         self::$carriers[$this->id_carrier][$cache_key] = false;
         return false;
     }
     $carrier_shipping_method = $carrier->getShippingMethod();
     $order_total_price = empty($products) ? $cart->getOrderTotal(false, Cart::BOTH_WITHOUT_SHIPPING) : $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $products, $this->id_carrier);
     $total_weight = empty($products) ? $cart->getTotalWeight() : $cart->getTotalWeight($products);
     $cart_total = $carrier_shipping_method == Carrier::SHIPPING_METHOD_WEIGHT ? DpdGroupShipment::convertWeight($total_weight) : $order_total_price;
     $price_rule = DpdGroupShipment::getPriceRule($cart_total, $id_method, $id_address_delivery, $is_cod_method);
     $additional_shipping_cost = $this->calculateAdditionalShippingCost($cart, $products);
     $additional_shipping_cost = Tools::convertPrice($additional_shipping_cost);
     $handling_charges = $carrier->shipping_handling ? Configuration::get('PS_SHIPPING_HANDLING') : 0;
     $handling_charges = Tools::convertPrice($handling_charges);
     $price = false;
     switch ($configuration->price_calculation_method) {
         case DpdGroupConfiguration::PRICE_CALCULATION_PRESTASHOP:
             $price = $this->getPriceByPrestaShopCalculationType($carrier_shipping_method, $carrier, $total_weight, $zone, $additional_shipping_cost, $handling_charges, $is_cod_method, $order_total_price, $configuration, $price_rule);
             break;
         case DpdGroupConfiguration::PRICE_CALCULATION_WEB_SERVICES:
             $price = $this->getPriceByWebServicesCalculationType($cart, $is_cod_method, $order_total_price, $id_method, $id_address_delivery, $additional_shipping_cost, $handling_charges, $configuration, $price_rule, $products);
             break;
         case DpdGroupConfiguration::PRICE_CALCULATION_CSV:
             $price = $this->getPriceByCSVCalculationType($price_rule, $order_total_price, $additional_shipping_cost, $handling_charges, $is_cod_method, $configuration);
             break;
     }
     self::$carriers[$this->id_carrier][$cache_key] = $price;
     return self::$carriers[$this->id_carrier][$cache_key];
 }
コード例 #9
0
    function getZoneByStateOrCountry($id_country, $id_state)
    {
        global $defaultCountry;
        if (!isset($id_country) or intval($id_country) <= 0) {
            $id_country = $defaultCountry->id;
        }
        $id_zone = 0;
        if (isset($id_state) and intval($id_state) > 0) {
            $result = Db::getInstance()->getRow('
		    SELECT `id_zone`
		    FROM `' . _DB_PREFIX_ . 'state`
		    WHERE `id_state` = ' . intval($id_state));
            $id_zone = $result['id_zone'];
        }
        if (!isset($id_zone) or intval($id_zone) <= 0) {
            $id_zone = Country::getIdZone($id_country);
        }
        return $id_zone;
    }
コード例 #10
0
 protected function getCustomerInfo($id_zone, $dest_zip, $dest_country, $dest_city, $cart)
 {
     $cookie_zip = $this->context->cookie->postcode ? $this->context->cookie->postcode : $this->context->cookie->pc_dest_zip;
     $cookie_country = $this->context->cookie->id_country ? $this->context->cookie->id_country : $this->context->cookie->pc_dest_country;
     // Check if customer is logged in, and cart has an address selected.
     if ($cart->id_address_delivery > 0 && $this->context->customer->logged) {
         $address = new Address(intval($cart->id_address_delivery));
         if (!Validate::isLoadedObject($address)) {
             $id_address = Address::getFirstCustomerAddressId($cart->id_customer, true);
             if ($id_address > 0) {
                 $address = new Address(intval($id_address));
             }
             if (!Validate::isLoadedObject($address)) {
                 return false;
             }
         }
         if ($dest_zip == "") {
             $dest_zip = $address->postcode;
         }
         $country = new Country($address->id_country);
         if ($dest_country == "") {
             $dest_country = $country->iso_code;
         }
         if ($dest_city == "") {
             $dest_city = $address->city;
         }
     } else {
         if ($dest_zip == "" && $cookie_zip) {
             $dest_zip = $cookie_zip;
             $dest_city = $this->context->cookie->pc_dest_city;
         } else {
             if ($dest_zip == "" && $this->_dhl_address_display['zip'] == 1) {
                 return false;
             }
         }
         if ($dest_country == "" && $cookie_country) {
             $dest_country = $cookie_country;
             $country = new Country($dest_country);
             $dest_country = $country->iso_code;
         }
     }
     if ((int) $id_zone == 0) {
         $id_country = $cookie_country;
         if ((int) $id_country > 0) {
             $id_zone = Country::getIdZone($id_country);
         }
         if ((int) $id_country == 0 or (int) $id_zone == 0) {
             return false;
         }
     }
     return array('dest_zip' => $dest_zip, 'dest_country' => $dest_country, 'dest_city' => $dest_city, 'id_zone' => $id_zone);
 }
コード例 #11
0
	/**
	 *
	 * @param int $id_zone
	 * @param Array $groups group of the customer
	 * @return Array
	 */
	public static function getCarriersForOrder($id_zone, $groups = null, $cart = null)
	{
		
		$context = Context::getContext();
		$id_lang = $context->language->id;
		if (is_null($cart))
			$cart = $context->cart;
		$id_currency = $context->currency->id;

		if (is_array($groups) && !empty($groups))
			$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, $groups, self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
		else
			$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, array(Configuration::get('PS_UNIDENTIFIED_GROUP')), self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
		$results_array = array();
                
               // var_dump($result);
		foreach ($result as $k => $row)
		{
			$carrier = new Carrier((int)$row['id_carrier']);
			$shipping_method = $carrier->getShippingMethod();
			if ($shipping_method != Carrier::SHIPPING_METHOD_FREE)
			{
				// Get only carriers that are compliant with shipping method
				if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false)
					|| ($shipping_method == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false))
				{
					unset($result[$k]);
					continue;
				}

				// If out-of-range behavior carrier is set on "Desactivate carrier"
				if ($row['range_behavior'])
				{
					// Get id zone
					if (!$id_zone)
							$id_zone = Country::getIdZone(Country::getDefaultCountryId());

					// Get only carriers that have a range compatible with cart
					if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT
						&& (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone)))
						|| ($shipping_method == Carrier::SHIPPING_METHOD_PRICE
						&& (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $id_currency))))
					{
						unset($result[$k]);
						continue;
					}
				}
			}

			$row['name'] = (strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME'));
			$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 price is false, then the carrier is unavailable (carrier module)
			if ($row['price'] === false)
			{
                            $row['price'] = 0;
//				unset($result[$k]);
//				continue;
			}

			//Проверка, если способ доставки - DP, то этот способ доставки доступен, если в корзине только книги
			$log = '';
			$DeutschePostCarrierName = "Deutsche Post"; //название службы доставки "Deutsche post"
			
			$books_cat_ru_name = "Книги";
			$parent_for_books_cat_id = 2;
			$books_KNIGI_lang = 1;

			if ($row['name'] == $DeutschePostCarrierName) {
				//echo "поиск категории Книги";
				$bookscat = Category::searchByNameAndParentCategoryId($books_KNIGI_lang,$books_cat_ru_name,$parent_for_books_cat_id);
				//var_dump($bookscat);
				$books_cat_id = $bookscat["id_category"];
				/*
				id_category"]=> string(1) "3" ["id_parent"]=> string(1) "2" ["id_shop_default"]=> string(1) "1" ["level_depth"]=> string(1) "2" ["nleft"]=> string(1) "3" ["nright"]=> string(3) "102" ["active"]=> string(1) "1" ["date_add"]=> string(19) "2015-02-19 21:05:41" ["date_upd"]=> string(19) "2015-02-19 21:05:41" ["position"]=> string(1) "0" ["is_root_category"]=> string(1) "0" ["id_shop"]=> string(1) "1" ["id_lang"]=> string(1) "1" ["name"]=> string(10) "Книги" ["description"]=> string(0) "" ["link_rewrite"]=> string(5) "knigi" ["meta_title"]=> string(0) "" ["meta_keywords"]=> string(0) "" ["meta_description"]=> string(0) "" }

				*/
				/*
				$books_cat_id = 12; //id категории книги
				$BooksCategory = new Category($books_cat_id);
				$interval = $BooksCategory->getInterval($books_cat_id);
				
				$books_nleft = $interval['nleft'];//21;
				$books_nright = $interval['nright'];//134;
				*/
				$books_nleft = $bookscat["nleft"];
				$books_nright = $bookscat["nright"];
				$cart_products = $cart->getProducts();
				if (!empty($cart_products))
				{ 
					$all_books = true;
					foreach ($cart_products as $key => $cart_product)
					{
						$product = new Product($cart_product['id_product']);
						$categories = $product->getCategories();
						//var_dump($categories);
						if (!empty($categories))
						{
							$product_is_book = false;
							foreach ($categories as $key => $category) 
							{
								//echo $category;
								if ($category == $books_cat_id)
								{
									$product_is_book = true;
									//echo "это в самих книгах";
									break;
								}

								/*искать родителей до рута. если id родителя любого уровня = $books_cat_id, значить это книги*/
								//echo "nleft ".$books_nleft;
								//echo "nright ".$books_nright;
								//echo "<br/><br/>";
								$current_cat_id = $category;
								while (1)
								{
									$current_cat = new Category($current_cat_id);
									//var_dump($current_cat->id_parent);
									if ($current_cat->is_root_category == 1){
										//echo "это корневая категория";
										break;
									}
									if ($current_cat->id_parent == $books_cat_id)
									{
										$product_is_book = true;
										//echo " это книга";
										break;
									}
									$current_cat_id = $current_cat->id_parent;
									
								}
								
								
								if ($category >= $books_nleft AND $category <= $books_nright)
								{
									$product_is_book = true;
									//echo " это книга";
									break;
								}
								//echo " не книга";
							}
						}
						if (!$product_is_book) {
							$all_books = false;
							break;
						}
					}
					if (!$all_books){
						unset($result[$k]);
						continue;
					}
				}
				
			}
			//Конец проверки

			$results_array[] = $row;
		}


		// if we have to sort carriers by price
		$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;
	}
コード例 #12
0
 /**
  * Checks if a Dejala carrier already exists
  */
 public static function carrierExists($dejalaConfig)
 {
     global $cookie;
     $id_zone = 1;
     $moduleCountryIsoCode = strtoupper($dejalaConfig->country);
     $countryID = Country::getByIso($moduleCountryIsoCode);
     if (intval($countryID)) {
         $id_zone = Country::getIdZone($countryID);
     }
     $allCarriers = DejalaCarrierUtils::getCarriers(intval($cookie->id_lang), true, false, $id_zone, true);
     foreach ($allCarriers as $carrier) {
         if ($carrier['name'] == 'dejala' && $carrier['is_module'] == true) {
             return true;
         }
     }
     return false;
 }
コード例 #13
0
 /**
  * gets of a dejala carrier corresponding to $dejalaProduct
  */
 public static function getDejalaCarrier($dejalaConfig, $dejalaProduct)
 {
     global $cookie;
     $electedCarrier = NULL;
     $totalCartWeight = floatval($dejalaProduct['max_weight']);
     if ($totalCartWeight <= 0) {
         $totalCartWeight = 3.99;
     } else {
         $totalCartWeight -= 0.01;
     }
     /** MFR090828 - compare to HT price (since DejalaCarrier has a tax_id) */
     $vat_factor = 1 + $dejalaProduct['vat'] / 100;
     $priceTTC = round($dejalaProduct['price'] * $vat_factor + $dejalaProduct['margin'], 2);
     $priceHT = round($priceTTC / $vat_factor, 2);
     $productPrice = $priceHT;
     // MFR091130 - get id zone from the country used in the module (if the store zones were customized)
     // default (Europe)
     $id_zone = 1;
     $moduleCountryIsoCode = strtoupper($dejalaConfig->country);
     $countryID = Country::getByIso($moduleCountryIsoCode);
     if (intval($countryID)) {
         $id_zone = Country::getIdZone($countryID);
     }
     $allCarriers = DejalaCarrierUtils::getCarriers(intval($cookie->id_lang), true, false, $id_zone, true);
     $electedCarrier = NULL;
     foreach ($allCarriers as $carrier) {
         if ($carrier['name'] == 'dejala' && $carrier['range_behavior'] && Configuration::get('PS_SHIPPING_METHOD') && Carrier::checkDeliveryPriceByWeight($carrier['id_carrier'], $totalCartWeight, $id_zone)) {
             $mCarrier = new Carrier($carrier['id_carrier']);
             if ($productPrice == $mCarrier->getDeliveryPriceByWeight($totalCartWeight, $id_zone)) {
                 if ($electedCarrier == NULL) {
                     $electedCarrier = $mCarrier;
                 } else {
                     if ($mCarrier->id < $electedCarrier->id) {
                         $electedCarrier = $mCarrier;
                     }
                 }
             }
         }
     }
     return $electedCarrier;
 }
コード例 #14
0
ファイル: payu.php プロジェクト: bonekost/plugin_prestashop
 /**
  * @param $iso_country_code
  * @return null|string
  */
 public function shippingCostRetrieveRequest($iso_country_code)
 {
     if ($iso_country_code) {
         $cart = new Cart($this->id_cart);
         if ($id_country = Country::getByIso($iso_country_code)) {
             if ($id_zone = Country::getIdZone($id_country)) {
                 $carriers = Carrier::getCarriersForOrder($id_zone);
                 $currency = Currency::getCurrency($cart->id_currency);
                 if ($carriers) {
                     $carrier_list = array();
                     foreach ($carriers as $carrier) {
                         $c = new Carrier((int) $carrier['id_carrier']);
                         $shipping_method = $c->getShippingMethod();
                         $price = $shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int) $carrier['id_carrier']);
                         $price_tax_exc = $shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int) $carrier['id_carrier'], false);
                         $carrier_list[]['ShippingCost'] = array('Type' => $carrier['name'] . ' (' . $carrier['id_carrier'] . ')', 'CountryCode' => Tools::strtoupper($iso_country_code), 'Price' => array('Gross' => $this->toAmount($price), 'Net' => $this->toAmount($price_tax_exc), 'Tax' => $this->toAmount($price) - $this->toAmount($price_tax_exc), 'CurrencyCode' => Tools::strtoupper($currency['iso_code'])));
                     }
                     $shipping_cost = array('CountryCode' => Tools::strtoupper($iso_country_code), 'ShipToOtherCountry' => 'true', 'ShippingCostList' => $carrier_list);
                     $xml = OpenPayU::buildShippingCostRetrieveResponse($shipping_cost, $this->id_request, $iso_country_code);
                     return $xml;
                 } else {
                     Logger::addLog('carrier by id_zone is undefined');
                 }
             }
         }
     }
     return null;
 }
コード例 #15
0
 public function startImport()
 {
     global $cookie;
     @ini_set('max_execution_time', 0);
     ini_set('memory_limit', '256M');
     self::$_exportStartTime = time();
     $this->_header = self::$_serviceData['header'] == 1;
     self::$_sef = (int) Configuration::get('PS_REWRITING_SETTINGS');
     self::$_exportStore = (int) self::$_serviceData['id_store'];
     self::$_exportShop = (int) self::$_serviceData['id_shop'];
     self::$_exportGroup = (int) self::$_serviceData['id_group'];
     self::$_exportLanguage = (int) self::$_serviceData['id_lang'];
     self::$_carrierId = (int) self::$_serviceData['id_carrier'];
     self::$_carrierTax = self::getShippingTax(self::$_carrierId);
     $carrier = new Carrier((int) self::$_carrierId);
     self::$_carrierMethod = $carrier->getShippingMethod();
     self::$_exportCountry = (int) self::$_serviceData['id_country'];
     self::$_exportCurrency = (int) self::getCurrencyByCountry(self::$_exportCountry);
     self::$_exportState = (int) self::$_serviceData['id_state'];
     self::$_exportCondition = self::$_serviceData['condition'];
     self::$_zone = Country::getIdZone(self::$_exportCountry);
     self::$_billingMode = (int) Configuration::get('PS_SHIPPING_METHOD');
     self::$_shippingCarrierData = self::getCarrierShippingRanges();
     self::$_existingPictures = self::getExistingPictures();
     self::$_existingCategories = self::getExistingCategories(self::$_exportLanguage);
     self::$_specificPrices = self::getSpecificPrices(self::$_exportShop);
     self::$_productPriorities = self::getProductsPriorities();
     self::$_taxRates = self::getTaxes();
     self::$_exportCategories = MoussiqFreeService::getCategories($this->service_id);
     self::$_productCategories = self::getProductCategories();
     self::$_exportLanguageObj = new Language(self::$_exportLanguage);
     if (self::$_exportCurrency == 0) {
         self::$_exportCurrency = (int) Configuration::get('PS_CURRENCY_DEFAULT');
     }
     if (sizeof(self::$_productCategories)) {
         $chunk_size = 3000;
         $current_size = 0;
         $this->beforeImport(self::$_serviceData['template'], array());
         do {
             $products = self::getProducts(self::$_exportLanguage, $current_size, $chunk_size, 'date_add', 'ASC', false, self::$_serviceData['export_inactive'] == true ? false : true, self::$_exportCountry, self::$_exportShop, self::$_exportCondition);
             $current_size += $chunk_size;
             $fileName = $this->filename;
             $fileDir = dirname(__FILE__) . '/../export/';
             if (!self::checkDir($fileDir)) {
                 $this->_errors[] = Tools::displayError('The directory is not writeable');
                 return false;
             }
             foreach ($products as $product) {
                 if (array_key_exists($product['id_product'], self::$_productCategories)) {
                     $product['categories'] = self::$_productCategories[$product['id_product']];
                     $product['reduction'] = self::getProductSpecificPrice($product['id_product'], self::$_exportStore, Configuration::get('PS_CURRENCY_DEFAULT'), self::$_exportCountry, self::$_exportGroup);
                     $product['quantity'] = (int) StockAvailable::getQuantityAvailableByProduct($product['id_product'], null, self::$_exportShop);
                     //to fix, get cover id_image
                     $product['id_image'] = self::getProductCoverWs($product['id_product']);
                     $product['id_product_image'] = $product['id_product'];
                     $features = self::collectFeatures(self::$_exportLanguage, $product['id_product']);
                     if (is_array($features)) {
                         foreach ($features as $id_feature => $feature) {
                             $product['ft' . $id_feature] = trim($feature);
                         }
                     }
                     $this->addProductLine($product, self::$_serviceData['template']);
                 }
             }
         } while ($chunk_size == count($products));
         $this->postProcess();
         return $this->saveFile();
     }
 }
コード例 #16
0
ファイル: Carrier.php プロジェクト: Evil1991/PrestaShop-1.4
 /**
  * @param int $id_country
  * @param array $groups
  * @return Array carriers list
  * @deprecated
  */
 public static function getCarriersOpc($id_country, $groups = null)
 {
     Tools::displayAsDeprecated();
     return self::getCarriersForOrder((int) Country::getIdZone((int) $id_country), $groups);
 }
コード例 #17
0
ファイル: carriercompare.php プロジェクト: jicheng17/pengwine
 public function getCarriersListByIdZone($id_country, $id_state = 0, $zipcode = 0)
 {
     // cookie saving/updating
     $this->context->cookie->id_country = $id_country;
     if ($id_state != 0) {
         $this->context->cookie->id_state = $id_state;
     }
     if ($zipcode != 0) {
         $this->context->cookie->postcode = $zipcode;
     }
     $id_zone = 0;
     if ($id_state != 0) {
         $id_zone = State::getIdZone($id_state);
     }
     if (!$id_zone) {
         $id_zone = Country::getIdZone($id_country);
     }
     // Need to set the infos for carrier module !
     $this->context->cookie->id_country = $id_country;
     $this->context->cookie->id_state = $id_state;
     $this->context->cookie->postcode = $zipcode;
     $carriers = Carrier::getCarriersForOrder((int) $id_zone);
     return sizeof($carriers) ? $carriers : array();
 }
コード例 #18
0
	/**
	 *
	 * @param int $id_zone
	 * @param Array $groups group of the customer
	 * @return Array
	 */
	public static function getCarriersForOrder($id_zone, $groups = null, $cart = null)
	{
		$context = Context::getContext();
		$id_lang = $context->language->id;
		if (is_null($cart))
			$cart = $context->cart;
		$id_currency = $context->currency->id;

		if (is_array($groups) && !empty($groups))
			$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, $groups, self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
		else
			$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, array(Configuration::get('PS_UNIDENTIFIED_GROUP')), self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
		$results_array = array();
                
		foreach ($result as $k => $row)
		{
			$carrier = new Carrier((int)$row['id_carrier']);
			$shipping_method = $carrier->getShippingMethod();
			if ($shipping_method != Carrier::SHIPPING_METHOD_FREE)
			{
				// Get only carriers that are compliant with shipping method
				if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false)
					|| ($shipping_method == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false))
				{
					unset($result[$k]);
					continue;
				}

				// If out-of-range behavior carrier is set on "Desactivate carrier"
				if ($row['range_behavior'])
				{
					// Get id zone
					if (!$id_zone)
							$id_zone = Country::getIdZone(Country::getDefaultCountryId());

					// Get only carriers that have a range compatible with cart
					if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT
						&& (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone)))
						|| ($shipping_method == Carrier::SHIPPING_METHOD_PRICE
						&& (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $id_currency))))
					{
						unset($result[$k]);
						continue;
					}
				}
			}

			$row['name'] = (strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME'));
			$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 price is false, then the carrier is unavailable (carrier module)
			if ($row['price'] === false)
			{
                            $row['price'] = 0;
//				unset($result[$k]);
//				continue;
			}

			//Проверка, если способ доставки - DP, то этот способ доставки доступен, если в корзине только книги
			$DeutschePostCarrierName = "Deutsche Post"; //название службы доставки "Deutsche post"
			$books_cat_id = 12; //id категории книги
			if ($row['name'] == $DeutschePostCarrierName) {
				$cart_products = $cart->getProducts();
				if (!empty($cart_products))
				{
					$all_books = true;
					foreach ($cart_products as $key => $cart_product)
					{
						$product = new Product($cart_product['id_product']);
						$categories = $product->getCategories();
						if (!empty($categories))
						{
							$product_is_book = false;
							foreach ($categories as $key => $category) 
							{
								$log .= "категория = ".var_export($category,true)."; ";
								if ($category == $books_cat_id)
								{
									$product_is_book = true;
									break;
								}
							}
						}
						if (!$product_is_book) {
							$all_books = false;
							break;
						}
					}
					if (!$all_books){
						unset($result[$k]);
						continue;
					}
				}
				
			}
			//Конец проверки

			$results_array[] = $row;
		}
		file_put_contents($log_file, $log);

		// if we have to sort carriers by price
		$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;
	}
コード例 #19
0
 public function getCarriersListByIdZone($id_country, $id_state = 0)
 {
     global $cart, $smarty;
     $id_zone = 0;
     if ($id_state != 0) {
         $id_zone = State::getIdZone($id_state);
     }
     if (!$id_zone) {
         $id_zone = Country::getIdZone($id_country);
     }
     $carriers = Carrier::getCarriersForOrder((int) $id_zone);
     return sizeof($carriers) ? $carriers : array();
 }
コード例 #20
0
 protected function _processCarrier()
 {
     $this->context->cart->recyclable = (int) Tools::getValue('recyclable');
     $this->context->cart->gift = (int) Tools::getValue('gift');
     if ((int) Tools::getValue('gift')) {
         if (!Validate::isMessage($_POST['gift_message'])) {
             $this->errors[] = Tools::displayError('Invalid gift message.');
         } else {
             $this->context->cart->gift_message = strip_tags($_POST['gift_message']);
         }
     }
     if (isset($this->context->customer->id) && $this->context->customer->id) {
         $address = new Address((int) $this->context->cart->id_address_delivery);
         if (!($id_zone = Address::getZoneById($address->id))) {
             $this->errors[] = Tools::displayError('No zone matches your address.');
         }
     } else {
         $id_zone = Country::getIdZone((int) Configuration::get('PS_COUNTRY_DEFAULT'));
     }
     if (Tools::getIsset('delivery_option')) {
         if ($this->validateDeliveryOption(Tools::getValue('delivery_option'))) {
             $this->context->cart->setDeliveryOption(Tools::getValue('delivery_option'));
         }
     } elseif (Tools::getIsset('id_carrier')) {
         // For retrocompatibility reason, try to transform carrier to an delivery option list
         $delivery_option_list = $this->context->cart->getDeliveryOptionList();
         if (count($delivery_option_list) == 1) {
             $delivery_option = reset($delivery_option_list);
             $key = Cart::desintifier(Tools::getValue('id_carrier'));
             foreach ($delivery_option_list as $id_address => $options) {
                 if (isset($options[$key])) {
                     $this->context->cart->id_carrier = (int) Tools::getValue('id_carrier');
                     $this->context->cart->setDeliveryOption(array($id_address => $key));
                     if (isset($this->context->cookie->id_country)) {
                         unset($this->context->cookie->id_country);
                     }
                     if (isset($this->context->cookie->id_state)) {
                         unset($this->context->cookie->id_state);
                     }
                 }
             }
         }
     }
     Hook::exec('actionCarrierProcess', array('cart' => $this->context->cart));
     if (!$this->context->cart->update()) {
         return false;
     }
     // Carrier has changed, so we check if the cart rules still apply
     CartRule::autoRemoveFromCart($this->context);
     CartRule::autoAddToCart($this->context);
     return true;
 }
コード例 #21
0
 public function getCarriersListByIdZone($id_country, $id_state = 0, $zipcode = 0)
 {
     // cookie saving/updating
     $this->context->cookie->id_country = $id_country;
     if ($id_state != 0) {
         $this->context->cookie->id_state = $id_state;
     }
     if ($zipcode != 0) {
         $this->context->cookie->postcode = $zipcode;
     }
     $id_zone = 0;
     if ($id_state != 0) {
         $id_zone = State::getIdZone($id_state);
     }
     if (!$id_zone) {
         $id_zone = Country::getIdZone($id_country);
     }
     $carriers = CarrierCompare::getCarriersByCountry($id_country, $id_state, $zipcode, $this->context->cart, $this->context->customer->id);
     return sizeof($carriers) ? $carriers : array();
 }
コード例 #22
0
ファイル: Carrier.php プロジェクト: M03G/PrestaShop
 /**
  * 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
  */
 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;
     }
     if (is_array($groups) && !empty($groups)) {
         $result = Carrier::getCarriers($id_lang, true, false, (int) $id_zone, $groups, self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
     } else {
         $result = Carrier::getCarriers($id_lang, true, false, (int) $id_zone, array(Configuration::get('PS_UNIDENTIFIED_GROUP')), self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
     }
     $results_array = array();
     foreach ($result as $k => $row) {
         $carrier = new Carrier((int) $row['id_carrier']);
         $shipping_method = $carrier->getShippingMethod();
         if ($shipping_method != Carrier::SHIPPING_METHOD_FREE) {
             // Get only carriers that are compliant with shipping method
             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 out-of-range behavior carrier is set to "Deactivate carrier"
             if ($row['range_behavior']) {
                 // Get id zone
                 if (!$id_zone) {
                     $id_zone = (int) Country::getIdZone(Country::getDefaultCountryId());
                 }
                 // Get only carriers that have a range compatible with cart
                 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'] = strval($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 price is false, then the carrier is unavailable (carrier module)
         if ($row['price'] === false) {
             unset($result[$k]);
             continue;
         }
         $results_array[] = $row;
     }
     // if we have to sort carriers by price
     $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;
 }
コード例 #23
0
 public function getCarriersListByIdZone($id_country, $id_state = 0, $zipcode = 0)
 {
     global $cart, $smarty, $cookie;
     // cookie saving/updating
     $cookie->id_country = $id_country;
     if ($id_state != 0) {
         $cookie->id_state = $id_state;
     }
     if ($zipcode !== 0) {
         $cookie->postcode = $zipcode;
     }
     $id_zone = 0;
     if ($id_state != 0) {
         $id_zone = State::getIdZone($id_state);
     }
     if (!$id_zone) {
         $id_zone = Country::getIdZone($id_country);
     }
     // Need to set the infos for carrier module !
     $cookie->id_country = $id_country;
     $cookie->id_state = $id_state;
     $cookie->postcode = $zipcode;
     $carriers = array();
     if ($this->addAddress($id_country, $zipcode)) {
         // Back up the current id_address_delivery
         $current_id_address_delivery = $cart->id_address_delivery;
         // Get the new one created
         $cart->id_address_delivery = Configuration::get(CarrierCompare::VIRTUAL_ADDRESS);
         $cart->id_customer = Configuration::get(CarrierCompare::VIRTUAL_CUSTOMER);
         // Get carriers with good id_zone
         $carriers = Carrier::getCarriersForOrder((int) $id_zone);
         // Delete Address and restore id_address_delivery
         $address = new Address((int) Configuration::get(CarrierCompare::VIRTUAL_ADDRESS));
         $address->delete();
         $cart->id_address_delivery = $current_id_address_delivery;
     }
     return count($carriers) ? $carriers : array();
 }