Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * Return shipping total
  *
  * @param integer $id_carrier Carrier ID (default : current carrier)
  * @return float Shipping total
  */
 function getOrderShippingCost($id_carrier = NULL, $useTax = true)
 {
     global $defaultCountry;
     if ($this->isVirtualCart()) {
         return 0;
     }
     // Checking discounts in cart
     $products = $this->getProducts();
     $discounts = $this->getDiscounts(true);
     if ($discounts) {
         foreach ($discounts as $id_discount) {
             $discount = new Discount(intval($id_discount['id_discount']));
             if (!Validate::isLoadedObject($discount)) {
                 die(Tools::displayError());
             }
             if ($discount->id_discount_type == 3) {
                 $total_cart = 0;
                 $categories = Discount::getCategories($discount->id);
                 foreach ($products as $product) {
                     if (count($categories)) {
                         if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                             $total_cart += $product['total_wt'];
                         }
                     }
                 }
                 if ($total_cart >= $discount->minimal) {
                     return 0;
                 }
             }
         }
     }
     // Order total without fees
     $orderTotal = $this->getOrderTotal(true, 7);
     // Start with shipping cost at 0
     $shipping_cost = 0;
     // If no product added, return 0
     if ($orderTotal <= 0 and !intval(self::getNbProducts($this->id))) {
         return $shipping_cost;
     }
     // If no carrier, select default one
     if (!$id_carrier) {
         $id_carrier = $this->id_carrier;
     }
     if (empty($id_carrier)) {
         $id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (!isset(self::$_carriers[$id_carrier])) {
         self::$_carriers[$id_carrier] = new Carrier(intval($id_carrier));
     }
     $carrier = self::$_carriers[$id_carrier];
     if (!Validate::isLoadedObject($carrier)) {
         die(Tools::displayError('Hack attempt: "no default carrier"'));
     }
     if (!$carrier->active) {
         return $shipping_cost;
     }
     // Get id zone
     if (isset($this->id_address_delivery) and $this->id_address_delivery) {
         $id_zone = Address::getZoneById(intval($this->id_address_delivery));
     } else {
         $id_zone = intval($defaultCountry->id_zone);
     }
     // Select carrier tax
     if ($useTax and $carrier->id_tax) {
         if (!isset(self::$_taxes[$carrier->id_tax])) {
             self::$_taxes[$carrier->id_tax] = new Tax(intval($carrier->id_tax));
         }
         $tax = self::$_taxes[$carrier->id_tax];
         if (Validate::isLoadedObject($tax) and Tax::zoneHasTax(intval($tax->id), intval($id_zone)) and !Tax::excludeTaxeOption()) {
             $carrierTax = $tax->rate;
         }
     }
     $configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
     // Free fees
     if (isset($configuration['PS_SHIPPING_FREE_PRICE']) and $orderTotal >= floatval($configuration['PS_SHIPPING_FREE_PRICE']) and floatval($configuration['PS_SHIPPING_FREE_PRICE']) > 0) {
         return $shipping_cost;
     }
     if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) and $this->getTotalWeight() >= floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) and floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0) {
         return $shipping_cost;
     }
     // Get shipping cost using correct method
     if ($carrier->range_behavior) {
         // Get id zone
         if (isset($this->id_address_delivery) and $this->id_address_delivery) {
             $id_zone = Address::getZoneById(intval($this->id_address_delivery));
         } else {
             $id_zone = intval($defaultCountry->id_zone);
         }
         if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice($carrier->id, $this->getOrderTotal(true, 4), $id_zone)) {
             $shipping_cost += 0;
         } else {
             if (intval($configuration['PS_SHIPPING_METHOD'])) {
                 $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone);
             } else {
                 $shipping_cost += $carrier->getDeliveryPriceByPrice($orderTotal, $id_zone);
             }
         }
     } else {
         if (intval($configuration['PS_SHIPPING_METHOD'])) {
             $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone);
         } else {
             $shipping_cost += $carrier->getDeliveryPriceByPrice($orderTotal, $id_zone);
         }
     }
     // Apply tax
     if (isset($carrierTax)) {
         $shipping_cost *= 1 + $carrierTax / 100;
     }
     // Adding handling charges
     if (isset($configuration['PS_SHIPPING_HANDLING']) and $carrier->shipping_handling) {
         $shipping_cost += floatval($configuration['PS_SHIPPING_HANDLING']);
     }
     return floatval($shipping_cost);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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;
    }
Exemplo n.º 5
0
 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');
     }
 }
