コード例 #1
0
ファイル: Order.php プロジェクト: Oldwo1f/yakaboutique
    public function getTotalWeight()
    {
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
		SELECT SUM(product_weight * ' . PP::sqlQty('product_quantity') . ')
		FROM ' . _DB_PREFIX_ . 'order_detail
		WHERE id_order = ' . (int) $this->id);
        return (double) $result;
    }
コード例 #2
0
 protected function getQuantitySold($id_product, $id_product_attribute, $coverage)
 {
     $query = new DbQuery();
     $query->select('SUM(' . PP::sqlQty('product_quantity', 'od') . ')');
     $query->from('order_detail', 'od');
     $query->leftJoin('orders', 'o', 'od.id_order = o.id_order');
     $query->leftJoin('order_history', 'oh', 'o.date_upd = oh.date_add');
     $query->leftJoin('order_state', 'os', 'os.id_order_state = oh.id_order_state');
     $query->where('od.product_id = ' . (int) $id_product);
     $query->where('od.product_attribute_id = ' . (int) $id_product_attribute);
     $query->where('TO_DAYS(NOW()) - TO_DAYS(oh.date_add) <= ' . (int) $coverage);
     $query->where('o.valid = 1');
     $query->where('os.logable = 1 AND os.delivery = 1 AND os.shipped = 1');
     $quantity = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
     return $quantity;
 }
コード例 #3
0
ファイル: Product.php プロジェクト: Oldwo1f/yakaboutique
    public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null, $only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null, $id_address = null, &$specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, Context $context = null, $use_customer_price = true)
    {
        if (!$context) {
            $context = Context::getContext();
        }
        $cur_cart = $context->cart;
        if ($divisor !== null) {
            Tools::displayParameterAsDeprecated('divisor');
        }
        if (!Validate::isBool($usetax) || !Validate::isUnsignedId($id_product)) {
            die(Tools::displayError());
        }
        $id_group = null;
        if ($id_customer) {
            $id_group = Customer::getDefaultGroupId((int) $id_customer);
        }
        if (!$id_group) {
            $id_group = (int) Group::getCurrent()->id;
        }
        if (!is_object($cur_cart) || Validate::isUnsignedInt($id_cart) && $id_cart && $cur_cart->id != $id_cart) {
            /*
             * When a user (e.g., guest, customer, Google...) is on PrestaShop, he has already its cart as the global (see /init.php)
             * When a non-user calls directly this method (e.g., payment module...) is on PrestaShop, he does not have already it BUT knows the cart ID
             * When called from the back office, cart ID can be inexistant
             */
            if (!$id_cart && !isset($context->employee)) {
                die(Tools::displayError());
            }
            $cur_cart = new Cart($id_cart);
            if (!Validate::isLoadedObject($context->cart)) {
                $context->cart = $cur_cart;
            }
        }
        $qty = $quantity;
        if (is_array($quantity)) {
            $quantity = PP::resolveQty($qty[0], $qty[1]);
        }
        $cart_quantity = 0;
        if ((int) $id_cart) {
            $cache_id = 'Product::getPriceStatic_' . (int) $id_product . '-' . (int) $id_cart;
            if (!Cache::isStored($cache_id) || ($cart_quantity = Cache::retrieve($cache_id) != (double) $quantity)) {
                $sql = 'SELECT SUM(' . PP::sqlQty('quantity') . ')
				FROM `' . _DB_PREFIX_ . 'cart_product`
				WHERE `id_product` = ' . (int) $id_product . '
				AND `id_cart` = ' . (int) $id_cart;
                $cart_quantity = (double) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
                Cache::store($cache_id, $cart_quantity);
            }
            $cart_quantity = Cache::retrieve($cache_id);
        }
        $id_currency = (int) Validate::isLoadedObject($context->currency) ? $context->currency->id : Configuration::get('PS_CURRENCY_DEFAULT');
        $id_country = (int) $context->country->id;
        $id_state = 0;
        $zipcode = 0;
        if (!$id_address && Validate::isLoadedObject($cur_cart)) {
            $id_address = $cur_cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
        }
        if ($id_address) {
            $address_infos = Address::getCountryAndState($id_address);
            if ($address_infos['id_country']) {
                $id_country = (int) $address_infos['id_country'];
                $id_state = (int) $address_infos['id_state'];
                $zipcode = $address_infos['postcode'];
            }
        } elseif (isset($context->customer->geoloc_id_country)) {
            $id_country = (int) $context->customer->geoloc_id_country;
            $id_state = (int) $context->customer->id_state;
            $zipcode = $context->customer->postcode;
        }
        if (Tax::excludeTaxeOption()) {
            $usetax = false;
        }
        if ($usetax != false && !empty($address_infos['vat_number']) && $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') && Configuration::get('VATNUMBER_MANAGEMENT')) {
            $usetax = false;
        }
        if (is_null($id_customer) && Validate::isLoadedObject($context->customer)) {
            $id_customer = $context->customer->id;
        }
        return Product::priceCalculation($context->shop->id, $id_product, $id_product_attribute, $id_country, $id_state, $zipcode, $id_currency, $id_group, $qty, $usetax, $decimals, $only_reduc, $usereduc, $with_ecotax, $specific_price_output, $use_group_reduction, $id_customer, $use_customer_price, $id_cart, $cart_quantity);
    }
