示例#1
0
 protected function setDetailProductPrice(Order $order, Cart $cart, $product)
 {
     $this->setContext((int) $product['id_shop']);
     $specific_price = $null = null;
     Product::getPriceStatic((int) $product['id_product'], true, (int) $product['id_product_attribute'], 6, null, false, true, array($product['cart_quantity'], $product['cart_quantity_fractional']), false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $specific_price, true, true, $this->context);
     $this->specificPrice = $specific_price;
     $this->original_product_price = Product::getPriceStatic($product['id_product'], false, (int) $product['id_product_attribute'], 6, null, false, false, 1, false, null, null, null, $null, true, true, $this->context);
     $this->product_price = $this->original_product_price;
     $this->unit_price_tax_incl = (double) $product['price_wt'];
     $this->unit_price_tax_excl = (double) $product['price'];
     $this->total_price_tax_incl = (double) $product['total_wt'];
     $this->total_price_tax_excl = (double) $product['total'];
     $this->purchase_supplier_price = (double) $product['wholesale_price'];
     if ($product['id_supplier'] > 0 && ($supplier_price = ProductSupplier::getProductPrice((int) $product['id_supplier'], $product['id_product'], $product['id_product_attribute'], true)) > 0) {
         $this->purchase_supplier_price = (double) $supplier_price;
     }
     $this->setSpecificPrice($order, $product);
     $this->group_reduction = (double) Group::getReduction((int) $order->id_customer);
     $shop_id = $this->context->shop->id;
     $quantity_discount = SpecificPrice::getQuantityDiscount((int) $product['id_product'], $shop_id, (int) $cart->id_currency, (int) $this->vat_address->id_country, (int) $this->customer->id_default_group, (int) PP::resolveQty($product['cart_quantity'], $product['cart_quantity_fractional']), false, null, null, $null, true, true, $this->context);
     $unit_price = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : null, 2, null, false, true, 1, false, (int) $order->id_customer, null, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $null, true, true, $this->context);
     $this->product_quantity_discount = 0.0;
     if ($quantity_discount) {
         $this->product_quantity_discount = $unit_price;
         if (Product::getTaxCalculationMethod((int) $order->id_customer) == PS_TAX_EXC) {
             $this->product_quantity_discount = Tools::ps_round($unit_price, 2);
         }
         if (isset($this->tax_calculator)) {
             $this->product_quantity_discount -= $this->tax_calculator->addTaxes($quantity_discount['price']);
         }
     }
     $this->discount_quantity_applied = $this->specificPrice && $this->specificPrice['from_quantity'] > PP::getSpecificPriceFromQty((int) $product['id_product']) ? 1 : 0;
     $this->id_cart_product = (int) $product['id_cart_product'];
     $this->product_quantity_fractional = (double) $product['cart_quantity_fractional'];
     $ppropertiessmartprice_hook3 = null;
 }
示例#2
0
    public static function getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_product_attribute = null, $all_combinations = false, $id_customer = 0)
    {
        if (!SpecificPrice::isFeatureActive()) {
            return array();
        }
        $now = date('Y-m-d H:i:s');
        $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT *,
					' . SpecificPrice::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_customer) . '
			FROM `' . _DB_PREFIX_ . 'specific_price`
			WHERE
					`id_product` IN(0, ' . (int) $id_product . ') AND
					' . (!$all_combinations ? '`id_product_attribute` IN(0, ' . (int) $id_product_attribute . ') AND ' : '') . '
					`id_shop` IN(0, ' . (int) $id_shop . ') AND
					`id_currency` IN(0, ' . (int) $id_currency . ') AND
					`id_country` IN(0, ' . (int) $id_country . ') AND
					`id_group` IN(0, ' . (int) $id_group . ') AND
					`id_customer` IN(0, ' . (int) $id_customer . ')
					AND
					(
						(`from` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' >= `from`)
						AND
						(`to` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' <= `to`)
					)
					ORDER BY `from_quantity` ASC, `id_specific_price_rule` ASC, `score` DESC
		');
        $targeted_prices = array();
        $last_quantity = array();
        foreach ($res as $specific_price) {
            if (!isset($last_quantity[(int) $specific_price['id_product_attribute']])) {
                $last_quantity[(int) $specific_price['id_product_attribute']] = $specific_price['from_quantity'];
            } elseif ($last_quantity[(int) $specific_price['id_product_attribute']] == $specific_price['from_quantity']) {
                continue;
            }
            $last_quantity[(int) $specific_price['id_product_attribute']] = $specific_price['from_quantity'];
            if ($specific_price['from_quantity'] > PP::getSpecificPriceFromQty((int) $id_product)) {
                $targeted_prices[] = $specific_price;
            }
        }
        return $targeted_prices;
    }