Exemplo n.º 6
0
 public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null)
 {
     if (!Configuration::get('LEGAL_SHIPTAXMETH')) {
         return parent::getPackageShippingCost($id_carrier, $use_tax, $default_country, $product_list, $id_zone);
     }
     if ($this->isVirtualCart()) {
         return 0;
     }
     if (!$default_country) {
         $default_country = Context::getContext()->country;
     }
     if (!is_null($product_list)) {
         foreach ($product_list as $key => $value) {
             if ($value['is_virtual'] == 1) {
                 unset($product_list[$key]);
             }
         }
     }
     $complete_product_list = $this->getProducts();
     if (is_null($product_list)) {
         $products = $complete_product_list;
     } else {
         $products = $product_list;
     }
     if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
         $address_id = (int) $this->id_address_invoice;
     } elseif (count($product_list)) {
         $prod = current($product_list);
         $address_id = (int) $prod['id_address_delivery'];
     } else {
         $address_id = null;
     }
     if (!Address::addressExists($address_id)) {
         $address_id = null;
     }
     $cache_id = 'getPackageShippingCost_' . (int) $this->id . '_' . (int) $address_id . '_' . (int) $id_carrier . '_' . (int) $use_tax . '_' . (int) $default_country->id;
     if ($products) {
         foreach ($products as $product) {
             $cache_id .= '_' . (int) $product['id_product'] . '_' . (int) $product['id_product_attribute'];
         }
     }
     if (Cache::isStored($cache_id)) {
         return Cache::retrieve($cache_id);
     }
     // Order total in default currency without fees
     $order_total = $this->getOrderTotal(true, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING, $product_list);
     // Start with shipping cost at 0
     $shipping_cost = 0;
     // If no product added, return 0
     if (!count($products)) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     if (!isset($id_zone)) {
         // Get id zone
         if (!$this->isMultiAddressDelivery() && isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
             $id_zone = Address::getZoneById((int) $this->id_address_delivery);
         } else {
             if (!Validate::isLoadedObject($default_country)) {
                 $default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
             }
             $id_zone = (int) $default_country->id_zone;
         }
     }
     if ($id_carrier && !$this->isCarrierInRange((int) $id_carrier, (int) $id_zone)) {
         $id_carrier = '';
     }
     if (empty($id_carrier) && $this->isCarrierInRange((int) Configuration::get('PS_CARRIER_DEFAULT'), (int) $id_zone)) {
         $id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT');
     }
     $total_package_without_shipping_tax_inc = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list);
     if (empty($id_carrier)) {
         if ((int) $this->id_customer) {
             $customer = new Customer((int) $this->id_customer);
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone, $customer->getGroups());
             unset($customer);
         } else {
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone);
         }
         foreach ($result as $k => $row) {
             if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT')) {
                 continue;
             }
             if (!isset(self::$_carriers[$row['id_carrier']])) {
                 self::$_carriers[$row['id_carrier']] = new Carrier((int) $row['id_carrier']);
             }
             $carrier = self::$_carriers[$row['id_carrier']];
             // Get only carriers that are compliant with shipping method
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight((int) $id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice((int) $id_zone) === false) {
                 unset($result[$k]);
                 continue;
             }
             // If out-of-range behavior carrier is set on "Desactivate carrier"
             if ($row['range_behavior']) {
                 $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), (int) $id_zone);
                 $total_order = $total_package_without_shipping_tax_inc;
                 $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int) $id_zone, (int) $this->id_currency);
                 // Get only carriers that have a range compatible with cart
                 if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) {
                     unset($result[$k]);
                     continue;
                 }
             }
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), (int) $id_zone);
             } else {
                 $shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $id_zone, (int) $this->id_currency);
             }
             if (!isset($min_shipping_price)) {
                 $min_shipping_price = $shipping;
             }
             if ($shipping <= $min_shipping_price) {
                 $id_carrier = (int) $row['id_carrier'];
                 $min_shipping_price = $shipping;
             }
         }
     }
     if (empty($id_carrier)) {
         $id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (!isset(self::$_carriers[$id_carrier])) {
         self::$_carriers[$id_carrier] = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
     }
     $carrier = self::$_carriers[$id_carrier];
     // No valid Carrier or $id_carrier <= 0 ?
     if (!Validate::isLoadedObject($carrier)) {
         Cache::store($cache_id, 0);
         return 0;
     }
     if (!$carrier->active) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Free fees if free carrier
     if ($carrier->is_free == 1) {
         Cache::store($cache_id, 0);
         return 0;
     }
     // Select carrier tax
     if ($use_tax && !Tax::excludeTaxeOption()) {
         $address = Address::initialize((int) $address_id);
         $carrier_tax = $carrier->getTaxesRate($address);
     }
     $configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
     // Free fees
     $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));
     }
     $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false);
     if ($orderTotalwithDiscounts >= (double) $free_fees_price && (double) $free_fees_price > 0) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] && (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Get shipping cost using correct method
     if ($carrier->range_behavior) {
         if (!isset($id_zone)) {
             // Get id zone
             if (isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
                 $id_zone = Address::getZoneById((int) $this->id_address_delivery);
             } else {
                 $id_zone = (int) $default_country->id_zone;
             }
         }
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), (int) $id_zone) || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !Carrier::checkDeliveryPriceByPrice($carrier->id, $total_package_without_shipping_tax_inc, $id_zone, (int) $this->id_currency)) {
             $shipping_cost += 0;
         } else {
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
             } else {
                 // by price
                 $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
             }
         }
     } else {
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
             $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
         } else {
             $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
         }
     }
     // Adding handling charges
     if (isset($configuration['PS_SHIPPING_HANDLING']) && $carrier->shipping_handling) {
         $shipping_cost += (double) $configuration['PS_SHIPPING_HANDLING'];
     }
     // Additional Shipping Cost per product
     foreach ($products as $product) {
         if (!$product['is_virtual']) {
             $shipping_cost += $product['additional_shipping_cost'] * $product['cart_quantity'];
         }
     }
     $shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int) $this->id_currency));
     //get external shipping cost from module
     if ($carrier->shipping_external) {
         $module_name = $carrier->external_module_name;
         $module = Module::getInstanceByName($module_name);
         if (Validate::isLoadedObject($module)) {
             if (array_key_exists('id_carrier', $module)) {
                 $module->id_carrier = $carrier->id;
             }
             if ($carrier->need_range) {
                 if (method_exists($module, 'getPackageShippingCost')) {
                     $shipping_cost = $module->getPackageShippingCost($this, $shipping_cost, $products);
                 } else {
                     $shipping_cost = $module->getOrderShippingCost($this, $shipping_cost);
                 }
             } else {
                 $shipping_cost = $module->getOrderShippingCostExternal($this);
             }
             // Check if carrier is available
             if ($shipping_cost === false) {
                 Cache::store($cache_id, false);
                 return false;
             }
         } else {
             Cache::store($cache_id, false);
             return false;
         }
     }
     $shipping_cost = (double) Tools::ps_round((double) $shipping_cost, 2);
     Cache::store($cache_id, $shipping_cost);
     return $shipping_cost;
 }
