Example #1
0
 public function __construct(ShoppCartItem $Item)
 {
     $this->amount =& $Item->quantity;
     $this->id = $Item->fingerprint();
 }
Example #2
0
 /**
  * Add new item taxes to the tax register
  *
  * @author Jonathan Davis
  * @since 1.3
  *
  * @param ShoppCartItem $Item The cart item from shopp_cart_item_retotal
  * @return void
  **/
 public function itemtaxes(ShoppCartItem $Item)
 {
     $itemid = $Item->fingerprint();
     if (!$this->exists($itemid)) {
         return;
     }
     foreach ($Item->taxes as $id => &$ItemTax) {
         $this->Totals->register(new OrderAmountItemTax($ItemTax, $itemid));
     }
 }
Example #3
0
 /**
  * Displays the currently selected product variation for the item or a drop-down menu to change the selection
  *
  * @api `shopp('cartitem.options')`
  * @since 1.1
  *
  * @param string        $result  The output
  * @param array         $options The options
  * - **before**: ` ` Markup to add before the options
  * - **after**: ` ` Markup to add after the options
  * - **show**: (selected) Set to `selected` to provide the currently selected option label @see `shopp('cartitem.option-label')`
  * - **class**: The class attribute specifies one or more class-names for the menu element
  * @param ShoppCartItem $O       The working object
  * @return string The options markup
  **/
 public static function options($result, $options, $O)
 {
     $class = "";
     if (!isset($options['before'])) {
         $options['before'] = '';
     }
     if (!isset($options['after'])) {
         $options['after'] = '';
     }
     if (isset($options['show']) && strtolower($options['show']) == "selected") {
         return !empty($O->option->label) ? $options['before'] . $O->option->label . $options['after'] : '';
     }
     if (isset($options['class'])) {
         $class = ' class="' . $options['class'] . '" ';
     }
     if (count($O->variants) > 1) {
         $result .= $options['before'];
         $result .= '<input type="hidden" name="items[' . $O->_id . '][product]" value="' . $O->product . '"/>';
         $result .= ' <select name="items[' . $O->_id . '][price]" id="items-' . $O->_id . '-price"' . $class . '>';
         $result .= $O->options($O->priceline);
         $result .= '</select>';
         $result .= $options['after'];
     }
     return $result;
 }
Example #4
0
 /**
  * Adds an item discount amount entry to the applied item discounts list
  *
  * @author Jonathan Davis
  * @since 1.3
  *
  * @param ShoppCartItem $Item The item object to calculate a discount from
  * @return float The item discount amount
  **/
 public function item(ShoppCartItem $Item)
 {
     // These must result in the discount applied to the *unit price*!
     switch ($this->type) {
         case self::PERCENT_OFF:
             $amount = $Item->unitprice * ($this->discount() / 100);
             break;
         case self::AMOUNT_OFF:
             $amount = $this->discount();
             break;
         case self::SHIP_FREE:
             $Item->freeshipping = true;
             $this->shipping = true;
             $amount = 0;
             break;
         case self::BOGOF:
             list($buy, $get) = $this->discount();
             // The total quantity per discount
             $buying = $buy + $get;
             // The number of times the discount will apply
             $amount = $Item->quantity / $buying;
             // Keep the BOGOF factor floored when quantity over buying has remainders
             if ($Item->quantity % $buying) {
                 $amount = (int) floor($amount);
             }
             break;
     }
     $this->items[$Item->fingerprint()] = (double) $amount;
     return $amount;
 }