Exemple #1
0
 public function isCarrierInRange($id_carrier, $id_zone)
 {
     if (version_compare(_PS_VERSION_, "1.4.2.5", "==") || version_compare(_PS_VERSION_, "1.4.3.0", "==")) {
         // fix a bug in Prestashop
         $carrier = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
         $shippingMethod = $carrier->getShippingMethod();
         ###### that is the bug BOF ######
         if (!$carrier->range_behavior) {
             return true;
         }
         ###### that is the bug EOF ######
         if ($shippingMethod == Carrier::SHIPPING_METHOD_FREE) {
             return true;
         }
         if ($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT && Carrier::checkDeliveryPriceByWeight((int) $id_carrier, $this->getTotalWeight(), $id_zone)) {
             return true;
         }
         if ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE && Carrier::checkDeliveryPriceByPrice((int) $id_carrier, $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, (int) $this->id_currency)) {
             return true;
         }
     } elseif (version_compare(_PS_VERSION_, "1.4.1.0", "==")) {
         // fix a bug in prestashop
         $carrier = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
         $is_in_zone = false;
         $order_total = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);
         ###### that is the bug BOF ######
         if (!$carrier->range_behavior) {
             return true;
         }
         ###### that is the bug EOF ######
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT and Carrier::checkDeliveryPriceByWeight((int) $id_carrier, $this->getTotalWeight(), $id_zone) or $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE and Carrier::checkDeliveryPriceByPrice((int) $id_carrier, $order_total, $id_zone, (int) $this->id_currency)) {
             $is_in_zone = true;
         }
         unset($carrier);
         return $is_in_zone;
     } else {
         return parent::isCarrierInRange($id_carrier, $id_zone);
     }
     return false;
 }
Exemple #2
0
 /**
  * isCarrierInRange
  *
  * Check if the specified carrier is in range
  *
  * @id_carrier int
  * @id_zone int
  */
 public function isCarrierInRange($id_carrier, $id_zone)
 {
     $carrier = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
     $shipping_method = $carrier->getShippingMethod();
     if (!$carrier->range_behavior) {
         return true;
     }
     if ($shipping_method == Carrier::SHIPPING_METHOD_FREE) {
         return true;
     }
     $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight((int) $id_carrier, $this->getTotalWeight(), $id_zone);
     if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && $check_delivery_price_by_weight) {
         return true;
     }
     $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice((int) $id_carrier, $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, (int) $this->id_currency);
     if ($shipping_method == Carrier::SHIPPING_METHOD_PRICE && $check_delivery_price_by_price) {
         return true;
     }
     return false;
 }
