示例#1
0
 /**
  * Filter callback to add standard monetary option behaviors
  *
  * @internal
  * @since 1.2
  *
  * @param string    $result    The output
  * @param array     $options   The options
  * - **wrap**: `on` (on, off) Wrap the amount in DOM-accessible markup
  * - **money**: `on` (on, off) Format the amount in the current currency format
  * - **number**: `off` (on, off) Provide the unformatted number (floating point)
  * @param string    $property  The tag property name
  * @param ShoppCart $O         The working object
  * @return ShoppCart The active ShoppCart context
  **/
 public static function _cart($result, $options, $property, $O)
 {
     // Passthru for non-monetary results
     $monetary = array('discount', 'subtotal', 'shipping', 'tax', 'total');
     if (!in_array($property, $monetary) || !is_numeric($result)) {
         return $result;
     }
     // @deprecated currency parameter
     if (isset($options['currency'])) {
         $options['money'] = $options['currency'];
     }
     // @deprecated wrapper parameter
     if (isset($options['wrapper'])) {
         $options['wrap'] = $options['wrapper'];
     }
     $defaults = array('wrap' => 'on', 'money' => 'on', 'number' => false);
     $options = array_merge($defaults, $options);
     extract($options);
     if (Shopp::str_true($number)) {
         return $result;
     }
     if (Shopp::str_true($money)) {
         $result = money(roundprice($result));
     }
     if (Shopp::str_true($wrap)) {
         return '<span class="shopp-cart cart-' . strtolower($property) . '">' . $result . '</span>';
     }
     return $result;
 }
示例#2
0
 /**
  * Filter callback to add standard monetary option behaviors
  *
  * @internal
  * @since 1.2
  *
  * @param string    $result    The output
  * @param array     $options   The options
  * - **money**: `on` (on, off) Format the amount in the current currency format
  * - **number**: `off` (on, off) Provide the unformatted number (floating point)
  * @param string    $property  The tag property name
  * @param ShoppCart $O         The working object
  * @return ShoppCart The active ShoppCart context
  **/
 public static function _cartitem($result, $options, $property, $O)
 {
     // Passthru for non-monetary results
     $monetary = array('discount', 'unitprice', 'unittax', 'discounts', 'tax', 'total', 'price', 'prices', 'saleprice', 'saleprices');
     if (!in_array($property, $monetary) || !is_numeric($result)) {
         return $result;
     }
     // @deprecated currency parameter
     if (isset($options['currency'])) {
         $options['money'] = $options['currency'];
     }
     $defaults = array('money' => 'on', 'number' => false, 'show' => '');
     $options = array_merge($defaults, $options);
     extract($options);
     if (in_array($show, array('%', 'percent'))) {
         return $result;
     }
     // Pass thru percentage rendering
     if (Shopp::str_true($number)) {
         return $result;
     }
     if (Shopp::str_true($money)) {
         $result = money(roundprice($result));
     }
     return $result;
 }
示例#3
0
	/**
	 * Calculates total taxes
	 *	 
	 * @since 1.1
	 *
	 * @return float Total tax amount
	 **/
	function calculate () {
		$Totals =& $this->Order->Cart->Totals;

		$tiers = array();
		$taxes = 0;
		foreach ($this->Order->Cart->contents as $id => &$Item) {
			if (!$Item->taxable) continue;
			$Item->taxrate = $this->rate($Item);

			if (!isset($tiers[$Item->taxrate])) $tiers[$Item->taxrate] = $Item->total;
			else $tiers[$Item->taxrate] += $Item->total;

			$taxes += $Item->tax;
		}

		if ($this->shipping) {
			if ($this->vat) // Remove the taxes from the shipping amount for inclusive-tax calculations
				$Totals->shipping = (floatvalue($Totals->shipping)/(1+$Totals->taxrate));
			$taxes += roundprice($Totals->shipping*$Totals->taxrate);
		}

		return $taxes;
	}