Exemplo n.º 7
0
 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);
     $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 (Configuration::get('PS_SHIPPING_METHOD') && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false || !Configuration::get('PS_SHIPPING_METHOD') && $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 (Configuration::get('PS_SHIPPING_METHOD') && !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->context->cart->getTotalWeight(), $id_zone) || !Configuration::get('PS_SHIPPING_METHOD') && (!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 (_PS_VERSION_ >= '1.5') {
         $id_carrier = (int) $this->context->cart->id_carrier;
     }
     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'];
     }
     $this->context->smarty->assign(array('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'] : 0))));
     return $this->fetchTemplate('/tpl/', 'checkout_process');
 }
Exemplo n.º 8
0
 private function checkSoCarrierAvailable($id_carrier)
 {
     global $cart, $defaultCountry;
     $carrier = new Carrier((int) $id_carrier);
     $address = new Address((int) $cart->id_address_delivery);
     $id_zone = Address::getZoneById((int) $address->id);
     // Get only carriers that are compliant with shipping method
     if (Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false or !Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) {
         return false;
     }
     // If out-of-range behavior carrier is set on "Desactivate carrier"
     if ($carrier->range_behavior) {
         // Get id zone
         if (isset($cart->id_address_delivery) and $cart->id_address_delivery) {
             $id_zone = Address::getZoneById((int) $cart->id_address_delivery);
         } else {
             $id_zone = (int) $defaultCountry->id_zone;
         }
         // Get only carriers that have a range compatible with cart
         if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight((int) $carrier->id, $cart->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice((int) $carrier->id, $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $cart->id_currency)) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 9
0
 public function hookextraCarrier($params)
 {
     global $smarty, $cart, $cookie, $defaultCountry, $nbcarriers;
     if (Configuration::get('MR_ENSEIGNE_WEBSERVICE') == '' || Configuration::get('MR_CODE_MARQUE') == '' || Configuration::get('MR_KEY_WEBSERVICE') == '' || Configuration::get('MR_LANGUAGE') == '') {
         return '';
     }
     $address = new Address((int) $cart->id_address_delivery);
     $id_zone = Address::getZoneById((int) $address->id);
     $carriersList = self::_getCarriers();
     // Check if the defined carrier are ok
     foreach ($carriersList as $k => $row) {
         $carrier = new Carrier((int) $row['id_carrier']);
         if ((Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false) || (!Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByPrice($id_zone) === false)) {
             unset($carriersList[$k]);
         } else {
             if ($row['range_behavior']) {
                 // Get id zone
                 $id_zone = (isset($cart->id_address_delivery) and $cart->id_address_delivery) ? Address::getZoneById((int) $cart->id_address_delivery) : (int) $defaultCountry->id_zone;
                 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, self::BOTH_WITHOUT_SHIPPING), $id_zone, $cart->id_currency)) {
                     unset($carriersList[$k]);
                 }
             }
         }
     }
     $preSelectedRelay = $this->getRelayPointSelected($params['cart']->id);
     $smarty->assign(array('one_page_checkout' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? Configuration::get('PS_ORDER_PROCESS_TYPE') : 0, 'new_base_dir' => self::$moduleURL, 'MRToken' => self::$MRFrontToken, 'carriersextra' => $carriersList, 'preSelectedRelay' => isset($preSelectedRelay['MR_selected_num']) ? $preSelectedRelay['MR_selected_num'] : '', 'jQueryOverload' => self::getJqueryCompatibility(false)));
     return $this->display(__FILE__, 'mondialrelay.tpl');
 }
 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;
 }