Exemple #3
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;
	}
 public function generateFlux()
 {
     if (Tools::getValue('token') == '' || Tools::getValue('token') != Configuration::get('SHOPPING_FLUX_TOKEN')) {
         die('Invalid Token');
     }
     $titles = array(0 => 'id_produit', 1 => 'nom_produit', 2 => 'url_produit', 3 => 'url_image', 4 => 'description', 5 => 'description_courte', 6 => 'prix', 7 => 'prix_barre', 8 => 'frais_de_port', 9 => 'delaiLiv', 10 => 'marque', 11 => 'rayon', 12 => 'stock', 13 => 'qte_stock', 14 => 'EAN', 15 => 'poids', 16 => 'ecotaxe', 17 => 'TVA', 18 => 'Reference constructeur', 19 => 'Reference fournisseur');
     echo implode("|", $titles) . "\r\n";
     //For Shipping
     $configuration = Configuration::getMultiple(array('PS_TAX_ADDRESS_TYPE', 'PS_CARRIER_DEFAULT', 'PS_COUNTRY_DEFAULT', 'PS_LANG_DEFAULT', 'PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
     $products = Product::getSimpleProducts($configuration['PS_LANG_DEFAULT']);
     $defaultCountry = new Country($configuration['PS_COUNTRY_DEFAULT'], Configuration::get('PS_LANG_DEFAULT'));
     $id_zone = (int) $defaultCountry->id_zone;
     $carrier = new Carrier((int) $configuration['PS_CARRIER_DEFAULT']);
     $carrierTax = Tax::getCarrierTaxRate((int) $carrier->id, (int) $this->{$configuration['PS_TAX_ADDRESS_TYPE']});
     foreach ($products as $key => $produit) {
         $product = new Product((int) $produit['id_product'], true, $configuration['PS_LANG_DEFAULT']);
         //For links
         $link = new Link();
         //For images
         $cover = $product->getCover($product->id);
         $ids = $product->id . '-' . $cover['id_image'];
         //For shipping
         if ($product->getPrice(true, NULL, 2, NULL, false, true, 1) >= (double) $configuration['PS_SHIPPING_FREE_PRICE'] and (double) $configuration['PS_SHIPPING_FREE_PRICE'] > 0) {
             $shipping = 0;
         } elseif (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) and $product->weight >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] and (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) {
             $shipping = 0;
         } else {
             if (isset($configuration['PS_SHIPPING_HANDLING']) and $carrier->shipping_handling) {
                 $shipping = (double) $configuration['PS_SHIPPING_HANDLING'];
             }
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping += $carrier->getDeliveryPriceByWeight($product->weight, $id_zone);
             } else {
                 $shipping += $carrier->getDeliveryPriceByPrice($product->getPrice(true, NULL, 2, NULL, false, true, 1), $id_zone);
             }
             $shipping *= 1 + $carrierTax / 100;
             $shipping = (double) Tools::ps_round((double) $shipping, 2);
         }
         $data = array();
         $data[0] = $product->id;
         $data[1] = $product->name;
         $data[2] = $link->getProductLink($product);
         $data[3] = $link->getImageLink($product->link_rewrite, $ids, 'large');
         $data[4] = $product->description;
         $data[5] = $product->description_short;
         $data[6] = $product->getPrice(true, NULL, 2, NULL, false, true, 1);
         $data[7] = $product->getPrice(true, NULL, 2, NULL, false, false, 1);
         $data[8] = $shipping;
         $data[9] = $carrier->delay[2];
         $data[10] = $product->manufacturer_name;
         $data[11] = $product->category;
         $data[12] = $product->quantity > 0 ? 'oui' : 'non';
         $data[13] = $product->quantity;
         $data[14] = $product->ean13;
         $data[15] = $product->weight;
         $data[16] = $product->ecotax;
         $data[17] = $product->tax_rate;
         $data[18] = $product->reference;
         $data[19] = $product->supplier_reference;
         foreach ($data as $key => $value) {
             $data[$key] = $this->clean($value);
         }
         echo implode("|", $data) . "\r\n";
     }
 }
