コード例 #1
0
ファイル: Carrier.php プロジェクト: juanchog/modules-1.6.0.12
 public function getTaxesRate(Address $address)
 {
     /*
      * EU-Legal
      * alternative method for tax calculation instead of static taxrate (LEGAL_SHIPTAXMETH)
      * Only if Cart exists and at least one product in cart, otherwise the alternative method could not be applied
      */
     if (Configuration::get('LEGAL_SHIPTAXMETH') && ($cart = Context::getContext()->cart) && ($products = $cart->getProducts()) && !empty($products)) {
         return Cart::getTaxesAverageUsed($cart->id);
     }
     return parent::getTaxesRate($address);
 }
コード例 #2
0
ファイル: Discount.php プロジェクト: greench/prestashop
 /**
  * Return discount value
  *
  * @param integer $nb_discounts Number of discount currently in cart
  * @param boolean $order_total_products Total cart products amount
  * @return mixed Return a float value or '!' if reduction is 'Shipping free'
  */
 public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true)
 {
     $totalAmount = 0;
     $cart = new Cart((int) $idCart);
     if (!Validate::isLoadedObject($cart)) {
         return 0;
     }
     if (!$this->cumulable and (int) $nb_discounts > 1 or !$this->active or !$this->quantity and !$cart->OrderExists()) {
         return 0;
     }
     if ($this->usedByCustomer((int) $cart->id_customer) >= $this->quantity_per_user and !$cart->OrderExists()) {
         return 0;
     }
     $date_start = strtotime($this->date_from);
     $date_end = strtotime($this->date_to);
     if ((time() < $date_start or time() > $date_end) and !$cart->OrderExists()) {
         return 0;
     }
     $products = $cart->getProducts();
     $categories = Discount::getCategories((int) $this->id);
     foreach ($products as $product) {
         if (count($categories) and Product::idIsOnCategoryId($product['id_product'], $categories)) {
             $totalAmount += $this->include_tax ? $product['total_wt'] : $product['total'];
         }
     }
     if ($this->minimal > 0 and $totalAmount < $this->minimal) {
         return 0;
     }
     switch ($this->id_discount_type) {
         /* Relative value (% of the order total) */
         case 1:
             $amount = 0;
             $percentage = $this->value / 100;
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                     if ($this->cumulable_reduction or !$product['reduction_applies'] and !$product['on_sale']) {
                         $amount += ($useTax ? $product['total_wt'] : $product['total']) * $percentage;
                     }
                 }
             }
             return $amount;
             /* Absolute value */
         /* Absolute value */
         case 2:
             // An "absolute" voucher is available in one currency only
             $currency = (int) $cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : Currency::getCurrent();
             if ($this->id_currency != $currency->id) {
                 return 0;
             }
             $taxDiscount = Cart::getTaxesAverageUsed((int) $cart->id);
             if (!$useTax and isset($taxDiscount) and $taxDiscount != 1) {
                 $this->value = abs($this->value / (1 + $taxDiscount * 0.01));
             }
             // Main return
             $value = 0;
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                     $value = $this->value;
                 }
             }
             // Return 0 if there are no applicable categories
             return $value;
             /* Free shipping (does not return a value but a special code) */
         /* Free shipping (does not return a value but a special code) */
         case 3:
             return '!';
     }
     return 0;
 }
コード例 #3
0
ファイル: Cart.php プロジェクト: juanchog/modules-1.6.0.12
 public function getGiftWrappingPrice($with_taxes = true, $id_address = null)
 {
     static $address = array();
     /*
      * EU-Legal
      * alternative method for tax calculation (LEGAL_SHIPTAXMETH)
      */
     if (!Configuration::get('LEGAL_SHIPTAXMETH')) {
         parent::getGiftWrappingPrice($with_taxes, $id_address);
     }
     $wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE');
     if ($with_taxes && $wrapping_fees > 0) {
         $tax_rate = Cart::getTaxesAverageUsed((int) $this->id);
         -($wrapping_fees = $wrapping_fees * (1 + $tax_rate / 100));
     }
     return $wrapping_fees;
 }
コード例 #4
0
ファイル: order.php プロジェクト: jeprodev/jeproshop
 public function getTaxesAverageUsed()
 {
     return Cart::getTaxesAverageUsed((int) $this->id_cart);
 }
コード例 #5
0
ファイル: Discount.php プロジェクト: Evil1991/PrestaShop-1.4
 /**
  * Return discount value
  *
  * @param integer $nb_discounts Number of discount currently in cart
  * @param boolean $order_total_products Total cart products amount
  * @param boolean $shipping_fees Total cart products amount
  * @param integer $id_cart Cart ID
  * @param boolean $use_tax Enable tax calculations
  * @return mixed Return a float value or '!' if reduction is 'Shipping free'
  */
 public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $id_cart = 0, $use_tax = true)
 {
     global $cart;
     $c = $id_cart && isset($cart->id) && $cart->id == $id_cart ? $cart : ($id_cart ? new Cart((int) $id_cart) : null);
     if (!Validate::isLoadedObject($c) || (!$this->cumulable && (int) $nb_discounts > 1 || !$this->active || !$this->quantity && !$c->OrderExists()) || $c->id_customer && $this->usedByCustomer((int) $c->id_customer, false) >= $this->quantity_per_user && !$c->OrderExists() || (time() < strtotime($this->date_from) || time() > strtotime($this->date_to)) && !$c->OrderExists()) {
         return 0;
     }
     $products = $c->getProducts();
     $categories = self::getCategories((int) $this->id, false);
     $totalAmount = 0;
     foreach ($products as $product) {
         if (count($categories) && Product::idIsOnCategoryId($product['id_product'], $categories)) {
             $totalAmount += $this->include_tax ? $product['total_wt'] : $product['total'];
         }
     }
     if ($this->minimal > 0 && $totalAmount < $this->minimal) {
         return 0;
     }
     switch ($this->id_discount_type) {
         /* Relative value (% of the order total) */
         case 1:
             $amount = 0;
             $percentage = $this->value / 100;
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories) && ($this->cumulable_reduction || !$product['reduction_applies'] && !$product['on_sale'])) {
                     $amount += ($use_tax ? $product['total_wt'] : $product['total']) * $percentage;
                 }
             }
             return $amount;
             /* Absolute value */
         /* Absolute value */
         case 2:
             /* This type of voucher is restricted to a specific currency */
             if ($c->id_currency) {
                 $id_currency = (int) $c->id_currency;
             } else {
                 global $cookie;
                 if ($cookie->id_currency) {
                     $id_currency = (int) $cookie->id_currency;
                 }
             }
             if (!isset($id_currency)) {
                 $id_currency = (int) _PS_CURRENCY_DEFAULT_;
             }
             if ($this->id_currency != $id_currency) {
                 return 0;
             }
             if (!$use_tax) {
                 $taxDiscount = Cart::getTaxesAverageUsed((int) $c->id);
                 if ($taxDiscount != 1) {
                     $this->value = abs($this->value / (1 + $taxDiscount * 0.01));
                 }
             }
             // Main return
             $value = 0;
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                     $value = $this->value;
                 }
             }
             // Return 0 if there are no applicable categories
             return $value;
             /* Free shipping (does not return a value but a special code) */
         /* Free shipping (does not return a value but a special code) */
         case 3:
             return '!';
     }
     return 0;
 }