Exemplo n.º 11
0
 public function hookextraCarrier($params)
 {
     global $smarty, $cart, $cookie, $defaultCountry, $nbcarriers;
     if (Configuration::get('MR_ENSEIGNE_WEBSERVICE') == '' or Configuration::get('MR_CODE_MARQUE') == '' or Configuration::get('MR_KEY_WEBSERVICE') == '' or Configuration::get('MR_LANGUAGE') == '') {
         return '';
     }
     $totalweight = Configuration::get('MR_WEIGHT_COEF') * $cart->getTotalWeight();
     if (Validate::isUnsignedInt($cart->id_carrier)) {
         $carrier = new Carrier((int) $cart->id_carrier);
         if ($carrier->active and !$carrier->deleted) {
             $checked = (int) $cart->id_carrier;
         }
     }
     if (!isset($checked) or $checked == 0) {
         $checked = (int) Configuration::get('PS_CARRIER_DEFAULT');
     }
     $address = new Address((int) $cart->id_address_delivery);
     $id_zone = Address::getZoneById((int) $address->id);
     $country = new Country((int) $address->id_country);
     $query = self::getmrth((int) $cookie->id_lang, true, (int) $country->id_zone, $country->iso_code);
     $resultsArray = array();
     $i = 0;
     foreach ($query as $k => $row) {
         $carrier = new Carrier((int) $row['id_carrier']);
         if (Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false or !Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) {
             unset($result[$k]);
             continue;
         }
         if ($row['range_behavior']) {
             // Get id zone
             if (isset($cart->id_address_delivery) and $cart->id_address_delivery) {
                 $id_zone = Address::getZoneById((int) $cart->id_address_delivery);
             } else {
                 $id_zone = (int) $defaultCountry->id_zone;
             }
             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, self::BOTH_WITHOUT_SHIPPING), $id_zone, $cart->id_currency)) {
                 unset($result[$k]);
                 continue;
             }
         }
         $settings = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'mr_method` WHERE `id_carrier` = ' . (int) $row['id_carrier']);
         $row['name'] = $settings[0]['mr_Name'];
         $row['col'] = $settings[0]['mr_ModeCol'];
         $row['liv'] = $settings[0]['mr_ModeLiv'];
         $row['ass'] = $settings[0]['mr_ModeAss'];
         $row['price'] = $cart->getOrderShippingCost((int) $row['id_carrier']);
         $row['img'] = file_exists(_PS_SHIP_IMG_DIR_ . (int) $row['id_carrier'] . '.jpg') ? _THEME_SHIP_DIR_ . (int) $row['id_carrier'] . '.jpg' : '';
         $resultsArray[] = $row;
         $i++;
     }
     if ($i > 0) {
         include_once _PS_MODULE_DIR_ . 'mondialrelay/page_iso.php';
         $smarty->assign(array('address_map' => $address->address1 . ', ' . $address->postcode . ', ' . ote_accent($address->city) . ', ' . $country->iso_code, 'input_cp' => $address->postcode, 'input_ville' => ote_accent($address->city), 'input_pays' => $country->iso_code, 'input_poids' => Configuration::get('MR_WEIGHT_COEF') * $cart->getTotalWeight(), 'nbcarriers' => $nbcarriers, 'checked' => (int) $checked, 'google_api_key' => Configuration::get('MR_GOOGLE_MAP'), 'one_page_checkout' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? Configuration::get('PS_ORDER_PROCESS_TYPE') : 0, 'new_base_dir' => self::$moduleURL, 'carriersextra' => $resultsArray));
         $nbcarriers = $nbcarriers + $i;
         return $this->display(__FILE__, 'mondialrelay.tpl');
     }
 }
Exemplo n.º 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;
 }
 private function checkSoCarrierAvailable($id_carrier)
 {
     $carrier = new Carrier((int) $id_carrier);
     $address = new Address((int) $this->context->cart->id_address_delivery);
     $id_zone = Address::getZoneById((int) $address->id);
     // backward compatibility
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         // Get only carriers that are compliant with shipping method
         if (Configuration::get('PS_SHIPPING_METHOD') && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false || !Configuration::get('PS_SHIPPING_METHOD') && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) {
             return false;
         }
     } else {
         if ($carrier->shipping_method) {
             if ($carrier->shipping_method == 1 && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false || $carrier->shipping_method == 2 && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) {
                 return false;
             }
         } else {
             if (Configuration::get('PS_SHIPPING_METHOD') && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false || !Configuration::get('PS_SHIPPING_METHOD') && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) {
                 return false;
             }
         }
     }
     // If out-of-range behavior carrier is set on "Desactivate carrier"
     if ($carrier->range_behavior) {
         // Get id zone
         $id_zone = (int) $this->context->country->id_zone;
         if (isset($this->context->cart->id_address_delivery) && $this->context->cart->id_address_delivery) {
             $id_zone = Address::getZoneById((int) $this->context->cart->id_address_delivery);
         }
         if (version_compare(_PS_VERSION_, '1.5', '<')) {
             // Get only carriers that have a range compatible with cart
             if (Configuration::get('PS_SHIPPING_METHOD') && !Carrier::checkDeliveryPriceByWeight((int) $carrier->id, $this->context->cart->getTotalWeight(), $id_zone) || !Configuration::get('PS_SHIPPING_METHOD') && !Carrier::checkDeliveryPriceByPrice((int) $carrier->id, $this->context->cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency)) {
                 return false;
             }
         } else {
             if ($carrier->shipping_method) {
                 if ($carrier->shipping_method == 1 && !Carrier::checkDeliveryPriceByWeight((int) $carrier->id, $this->context->cart->getTotalWeight(), $id_zone) || $carrier->shipping_method == 2 && !Carrier::checkDeliveryPriceByPrice((int) $carrier->id, $this->context->cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency)) {
                     return false;
                 }
             } else {
                 if (Configuration::get('PS_SHIPPING_METHOD') && !Carrier::checkDeliveryPriceByWeight((int) $carrier->id, $this->context->cart->getTotalWeight(), $id_zone) || !Configuration::get('PS_SHIPPING_METHOD') && !Carrier::checkDeliveryPriceByPrice((int) $carrier->id, $this->context->cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency)) {
                     return false;
                 }
             }
         }
     }
     return true;
 }