Exemple #5
0
 public function getOrderShippingCostPerSellerCarrier($id_seller, $use_tax, $id_zone, $id_carrier, $carrier_amount, $carrier_weight)
 {
     $shipping_cost = 0;
     $carrier = new Carrier($id_carrier, $this->id_lang);
     if ($carrier->is_free == 1) {
         return 0;
     }
     if ($use_tax and !Tax::excludeTaxeOption()) {
         $carrierTax = Tax::getCarrierTaxRate((int) $carrier->id, (int) $this->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
     }
     $configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_FREE_WEIGHT'));
     $free_fees_price = 0;
     if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) {
         $free_fees_price = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency));
     }
     $free_fees_weight = 0;
     if (isset($configuration['PS_SHIPPING_FREE_WEIGHT'])) {
         $free_fees_weight = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_WEIGHT'], Currency::getCurrencyInstance((int) $this->id_currency));
     }
     $shipping_method = $carrier->getShippingMethod();
     if ($shipping_method == Carrier::SHIPPING_METHOD_PRICE and $carrier_amount >= (double) $free_fees_price and (double) $free_fees_price > 0) {
     } else {
         if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT and $carrier_weight >= (double) $free_fees_weight and (double) $free_fees_weight > 0) {
         } else {
             if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $seller_shipping = $carrier->getDeliveryPriceByWeight($carrier_weight, $id_zone);
                 $shipping_cost += $seller_shipping;
             } else {
                 $seller_shipping = $carrier->getDeliveryPriceByPrice($carrier_amount, $id_zone, (int) $this->id_currency);
                 $shipping_cost += $seller_shipping;
             }
         }
     }
     $shipping_cost += $this->getAdditionalShippingCostOfSeller($id_carrier);
     if ($carrier->shipping_handling) {
         $shipping_cost += (double) Configuration::get('PS_SHIPPING_HANDLING');
     }
     if (isset($carrierTax)) {
         $shipping_cost *= 1 + $carrierTax / 100;
     }
     $shipping_cost = Tools::convertPrice($shipping_cost);
     return $shipping_cost;
 }
 /**
  * @param Carrier $carrier
  * @param array   $tpl_vars
  * @param array   $fields_value
  */
 protected function getTplRangesVarsAndValues($carrier, &$tpl_vars, &$fields_value)
 {
     $tpl_vars['zones'] = Zone::getZones(false);
     $carrier_zones = $carrier->getZones();
     $carrier_zones_ids = array();
     if (is_array($carrier_zones)) {
         foreach ($carrier_zones as $carrier_zone) {
             $carrier_zones_ids[] = $carrier_zone['id_zone'];
         }
     }
     $range_table = $carrier->getRangeTable();
     $shipping_method = $carrier->getShippingMethod();
     $zones = Zone::getZones(false);
     foreach ($zones as $zone) {
         $fields_value['zones'][$zone['id_zone']] = Tools::getValue('zone_' . $zone['id_zone'], in_array($zone['id_zone'], $carrier_zones_ids));
     }
     if ($shipping_method == Carrier::SHIPPING_METHOD_FREE) {
         $range_obj = $carrier->getRangeObject($carrier->shipping_method);
         $price_by_range = array();
     } else {
         $range_obj = $carrier->getRangeObject();
         $price_by_range = Carrier::getDeliveryPriceByRanges($range_table, (int) $carrier->id);
     }
     foreach ($price_by_range as $price) {
         $tpl_vars['price_by_range'][$price['id_' . $range_table]][$price['id_zone']] = $price['price'];
     }
     $tmp_range = $range_obj->getRanges((int) $carrier->id);
     $tpl_vars['ranges'] = array();
     if ($shipping_method != Carrier::SHIPPING_METHOD_FREE) {
         foreach ($tmp_range as $id => $range) {
             $tpl_vars['ranges'][$range['id_' . $range_table]] = $range;
             $tpl_vars['ranges'][$range['id_' . $range_table]]['id_range'] = $range['id_' . $range_table];
         }
     }
     // init blank range
     if (!count($tpl_vars['ranges'])) {
         $tpl_vars['ranges'][] = array('id_range' => 0, 'delimiter1' => 0, 'delimiter2' => 0);
     }
 }
    public static function getInternationalShippings($id_ebay_profile, $id_product = null)
    {
        $shippings = Db::getInstance()->ExecuteS('SELECT *
			FROM ' . _DB_PREFIX_ . 'ebay_shipping 
			WHERE `id_ebay_profile` = ' . (int) $id_ebay_profile . ' 
			AND international = 1');
        //Check if product can be shipped because of weight or dimension
        if ($id_product) {
            $exclude = array();
            foreach ($shippings as $key => $value) {
                $carrier = new Carrier($value['ps_carrier']);
                $product = new Product($id_product);
                if ($carrier->range_behavior) {
                    if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !Carrier::checkDeliveryPriceByWeight($carrier->id, $product->weight, $value['id_zone']) || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !Carrier::checkDeliveryPriceByPrice($carrier->id, $product->weight, $value['id_zone'], Configuration::get('PS_CURRENCY_DEFAULT'))) {
                        $exclude[] = $key;
                    }
                }
                if ($carrier->max_width < $product->width && $carrier->max_width != 0 || $carrier->max_height < $product->height && $carrier->max_height != 0 || $carrier->max_depth < $product->depth && $carrier->max_depth != 0) {
                    $exclude[] = $key;
                    continue;
                }
            }
            $exclude = array_unique($exclude);
            foreach ($exclude as $key_to_exclude) {
                unset($shippings[$key_to_exclude]);
            }
        }
        if ($id_product && version_compare(_PS_VERSION_, '1.5', '>')) {
            $shippings_product = Db::getInstance()->ExecuteS('SELECT id_carrier_reference as ps_carrier
			FROM ' . _DB_PREFIX_ . 'product_carrier WHERE id_product = ' . (int) $id_product);
            if (count($shippings_product) > 0) {
                if (array_intersect_assoc($shippings, $shippings_product)) {
                    $shippings = array_intersect_assoc($shippings, $shippings_product);
                }
            }
        }
        return $shippings;
    }
 public function hookExtraCarrier($params)
 {
     /*  TODO : Makes it work with multi-shipping */
     if (!MondialRelay::isAccountSet()) {
         return '';
     }
     $id_carrier = false;
     $preSelectedRelay = $this->getRelayPointSelected($this->context->cart->id);
     $carriersList = MondialRelay::_getCarriers();
     $address = new Address($this->context->cart->id_address_delivery);
     $country = new Country($address->id_country);
     $id_zone = Address::getZoneById((int) $address->id);
     /*  Check if the defined carrier are ok */
     foreach ($carriersList as $k => $row) {
         /*  For now works only with single shipping (>= 1.5 compatibility) */
         if (method_exists($this->context->cart, 'carrierIsSelected')) {
             if ($this->context->cart->carrierIsSelected($row['id_carrier'], $params['address']->id)) {
                 $id_carrier = $row['id_carrier'];
             }
         }
         /*  Temporary carrier for some test */
         $carrier = new Carrier((int) $row['id_carrier']);
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) {
             unset($carriersList[$k]);
         } else {
             if ($row['range_behavior']) {
                 /*  Get id zone */
                 $id_zone = isset($this->context->cart->id_address_delivery) && $this->context->cart->id_address_delivery ? Address::getZoneById((int) $this->context->cart->id_address_delivery) : (int) $this->context->country->id_zone;
                 if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->context->cart->getTotalWeight(), $id_zone) || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->context->cart->getOrderTotal(true, MondialRelay::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency) || !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->context->cart->getOrderTotal(true, MondialRelay::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency))) {
                     unset($carriersList[$k]);
                 }
             }
         }
     }
     $carrier = null;
     if ($id_carrier && ($method = MondialRelay::getMethodByIdCarrier($id_carrier))) {
         $carrier = new Carrier((int) $id_carrier);
         /*  Add dynamically a new field */
         $carrier->id_mr_method = $method['id_mr_method'];
         $carrier->mr_dlv_mode = $method['dlv_mode'];
     }
     if (Configuration::get('PS_SSL_ENABLED') || !empty($_SERVER['HTTPS']) && Tools::strtolower($_SERVER['HTTPS']) != 'off') {
         $ssl = 'true';
     } else {
         $ssl = 'false';
     }
     $this->context->smarty->assign(array('address' => $address, 'account_shop' => $this->account_shop, 'country' => $country, 'ssl' => $ssl, 'MR_Data' => MRTools::jsonEncode(array('carrier_list' => $carriersList, 'carrier' => $carrier, 'PS_VERSION' => _PS_VERSION_, 'pre_selected_relay' => isset($preSelectedRelay['MR_selected_num']) ? $preSelectedRelay['MR_selected_num'] : -1))));
     if (Configuration::get('MONDIAL_RELAY_MODE') == 'widget') {
         return $this->fetchTemplate('/views/templates/front/', 'checkout_process_widget');
     } else {
         return $this->fetchTemplate('/views/templates/front/', 'checkout_process');
     }
 }
    private static function getCarrierShippingRanges()
    {
        $carrier = new Carrier((int) self::$_carrierId);
        // Get only carriers that are compliant with shipping method
        if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight((int) self::$_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice((int) self::$_zone) === false) {
            return array();
        }
        if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
            $table = 'range_weight';
        }
        if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE) {
            $table = 'range_price';
        }
        if (!in_array($table, array('range_price', 'range_weight'))) {
            return array();
        }
        $sql = '
        SELECT d.`id_' . $table . '` ,
               d.`id_carrier`        ,
               d.`id_zone`           ,
               d.`price`             ,
               r.`delimiter1`        ,
               r.`delimiter2`
        FROM `' . _DB_PREFIX_ . 'delivery` d

            LEFT JOIN `' . _DB_PREFIX_ . $table . '` r
            ON  r.`id_' . $table . '` = d.`id_' . $table . '`

        WHERE
                d.`id_' . $table . '` IS NOT NULL
            AND d.`id_' . $table . '` != 0
            AND d.price > 0
            AND d.id_carrier = ' . (int) self::$_carrierId . '
            AND d.id_zone = ' . (int) self::$_zone;
        $result = Db::getInstance()->ExecuteS($sql);
        $priceRanges = array();
        $i = 0;
        foreach ($result as $range) {
            $priceRanges[$i]['price'] = $range['price'];
            $priceRanges[$i]['from'] = $range['delimiter1'];
            $priceRanges[$i]['to'] = $range['delimiter2'];
            $i++;
        }
        return $priceRanges;
    }
