Exemplo n.º 1
0
 /**
  * Calculate taxes that apply to the item
  *
  * @author Jonathan Davis
  * @since 1.3
  *
  * @param integer $quantity The taxable quantity of items
  * @return void
  **/
 public function taxes($quantity = 1)
 {
     if (!$this->istaxed) {
         return do_action('shopp_cart_item_taxes', $this);
     }
     $Tax = ShoppOrder()->Tax;
     if (empty($Tax)) {
         $Tax = new ShoppTax();
     }
     // ShoppTax support for Dev API calls
     // For all the price units (base product and any addons),
     // distribute discounts across taxable amounts using weighted averages
     $_ = array();
     if ($this->unitprice > 0) {
         $taxable = 0;
         foreach ($this->taxable as $amount) {
             $_[] = $amount - $amount / $this->unitprice * $this->discount;
         }
     }
     $taxable = (double) array_sum($_);
     $taxableqty = $this->bogof && $this->bogof != $this->quantity ? $this->quantity - $this->bogof : $this->quantity;
     $Tax->rates($this->taxes, $Tax->item($this));
     $this->unittax = ShoppTax::calculate($this->taxes, $taxable);
     $this->tax = $Tax->total($this->taxes, (int) $taxableqty);
     // Handle inclusive tax price adjustments for non-EU markets or alternate tax rate markets
     $adjustment = ShoppTax::adjustment($this->taxes);
     if (1 != $adjustment) {
         if (!isset($this->taxprice)) {
             $this->taxprice = $this->unitprice;
         }
         // Modify the unitprice from the original tax inclusive price and update the discounted price
         $this->unitprice = $this->taxprice / $adjustment;
         $this->priced = $this->unitprice - $this->discount;
     } elseif (isset($this->taxprice)) {
         // Undo tax price adjustments
         $this->unitprice = $this->taxprice;
         unset($this->taxprice);
     }
     do_action('shopp_cart_item_taxes', $this);
 }
Exemplo n.º 2
0
 public static function baserates($Item = null)
 {
     // Get base tax rate
     $base = shopp_setting('base_operations');
     $BaseTax = new ShoppTax();
     $BaseTax->location($base['country'], false, false);
     // Calculate the deduction
     $baserates = array();
     $BaseTax->rates($baserates, $BaseTax->item($Item));
     return (array) $baserates;
 }
Exemplo n.º 3
0
 /**
  * Determines all applicable tax rates for the store or an item
  *
  * @author Jonathan Davis
  * @since 1.0
  * @version 1.3
  *
  * @param Object $Item (optional) The ShoppProduct, ShoppCartItem or ShoppPurchased object to find tax rates for
  * @return float The determined tax rate
  **/
 public static function taxrates($Item = null)
 {
     $Tax = new ShoppTax();
     $Order = ShoppOrder();
     // Setup taxable address
     $Tax->address($Order->Billing, $Order->Shipping, $Order->Cart->shipped());
     $taxes = array();
     if (is_null($Item)) {
         $Tax->rates($taxes);
     } else {
         $Tax->rates($taxes, $Tax->item($Item));
     }
     return apply_filters('shopp_taxrates', $taxes);
 }
Exemplo n.º 4
0
 public static function baserates($Item = null)
 {
     // Get base tax rate
     $BaseTax = new ShoppTax();
     $BaseTax->location(ShoppBaseLocale()->country(), false, false);
     // Calculate the deduction
     $baserates = array();
     $BaseTax->rates($baserates, $BaseTax->item($Item));
     return (array) $baserates;
 }