Exemplo n.º 14
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;
	}
Exemplo n.º 15
0
 private function isCarrierInRange($carrier, $id_zone)
 {
     if (!$carrier->range_behavior) {
         PowaTagLogs::initAPILog('isCarrierInRange', PowaTagLogs::SUCCESS, '! carrier->range_behavior');
         return true;
     }
     $shipping_method = $carrier->getShippingMethod();
     if ($shipping_method == Carrier::SHIPPING_METHOD_FREE) {
         PowaTagLogs::initAPILog('isCarrierInRange', PowaTagLogs::SUCCESS, 'shipping_method == Carrier::SHIPPING_METHOD_FREE');
         return true;
     }
     $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight((int) $carrier->id, null, $id_zone);
     if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && $check_delivery_price_by_weight) {
         PowaTagLogs::initAPILog('isCarrierInRange', PowaTagLogs::SUCCESS, 'shipping_method == Carrier::SHIPPING_METHOD_WEIGHT ...');
         return true;
     }
     $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice((int) $carrier->id, $this->subTotal, $id_zone, (int) $this->id_currency);
     if ($shipping_method == Carrier::SHIPPING_METHOD_PRICE && $check_delivery_price_by_price) {
         PowaTagLogs::initAPILog('isCarrierInRange', PowaTagLogs::SUCCESS, 'shipping_method == Carrier::SHIPPING_METHOD_PRICE ...');
         return true;
     }
     PowaTagLogs::initAPILog('isCarrierInRange', PowaTagLogs::ERROR, 'No suitable shipping method found');
     return false;
 }
Exemplo n.º 16
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;
	}