Exemple #10
0
 /**
  * isCarrierInRange
  *
  * Check if the specified carrier is in range
  *
  * @id_carrier int
  * @id_zone int
  */
 public function isCarrierInRange($id_carrier, $id_zone)
 {
     $carrier = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
     $is_in_zone = false;
     $order_total = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);
     if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT and Carrier::checkDeliveryPriceByWeight((int) $id_carrier, $this->getTotalWeight(), $id_zone) or $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE and Carrier::checkDeliveryPriceByPrice((int) $id_carrier, $order_total, $id_zone, (int) $this->id_currency)) {
         $is_in_zone = true;
     }
     unset($carrier);
     return $is_in_zone;
 }
 function getCarriersByZoneID($id_zone)
 {
     global $cookie, $cart;
     $id_groups = array(1);
     $islogged = _PS_VERSION_ > '1.5' ? Context::getContext()->customer->isLogged() : $cookie->isLogged();
     if ($islogged) {
         $customer = new Customer((int) $cookie->id_customer);
         $id_groups = $customer->getGroups();
     }
     $result = Carrier::getCarriers(intval($cookie->id_lang), true, false, intval($id_zone), $id_groups, Carrier::ALL_CARRIERS);
     $resultsArray = array();
     foreach ($result as $k => $row) {
         $carrier = new Carrier(intval($row['id_carrier']));
         $shipping_method = $carrier->getShippingMethod();
         if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false or $shipping_method == Carrier::SHIPPING_METHOD_PRICE and $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) {
             unset($result[$k]);
             continue;
         }
         if ($row['range_behavior']) {
             if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone)) {
                 unset($result[$k]);
                 continue;
             }
         }
         $row['name'] = strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME');
         $method = $carrier->getShippingMethod();
         $row['price'] = 0;
         if ($method == Carrier::SHIPPING_METHOD_PRICE) {
             $row['price'] = $carrier->getDeliveryPriceByPrice($cart->getOrderTotal(Cart::BOTH_WITHOUT_SHIPPING), $id_zone);
         } else {
             if ($method == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $row['price'] = $carrier->getDeliveryPriceByWeight($cart->getTotalWeight(), $id_zone);
             }
         }
         if ((int) $row['shipping_handling'] == 1) {
             $row['price'] = (double) $row['price'] + (double) Configuration::get('PS_SHIPPING_HANDLING');
         }
         if ((int) $row['is_free']) {
             $row['price'] = 0;
         }
         $row['price_tax_exc'] = $row['price'];
         $address = new Address($cart->id_address_delivery);
         $tax_rate = $carrier->getTaxesRate($address);
         $currency = new Currency($cart->id_currency);
         $row['price'] = $row['price'] * $currency->conversion_rate * (1 + (double) $tax_rate / 100);
         $row['img'] = file_exists(_PS_SHIP_IMG_DIR_ . intval($row['id_carrier']) . '.jpg') ? _THEME_SHIP_DIR_ . intval($row['id_carrier']) . '.jpg' : '';
         $resultsArray[] = $row;
     }
     return $resultsArray;
 }