示例#4
0
文件: Item.php 项目: borkweb/shopp
 /**
  * Loads or constructs the Item object from product and product pricing parameters
  *
  * @author John Dillick, Jonathan Davis
  * @since 1.2
  *
  * @param object $Product Product object
  * @param mixed $pricing A list of price IDs; The option key of a price object; or a Price object
  * @param int $category (optional)The breadcrumb category ID where the product was added from
  * @param array $data (optional) Custom data associated with the line item
  * @param array $addons (optional) A set of addon options
  * @return void
  **/
 public function load($Product, $pricing, $category = false, $data = array(), $addons = array())
 {
     $Product->load_data();
     // If option ids are passed, lookup by option key, otherwise by id
     $Price = false;
     if (is_array($pricing) && !empty($pricing)) {
         $optionkey = $Product->optionkey($pricing);
         if (!isset($Product->pricekey[$optionkey])) {
             $optionkey = $Product->optionkey($pricing, true);
         }
         // deprecated prime
         if (isset($Product->pricekey[$optionkey])) {
             $Price = $Product->pricekey[$optionkey];
         }
     } elseif (is_numeric($pricing)) {
         $Price = $Product->priceid[$pricing];
     } elseif (is_a($pricing, 'ShoppPrice')) {
         $Price = $pricing;
     }
     // Find single product priceline
     if (!$Price && !Shopp::str_true($Product->variants)) {
         foreach ($Product->prices as &$Price) {
             $stock = true;
             if (Shopp::str_true($Price->inventory) && 1 > $Price->stock) {
                 $stock = false;
             }
             if ('product' == $Price->context && 'N/A' != $Price->type && $stock) {
                 break;
             }
         }
     }
     // Find first available variant priceline
     if (!$Price && Shopp::str_true($Product->variants)) {
         foreach ($Product->prices as &$Price) {
             $stock = true;
             if (Shopp::str_true($Price->inventory) && 1 > $Price->stock) {
                 $stock = false;
             }
             if ('variation' == $Price->context && 'N/A' != $Price->type && $stock) {
                 break;
             }
         }
     }
     if (isset($Product->id)) {
         $this->product = $Product->id;
     }
     if (isset($Price->id)) {
         $this->priceline = $Price->id;
     }
     $this->name = $Product->name;
     $this->slug = $Product->slug;
     $this->category = $category;
     $this->categories = $this->namelist($Product->categories);
     $this->tags = $this->namelist($Product->tags);
     $this->image = current($Product->images);
     $this->description = $Product->summary;
     if (shopp_setting_enabled('taxes')) {
         // Must init taxable above addons roll-up #2825
         $this->taxable = array();
     }
     // Re-init during ShoppCart::change() loads #2922
     // Product has variants
     if (Shopp::str_true($Product->variants) && empty($this->variants)) {
         $this->variants($Product->prices);
     }
     // Product has Addons
     if (Shopp::str_true($Product->addons)) {
         if (!empty($this->addons)) {
             // Compute addon differences
             $addons = array_diff($addons, array_keys($this->addons));
         }
         $this->addons($this->addonsum, $addons, $Product->prices);
     }
     if (isset($Price->id)) {
         $this->option = $this->mapprice($Price);
     }
     $this->sku = $Price->sku;
     $this->type = $Price->type;
     $this->sale = Shopp::str_true($Product->sale);
     $this->freeshipping = isset($Price->freeshipping) ? $Price->freeshipping : false;
     $baseprice = roundprice($this->sale ? $Price->promoprice : $Price->price);
     $this->unitprice = $baseprice + $this->addonsum;
     if (shopp_setting_enabled('taxes')) {
         if (Shopp::str_true($Price->tax)) {
             $this->taxable[] = $baseprice;
         }
         $this->istaxed = array_sum($this->taxable) > 0;
         $this->includetax = shopp_setting_enabled('tax_inclusive');
         if (isset($Product->excludetax) && Shopp::str_true($Product->excludetax)) {
             $this->includetax = false;
         }
     }
     if ('Donation' == $this->type) {
         $this->donation = $Price->donation;
     }
     $this->inventory = Shopp::str_true($Price->inventory) && shopp_setting_enabled('inventory');
     $this->data = stripslashes_deep(esc_attrs($data));
     // Handle Recurrences
     if ($this->has_recurring()) {
         $this->subprice = $this->unitprice;
         $this->recurrences();
         if ($this->is_recurring() && $this->has_trial()) {
             $trial = $this->trial();
             $this->unitprice = $trial['price'];
         }
     }
     // Map out the selected menu name and option
     if (Shopp::str_true($Product->variants)) {
         $selected = explode(',', $this->option->options);
         $s = 0;
         $variants = isset($Product->options['v']) ? $Product->options['v'] : $Product->options;
         foreach ((array) $variants as $i => $menu) {
             foreach ((array) $menu['options'] as $option) {
                 if ($option['id'] == $selected[$s]) {
                     $this->variant[$menu['name']] = $option['name'];
                     break;
                 }
             }
             $s++;
         }
     }
     $this->packaging = Shopp::str_true(shopp_product_meta($Product->id, 'packaging'));
     if (!empty($Price->download)) {
         $this->download = $Price->download;
     }
     $this->shipped = 'Shipped' == $Price->type;
     if ($this->shipped) {
         $dimensions = array('weight' => 0, 'length' => 0, 'width' => 0, 'height' => 0);
         if (Shopp::str_true($Price->shipping)) {
             $this->shipfee = $Price->shipfee;
             if (isset($Price->dimensions)) {
                 $dimensions = array_merge($dimensions, $Price->dimensions);
             }
         } else {
             $this->freeshipping = true;
         }
         if (isset($Product->addons) && Shopp::str_true($Product->addons)) {
             $this->addons($dimensions, $addons, $Product->prices, 'dimensions');
             $this->addons($this->shipfee, $addons, $Product->prices, 'shipfee');
         }
         foreach ($dimensions as $dimension => $value) {
             $this->{$dimension} = $value;
         }
         if (isset($Product->processing) && Shopp::str_true($Product->processing)) {
             if (isset($Product->minprocess)) {
                 $this->processing['min'] = $Product->minprocess;
             }
             if (isset($Product->maxprocess)) {
                 $this->processing['max'] = $Product->maxprocess;
             }
         }
     }
 }