Exemplo n.º 17
0
function displayCarrier()
{
    global $smarty, $cart, $cookie, $defaultCountry, $link;
    $address = new Address(intval($cart->id_address_delivery));
    $id_zone = Address::getZoneById(intval($address->id));
    if (isset($cookie->id_customer)) {
        $customer = new Customer(intval($cookie->id_customer));
    } else {
        die(Tools::displayError($this->l('Fatal error: No customer')));
    }
    $result = Carrier::getCarriers(intval($cookie->id_lang), true, false, intval($id_zone), $customer->getGroups());
    if (!$result) {
        $result = Carrier::getCarriers(intval($cookie->id_lang), true, false, intval($id_zone));
    }
    $resultsArray = array();
    foreach ($result as $k => $row) {
        $carrier = new Carrier(intval($row['id_carrier']));
        // Get only carriers that are compliant with shipping method
        if (Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false or !Configuration::get('PS_SHIPPING_METHOD') and $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 (isset($cart->id_address_delivery) and $cart->id_address_delivery) {
                $id_zone = Address::getZoneById(intval($cart->id_address_delivery));
            } else {
                $id_zone = intval($defaultCountry->id_zone);
            }
            // Get only carriers that have a range compatible with cart
            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, 4), $id_zone)) {
                unset($result[$k]);
                continue;
            }
        }
        $row['name'] = strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME');
        $row['price'] = $cart->getOrderShippingCost(intval($row['id_carrier']));
        $row['price_tax_exc'] = $cart->getOrderShippingCost(intval($row['id_carrier']), false);
        $row['img'] = file_exists(_PS_SHIP_IMG_DIR_ . intval($row['id_carrier']) . '.jpg') ? _THEME_SHIP_DIR_ . intval($row['id_carrier']) . '.jpg' : '';
        $resultsArray[] = $row;
    }
    // Wrapping fees
    $wrapping_fees = floatval(Configuration::get('PS_GIFT_WRAPPING_PRICE'));
    $wrapping_fees_tax = new Tax(intval(Configuration::get('PS_GIFT_WRAPPING_TAX')));
    $wrapping_fees_tax_inc = $wrapping_fees * (1 + floatval($wrapping_fees_tax->rate) / 100);
    if (Validate::isUnsignedInt($cart->id_carrier) and $cart->id_carrier) {
        $carrier = new Carrier(intval($cart->id_carrier));
        if ($carrier->active and !$carrier->deleted) {
            $checked = intval($cart->id_carrier);
        }
    }
    $cms = new CMS(3, intval($cookie->id_lang));
    $link_conditions = $link->getCMSLink($cms, $cms->link_rewrite);
    if (!strpos($link_conditions, '?')) {
        $link_conditions .= '?content_only=1&TB_iframe=true&width=450&height=500&thickbox=true';
    } else {
        $link_conditions .= '&content_only=1&TB_iframe=true&width=450&height=500&thickbox=true';
    }
    if (!isset($checked) or intval($checked) == 0) {
        $checked = intval(Configuration::get('PS_CARRIER_DEFAULT'));
    }
    $smarty->assign(array('checkedTOS' => intval($cookie->checkedTOS), 'recyclablePackAllowed' => intval(Configuration::get('PS_RECYCLABLE_PACK')), 'giftAllowed' => intval(Configuration::get('PS_GIFT_WRAPPING')), 'conditions' => intval(Configuration::get('PS_CONDITIONS')), 'link_conditions' => $link_conditions, 'recyclable' => intval($cart->recyclable), 'gift_wrapping_price' => floatval(Configuration::get('PS_GIFT_WRAPPING_PRICE')), 'carriers' => $resultsArray, 'HOOK_EXTRACARRIER' => Module::hookExec('extraCarrier', array('address' => $address)), 'checked' => intval($checked), 'total_wrapping' => Tools::convertPrice($wrapping_fees_tax_inc, new Currency(intval($cookie->id_currency))), 'total_wrapping_tax_exc' => Tools::convertPrice($wrapping_fees, new Currency(intval($cookie->id_currency)))));
    Tools::safePostVars();
    $css_files = array(__PS_BASE_URI__ . 'css/thickbox.css' => 'all');
    $js_files = array(__PS_BASE_URI__ . 'js/jquery/thickbox-modified.js');
    include_once dirname(__FILE__) . '/header.php';
    $smarty->display(_PS_THEME_DIR_ . 'order-carrier.tpl');
}
Exemplo n.º 18
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;
 }
Exemplo n.º 19
0
 public function hookextraCarrier($params)
 {
     if (!MondialRelay::isAccountSet()) {
         return '';
     }
     $carrier = false;
     $id_carrier = false;
     $id_mr_method = false;
     $preSelectedRelay = $this->getRelayPointSelected($params['cart']->id);
     $carriersList = MondialRelay::_getCarriers();
     $address = new Address($this->context->cart->id_address_delivery);
     $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 !
         if (method_exists($params['cart'], 'carrierIsSelected')) {
             if ($params['cart']->carrierIsSelected($row['id_carrier'], $params['address']->id)) {
                 $id_carrier = $row['id_carrier'];
             }
         }
         $carrier = new Carrier((int) $row['id_carrier']);
         if ((Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false) || (!Configuration::get('PS_SHIPPING_METHOD') and $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) and $this->context->cart->id_address_delivery) ? Address::getZoneById((int) $this->context->cart->id_address_delivery) : (int) $this->context->country->id_zone;
                 if (Configuration::get('PS_SHIPPING_METHOD') && !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->context->cart->getTotalWeight(), $id_zone) || !Configuration::get('PS_SHIPPING_METHOD') && (!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 = MondialRelay::getMethodByIdCarrier($id_carrier);
     $this->context->smarty->assign(array('carriersextra' => $carriersList, 'preSelectedRelay' => isset($preSelectedRelay['MR_selected_num']) ? $preSelectedRelay['MR_selected_num'] : '', 'MR_carrier' => $carrier, 'MR_PS_VERSION' => _PS_VERSION_, 'MR_dlv_mode' => $id_carrier ? $carrier['dlv_mode'] : ''));
     return $this->fetchTemplate('/tpl/', 'checkout_process');
 }
Exemplo n.º 20
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;
 }