Exemple #12
0
 /**
  * isCarrierInRange
  *
  * Check if the specified carrier is in range
  *
  * @id_carrier int
  * @id_zone int
  */
 public function isCarrierInRange($id_carrier, $id_zone)
 {
     $carrier = new Carrier((int) $id_carrier, _PS_LANG_DEFAULT_);
     $shippingMethod = $carrier->getShippingMethod();
     if (!$carrier->range_behavior) {
         return true;
     }
     if ($shippingMethod == Carrier::SHIPPING_METHOD_FREE) {
         return true;
     }
     if ($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT and Carrier::checkDeliveryPriceByWeight((int) $id_carrier, $this->getTotalWeight(), $id_zone)) {
         return true;
     }
     if ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE and Carrier::checkDeliveryPriceByPrice((int) $id_carrier, $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, (int) $this->id_currency)) {
         return true;
     }
     return false;
 }
Exemple #13
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;
	}
Exemple #14
0
 /**
  * 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;
 }
Exemple #15
0
 /**
  *
  * @param int $id_zone
  * @param Array $groups group of the customer
  * @return Array 
  */
 public static function getCarriersForOrder($id_zone, $groups = null)
 {
     global $cookie, $cart;
     if (is_array($groups) && !empty($groups)) {
         $result = Carrier::getCarriers((int) $cookie->id_lang, true, false, (int) $id_zone, $groups, self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
     } else {
         $result = Carrier::getCarriers((int) $cookie->id_lang, true, false, (int) $id_zone, array(1), self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
     }
     $resultsArray = array();
     foreach ($result as $k => $row) {
         $carrier = new Carrier((int) $row['id_carrier']);
         $shippingMethod = $carrier->getShippingMethod();
         if ($shippingMethod != Carrier::SHIPPING_METHOD_FREE) {
             // Get only carriers that are compliant with shipping method
             if ($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false || $shippingMethod == 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 ($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT && !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone) || $shippingMethod == Carrier::SHIPPING_METHOD_PRICE && !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $cart->id_currency)) {
                     unset($result[$k]);
                     continue;
                 }
             }
         }
         $row['name'] = strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME');
         $row['price'] = $shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int) $row['id_carrier']);
         $row['price_tax_exc'] = $shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int) $row['id_carrier'], false);
         $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;
         }
         $resultsArray[] = $row;
     }
     return $resultsArray;
 }
 /**
  * Récupération du prix de shipping pour un produit id
  * @param $shipping
  * @return float
  */
 public function getShippingPrice($product_id, $attribute_id, $id_carrier = 0, $id_zone = 0)
 {
     $product = new Product($product_id);
     $shipping = 0;
     $carrier = new Carrier((int) $id_carrier);
     if ($id_zone == 0) {
         $defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
         $id_zone = (int) $defaultCountry->id_zone;
     }
     $carrierTax = Tax::getCarrierTaxRate((int) $carrier->id);
     $free_weight = Configuration::get('PS_SHIPPING_FREE_WEIGHT');
     $shipping_handling = Configuration::get('PS_SHIPPING_HANDLING');
     if ($product->getPrice(true, $attribute_id, 2, NULL, false, true, 1) >= (double) $free_weight and (double) $free_weight > 0) {
         $shipping = 0;
     } elseif (isset($free_weight) and $product->weight >= (double) $free_weight and (double) $free_weight > 0) {
         $shipping = 0;
     } else {
         if (isset($shipping_handling) and $carrier->shipping_handling) {
             $shipping = (double) $shipping_handling;
         }
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
             $shipping += $carrier->getDeliveryPriceByWeight($product->weight, $id_zone);
         } else {
             $shipping += $carrier->getDeliveryPriceByPrice($product->getPrice(true, $attribute_id, 2, NULL, false, true, 1), $id_zone);
         }
         $shipping *= 1 + $carrierTax / 100;
         $shipping = (double) Tools::ps_round((double) $shipping, 2);
     }
     unset($product);
     return $shipping;
 }
Exemple #17
0
 /**
  * @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;
 }