Exemplo n.º 1
0
    public function getMaxDeliveryPriceByPrice($id_zone)
    {
        $cache_id = 'Carrier::getMaxDeliveryPriceByPrice_' . (int) $this->id . '-' . (int) $id_zone;
        if (!Cache::isStored($cache_id)) {
            $sql = 'SELECT d.`price`
					FROM `' . _DB_PREFIX_ . 'delivery` d
					INNER JOIN `' . _DB_PREFIX_ . 'range_price` r ON d.`id_range_price` = r.`id_range_price`
					WHERE d.`id_zone` = ' . (int) $id_zone . '
						AND d.`id_carrier` = ' . (int) $this->id . '
						' . Carrier::sqlDeliveryRangeShop('range_price') . '
					ORDER BY r.`delimiter2` DESC';
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
            Cache::store($cache_id, $result);
        }
        return Cache::retrieve($cache_id);
    }
Exemplo n.º 2
0
    /**
     * Get delivery prices for a given shipping method (price/weight)
     *
     * @param string $range_table Table name (price or weight)
     * @param int    $id_carrier  Carrier ID
     *
     * @return array Delivery prices
     */
    public static function getDeliveryPriceByRanges($range_table, $id_carrier)
    {
        $sql = 'SELECT d.`id_' . bqSQL($range_table) . '`, d.id_carrier, d.id_zone, d.price
				FROM ' . _DB_PREFIX_ . 'delivery d
				LEFT JOIN `' . _DB_PREFIX_ . bqSQL($range_table) . '` r ON r.`id_' . bqSQL($range_table) . '` = d.`id_' . bqSQL($range_table) . '`
				WHERE d.id_carrier = ' . (int) $id_carrier . '
					AND d.`id_' . bqSQL($range_table) . '` IS NOT NULL
					AND d.`id_' . bqSQL($range_table) . '` != 0
					' . Carrier::sqlDeliveryRangeShop($range_table) . '
				ORDER BY r.delimiter1';
        return Db::getInstance()->executeS($sql);
    }
Exemplo n.º 3
0
    /**
     * Get delivery prices for a given order
     *
     * @param float $orderTotal Order total to pay
     * @param integer $zone_id Zone id (for customer delivery address)
     * @param integer $currency_id
     * @return float Delivery price
     */
    public function getDeliveryPriceByPrice($orderTotal, $zone_id, $currency_id = null)
    {
        $cache_key = $this->id . '_' . $order_total . '_' . $zone_id . '_' . $currency_id;
        if (!isset(self::$price_by_price[$cache_key])) {
            if (!empty($currency_id)) {
                $order_total = Tools::convertPrice($order_total, $currency_id, false);
            }
            $sql = 'SELECT d.`price`
					FROM `' . _DB_PREFIX_ . 'delivery` d
					LEFT JOIN `' . _DB_PREFIX_ . 'range_price` r ON d.`id_range_price` = r.`id_range_price`
					WHERE d.`zone_id` = ' . (int) $zone_id . '
						AND ' . (double) $order_total . ' >= r.`delimiter1`
						AND ' . (double) $order_total . ' < r.`delimiter2`
						AND d.`id_carrier` = ' . (int) $this->id . '
						' . Carrier::sqlDeliveryRangeShop('range_price') . '
					ORDER BY r.`delimiter1` ASC';
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
            if (!isset($result['price'])) {
                self::$price_by_price[$cache_key] = $this->getMaxDeliveryPriceByPrice($zone_id);
            } else {
                self::$price_by_price[$cache_key] = $result['price'];
            }
        }
        return self::$price_by_price[$cache_key];
    }