Exemplo n.º 21
0
 function displayOrderStep($params)
 {
     global $smarty, $cart, $cookie, $defaultCountry;
     if ($isVirtualCart = $cart->isVirtualCart()) {
         $cart->id_carrier = 0;
         $cart->update();
     }
     $smarty->assign('virtual_cart', $isVirtualCart);
     $address = new Address(intval($cart->id_address_delivery));
     $id_zone = Address::getZoneById($address->id);
     $result = Carrier::getCarriers(intval($cookie->id_lang), true, false, intval($id_zone));
     $resultsArray = array();
     foreach ($result as $k => $row) {
         $carrier = new Carrier(intval($row['id_carrier']));
         if (Configuration::get('PS_SHIPPING_METHOD') and !$carrier->getMaxDeliveryPriceByWeight($id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !$carrier->getMaxDeliveryPriceByPrice($id_zone)) {
             unset($result[$k]);
             continue;
         }
         if ($row['range_behavior']) {
             // Get id zone
             if (isset($cart->id_address_delivery) and $cart->id_address_delivery) {
                 $id_zone = Address::getZoneById(intval($cart->id_address_delivery));
             } else {
                 $id_zone = intval($defaultCountry->id_zone);
             }
             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->getOrderTotalLC(true, 4), $id_zone)) {
                 unset($result[$k]);
                 continue;
             }
         }
         $row['name'] = strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME');
         $row['price'] = $cart->getOrderShippingCostLC(intval($row['id_carrier']));
         $row['price_tax_exc'] = $cart->getOrderShippingCostLC(intval($row['id_carrier']), false);
         $row['img'] = file_exists(_PS_SHIP_IMG_DIR_ . intval($row['id_carrier']) . '.jpg') ? _THEME_SHIP_DIR_ . intval($row['id_carrier']) . '.jpg' : '';
         $row['extra'] = Module::hookExec('extraCarrierDetails', array("row" => $row, "carrier" => $carrier));
         $resultsArray[] = $row;
     }
     // Wrapping fees
     $wrapping_fees = floatval(Configuration::get('PS_GIFT_WRAPPING_PRICE'));
     $wrapping_fees_tax = new Tax(intval(Configuration::get('PS_GIFT_WRAPPING_TAX')));
     $wrapping_fees_tax_exc = $wrapping_fees / (1 + floatval($wrapping_fees_tax->rate) / 100);
     if (Validate::isUnsignedInt($cart->id_carrier)) {
         $carrier = new Carrier(intval($cart->id_carrier));
         if ($carrier->active and !$carrier->deleted) {
             $checked = intval($cart->id_carrier);
         }
     }
     if (!isset($checked)) {
         $checked = intval(Configuration::get('PS_CARRIER_DEFAULT'));
     }
     $smarty->assign(array('checkedTOS' => intval($cookie->checkedTOS), 'recyclablePackAllowed' => intval(Configuration::get('PS_RECYCLABLE_PACK')), 'giftAllowed' => intval(Configuration::get('PS_GIFT_WRAPPING')), 'conditions' => intval(Configuration::get('PS_CONDITIONS')), 'recyclable' => intval($cart->recyclable), 'gift_wrapping_price' => floatval(Configuration::get('PS_GIFT_WRAPPING_PRICE')), 'carriers' => $resultsArray, 'HOOK_EXTRACARRIER' => Module::hookExec('extraCarrier', array('address' => $address)), 'checked' => intval($checked), 'back' => strval(Tools::getValue('back')), 'total_wrapping' => number_format($wrapping_fees, 2, '.', ''), 'total_wrapping_tax_exc' => number_format($wrapping_fees_tax_exc, 2, '.', '')));
     Tools::safePostVars();
     $css_files = array(__PS_BASE_URI__ . 'css/thickbox.css' => 'all');
     $js_files = array(__PS_BASE_URI__ . 'js/jquery/thickbox-modified.js');
     include_once dirname(__FILE__) . '/../../header.php';
     echo $this->display(__FILE__, 'ordercarrier.tpl');
 }
Exemplo n.º 22
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;
 }