コード例 #4
0
ファイル: Product.php プロジェクト: Oldwo1f/yakaboutique
    public static function isDiscounted($id_product, $quantity = 1, Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }
        $id_group = $context->customer->id_default_group;
        $cart_quantity = !$context->cart ? 0 : Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
			SELECT SUM(' . PP::sqlQty('quantity') . ')
			FROM `' . _DB_PREFIX_ . 'cart_product`
			WHERE `id_product` = ' . (int) $id_product . ' AND `id_cart` = ' . (int) $context->cart->id);
        $quantity = $cart_quantity ? $cart_quantity : $quantity;
        $id_currency = (int) $context->currency->id;
        $ids = Address::getCountryAndState((int) $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
        $id_country = $ids['id_country'] ? (int) $ids['id_country'] : (int) Configuration::get('PS_COUNTRY_DEFAULT');
        return (bool) SpecificPrice::getSpecificPrice((int) $id_product, $context->shop->id, $id_currency, $id_country, $id_group, $quantity, null, 0, 0, $quantity);
    }
コード例 #5
0
ファイル: Cart.php プロジェクト: Oldwo1f/yakaboutique
    public function getTotalWeight($products = null)
    {
        if (!is_null($products)) {
            $total_weight = 0;
            foreach ($products as $product) {
                if (!isset($product['weight_attribute']) || is_null($product['weight_attribute'])) {
                    $total_weight += $product['weight'] * PP::resolveQty($product['cart_quantity'], $product['cart_quantity_fractional']);
                } else {
                    $total_weight += $product['weight_attribute'] * PP::resolveQty($product['cart_quantity'], $product['cart_quantity_fractional']);
                }
            }
            return $total_weight;
        }
        if (!isset(self::$_totalWeight[$this->id])) {
            if (Combination::isFeatureActive()) {
                $weight_product_with_attribute = Db::getInstance()->getValue('
				SELECT SUM((p.`weight` + pa.`weight`) * ' . PP::sqlQty('quantity', 'cp') . ') as nb
				FROM `' . _DB_PREFIX_ . 'cart_product` cp
				LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (cp.`id_product` = p.`id_product`)
				LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (cp.`id_product_attribute` = pa.`id_product_attribute`)
				WHERE (cp.`id_product_attribute` IS NOT NULL AND cp.`id_product_attribute` != 0)
				AND cp.`id_cart` = ' . (int) $this->id);
            } else {
                $weight_product_with_attribute = 0;
            }
            $weight_product_without_attribute = Db::getInstance()->getValue('
			SELECT SUM(p.`weight` * ' . PP::sqlQty('quantity', 'cp') . ') as nb
			FROM `' . _DB_PREFIX_ . 'cart_product` cp
			LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (cp.`id_product` = p.`id_product`)
			WHERE (cp.`id_product_attribute` IS NULL OR cp.`id_product_attribute` = 0)
			AND cp.`id_cart` = ' . (int) $this->id);
            self::$_totalWeight[$this->id] = round((double) $weight_product_with_attribute + (double) $weight_product_without_attribute, 3);
        }
        return self::$_totalWeight[$this->id];
    }