Пример #1
0
/**
 * @deprecated Use Shopp::roundprice()
 **/
function roundprice($amount, $format = array())
{
    return Shopp::roundprice($amount, $format);
}
Пример #2
0
 /**
  * Provides product varient input markup or properties for the current variant in the variants loop
  *
  * Used with `shopp('product.variants')` looping.
  *
  * @api `shopp('product.variant')`
  * @since 1.1
  *
  * @param string       $result  The output
  * @param array        $options The options
  * - **discounts**: `on` (on,off) When used with the **saleprice** property, shows the discounted price of the variant
  * - **input**: `null` (text,checkbox,radio,hidden) Sets the type of input to create
  * - **money**: `on` (on, off) Format the amount in the current currency format
  * - **number**: `off` (on, off) Provide the unformatted number (floating point)
  * - **separator**: ` ` The separator to use between properties when requesting multiple properties
  * - **taxes**: `null` (on,off) Include or exclude taxes from prices
  * - **units**: `on` (on,off) Include the weight unit when weight is requested as a property
  * @param ShoppProduct $O       The working object
  * @return string The variant input markup or property value
  **/
 public static function variant($result, $options, $O)
 {
     $defaults = array('discounts' => 'on', 'money' => 'on', 'number' => 'off', 'separator' => ' ', 'taxes' => null, 'units' => 'on');
     $options = array_merge($defaults, $options);
     extract($options, EXTR_SKIP);
     if (isset($promos)) {
         $discounts = $promos;
     }
     // support for deprecated `promos` option
     $weightunit = Shopp::str_true($units) ? shopp_setting('weight_unit') : '';
     $variation = current($O->prices);
     $taxes = isset($taxes) ? Shopp::str_true($taxes) : null;
     $_ = array();
     if (array_key_exists('id', $options)) {
         $_[] = $variation->id;
     }
     if (array_key_exists('label', $options)) {
         $_[] = $variation->label;
     }
     if (array_key_exists('type', $options)) {
         $_[] = $variation->type;
     }
     if (array_key_exists('sku', $options)) {
         $_[] = $variation->sku;
     }
     if (array_key_exists('stock', $options)) {
         $_[] = $variation->stock;
     }
     if (array_key_exists('price', $options)) {
         $price = Shopp::roundprice(self::_taxed((double) $variation->price, $O, $variation->tax, $taxes));
         if (Shopp::str_true($money)) {
             $_[] = money($price);
         } else {
             $_[] = $price;
         }
     }
     if (array_key_exists('saleprice', $options)) {
         $saleprice = Shopp::str_true($discounts) ? $variation->promoprice : $variation->saleprice;
         $saleprice = Shopp::roundprice(self::_taxed((double) $saleprice, $O, $variation->tax, $taxes));
         if (Shopp::str_true($money)) {
             $_[] = money($saleprice);
         } else {
             $_[] = $saleprice;
         }
     }
     if (array_key_exists('weight', $options)) {
         $_[] = round($variation->weight, 3) . ($weightunit ? " {$weightunit}" : false);
     }
     if (array_key_exists('shipfee', $options)) {
         $shipfee = Shopp::roundprice($variation->shipfee);
         if (Shopp::str_true($money)) {
             $_[] = money($shipfee);
         } else {
             $_[] = $shipfee;
         }
     }
     if (array_key_exists('sale', $options)) {
         return Shopp::str_true($variation->sale);
     }
     if (array_key_exists('shipping', $options)) {
         return Shopp::str_true($variation->shipping);
     }
     if (array_key_exists('tax', $options)) {
         return Shopp::str_true($variation->tax);
     }
     if (array_key_exists('inventory', $options)) {
         return Shopp::str_true($variation->inventory);
     }
     return join($separator, $_);
 }
Пример #3
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 ShoppPurchase $O         The working object
  * @return ShoppPurchase The active ShoppPurchase context
  **/
 public static function _money($result, $options, $property, $O)
 {
     // Passthru for non-monetary results
     $monetary = array('freight', 'subtotal', 'discount', 'shipping', 'itemaddon', 'itemtotal', 'itemunitprice', 'tax', 'total');
     if (!in_array($property, $monetary) || !is_numeric($result)) {
         return $result;
     }
     // Special case for purchase.item-addon `unitprice` option
     if ('itemaddon' == $property && !in_array('uniprice', $options)) {
         return $result;
     }
     // @deprecated currency parameter
     if (isset($options['currency'])) {
         $options['money'] = $options['currency'];
     }
     $defaults = array('money' => 'on', 'number' => false);
     $options = array_merge($defaults, $options);
     extract($options);
     if (Shopp::str_true($number)) {
         return $result;
     }
     if (Shopp::str_true($money)) {
         $result = Shopp::money(Shopp::roundprice($result));
     }
     return $result;
 }