Exemplo n.º 23
0
 /**
  * Return shipping total
  *
  * @param integer $id_carrier Carrier ID (default : current carrier)
  * @return float Shipping total
  */
 function getOrderShippingCost($id_carrier = NULL, $useTax = true)
 {
     global $defaultCountry;
     if ($this->isVirtualCart()) {
         return 0;
     }
     // Checking discounts in cart
     $products = $this->getProducts();
     $discounts = $this->getDiscounts(true);
     if ($discounts) {
         foreach ($discounts as $id_discount) {
             if ($id_discount['id_discount_type'] == 3) {
                 if ($id_discount['minimal'] > 0) {
                     $total_cart = 0;
                     $categories = Discount::getCategories(intval($id_discount['id_discount']));
                     if (sizeof($categories)) {
                         foreach ($products as $product) {
                             if (Product::idIsOnCategoryId(intval($product['id_product']), $categories)) {
                                 $total_cart += $product['total_wt'];
                             }
                         }
                     }
                     if ($total_cart >= $id_discount['minimal']) {
                         return 0;
                     }
                 } else {
                     return 0;
                 }
             }
         }
     }
     // Order total without fees
     $orderTotal = $this->getOrderTotal(true, 7);
     // Start with shipping cost at 0
     $shipping_cost = 0;
     // If no product added, return 0
     if ($orderTotal <= 0 and !intval(self::getNbProducts($this->id))) {
         return $shipping_cost;
     }
     // Get id zone
     if (isset($this->id_address_delivery) and $this->id_address_delivery) {
         $id_zone = Address::getZoneById(intval($this->id_address_delivery));
     } else {
         $id_zone = intval($defaultCountry->id_zone);
     }
     // If no carrier, select default one
     if (!$id_carrier) {
         $id_carrier = $this->id_carrier;
     }
     if (empty($id_carrier)) {
         if (Configuration::get('PS_SHIPPING_METHOD') and Carrier::checkDeliveryPriceByWeight(intval(Configuration::get('PS_CARRIER_DEFAULT')), $this->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and Carrier::checkDeliveryPriceByPrice(intval(Configuration::get('PS_CARRIER_DEFAULT')), $this->getOrderTotal(true, 4), $id_zone)) {
             $id_carrier = intval(Configuration::get('PS_CARRIER_DEFAULT'));
         }
     }
     if (empty($id_carrier)) {
         if (intval($this->id_customer)) {
             $customer = new Customer(intval($this->id_customer));
             $result = Carrier::getCarriers(intval(Configuration::get('PS_LANG_DEFAULT')), true, false, intval($id_zone), $customer->getGroups());
             unset($customer);
         } else {
             $result = Carrier::getCarriers(intval(Configuration::get('PS_LANG_DEFAULT')), true, false, intval($id_zone));
         }
         $resultsArray = array();
         foreach ($result as $k => $row) {
             if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT')) {
                 continue;
             }
             if (!isset(self::$_carriers[$row['id_carrier']])) {
                 self::$_carriers[$row['id_carrier']] = new Carrier(intval($row['id_carrier']));
             }
             $carrier = self::$_carriers[$row['id_carrier']];
             // Get only carriers that are compliant with shipping method
             if (Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false or !Configuration::get('PS_SHIPPING_METHOD') and $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 only carriers that have a range compatible with cart
                 if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->getOrderTotal(true, 4), $id_zone)) {
                     unset($result[$k]);
                     continue;
                 }
             }
             if (intval(Configuration::get('PS_SHIPPING_METHOD'))) {
                 $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone);
                 if (!isset($tmp)) {
                     $tmp = $shipping;
                 }
                 if ($shipping <= $tmp) {
                     $id_carrier = intval($row['id_carrier']);
                 }
             } else {
                 $shipping = $carrier->getDeliveryPriceByPrice($orderTotal, $id_zone);
                 if (!isset($tmp)) {
                     $tmp = $shipping;
                 }
                 if ($shipping <= $tmp) {
                     $id_carrier = intval($row['id_carrier']);
                 }
             }
         }
     }
     if (empty($id_carrier)) {
         $id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (!isset(self::$_carriers[$id_carrier])) {
         self::$_carriers[$id_carrier] = new Carrier(intval($id_carrier));
     }
     $carrier = self::$_carriers[$id_carrier];
     if (!Validate::isLoadedObject($carrier)) {
         die(Tools::displayError('Fatal error: "no default carrier"'));
     }
     if (!$carrier->active) {
         return $shipping_cost;
     }
     // Select carrier tax
     if ($useTax and $carrier->id_tax) {
         if (!isset(self::$_taxes[$carrier->id_tax])) {
             self::$_taxes[$carrier->id_tax] = new Tax(intval($carrier->id_tax));
         }
         $tax = self::$_taxes[$carrier->id_tax];
         if (Validate::isLoadedObject($tax) and Tax::zoneHasTax(intval($tax->id), intval($id_zone)) and !Tax::excludeTaxeOption()) {
             $carrierTax = $tax->rate;
         }
     }
     $configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
     // Free fees
     $free_fees_price = 0;
     if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) {
         $free_fees_price = Tools::convertPrice(floatval($configuration['PS_SHIPPING_FREE_PRICE']), new Currency(intval($this->id_currency)));
     }
     $orderTotalwithDiscounts = $this->getOrderTotal(true, 4);
     if ($orderTotalwithDiscounts >= floatval($free_fees_price) and floatval($free_fees_price) > 0) {
         return $shipping_cost;
     }
     if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) and $this->getTotalWeight() >= floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) and floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0) {
         return $shipping_cost;
     }
     // Get shipping cost using correct method
     if ($carrier->range_behavior) {
         // Get id zone
         if (isset($this->id_address_delivery) and $this->id_address_delivery) {
             $id_zone = Address::getZoneById(intval($this->id_address_delivery));
         } else {
             $id_zone = intval($defaultCountry->id_zone);
         }
         if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice($carrier->id, $this->getOrderTotal(true, 4), $id_zone)) {
             $shipping_cost += 0;
         } else {
             if (intval($configuration['PS_SHIPPING_METHOD'])) {
                 $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone);
             } else {
                 $shipping_cost += $carrier->getDeliveryPriceByPrice($orderTotal, $id_zone);
             }
         }
     } else {
         if (intval($configuration['PS_SHIPPING_METHOD'])) {
             $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone);
         } else {
             $shipping_cost += $carrier->getDeliveryPriceByPrice($orderTotal, $id_zone);
         }
     }
     // Adding handling charges
     if (isset($configuration['PS_SHIPPING_HANDLING']) and $carrier->shipping_handling) {
         $shipping_cost += floatval($configuration['PS_SHIPPING_HANDLING']);
     }
     $shipping_cost = Tools::convertPrice($shipping_cost, new Currency(intval($this->id_currency)));
     // Apply tax
     if (isset($carrierTax)) {
         $shipping_cost *= 1 + $carrierTax / 100;
     }
     return floatval(Tools::ps_round(floatval($shipping_cost), 2));
 }