LemonStand Documentation

Shop_CartItem

The Shop_CartItem class represents an item in a customer shopping cart. Normally you will not need to create objects of this class. To access the shopping cart items use the Shop_Cart class. Please read the Creating the Cart page article for examples of the class usage.

Class fields

  • $key – a unique identifier of the item in the shopping cart
  • $product – a reference to the Shop_Product class object, corresponding the cart item
  • $options – an array of selected product options. Each element of the array is another array with keys corresponding the option name and values corresponding the option value: array('Color'=>'Blue')
  • $extra_options – an array of extra paid options, selected by a customer. Each element in the array is a PHP object with two fields: $price and $description.
  • $quantity – a quantity of products in the shopping cart item
  • $postponed – boolean value, indicating whether the item is postponed
  • $order_item - reference to the Shop_OrderItem object. When processing existing orders, LemonStand can automatically convert order items to cart items. In this case the reference to the original order item is stored in the $order_item field of the cart item object.

Class methods

  • total_discount() - returns the cart item discount, based on the discount rules defined on the Shop/Discounts page.
  • options_str() – returns a string, containing product options. Format: Color: white, Size: M. Use this method to simplify the code for displaying the shopping cart content.
  • single_price() - evaluates a single price of the cart item, taking into account extra paid options. The discount value is not subtracted from the single price.
  • total_depth() - returns a total depth of the cart item
  • total_width() - returns a total width of the cart item
  • total_height() - returns a total height of the cart item
  • total_volume() - returns a total volume of the cart item
  • total_weight() - returns a total weight of the cart item
  • total_price() - returns a total price of the cart item, taking into account the item quantity, extra options and a discount value.
  • get_tax_rates() - returns a list of taxes applied to the cart item. Returns an array, containing objects with the following fields: name, rate. You can use this method to output a list of applied taxes in the cart item table. Example:
    <? foreach ($item->get_tax_rates() as $tax_info): ?>
      <?= h($tax_info->name) ?>
    <? endforeach ?>
    
  • get_data_field($field_name) - extracts a custom data field value by the field name. You can use this field for displaying custom data fields previously assigned to the cart items. Controls for custom data fields should have names in the following format: item_data[<?= $item->key ?>][field_name]. You can learn about creating custom per-item input fields on the Cart page in this article. Example:
    <textarea 
      name="item_data[<?= $item->key ?>][x_engraving_text]"><?= h($item->get_data_field('x_engraving_text')) ?></textarea>
  • list_uploaded_files() - returns a list of files uploaded by the customer on the Product Details page. You can use this method to display files assigned to each item on the Cart page. The method returns an array of arrays with the following keys: name, size, path.
  • bundle_single_price() - returns total price (sum if all bundle items) of a single unit of the bundle product cart item. If the cart item does not represent a bundle product, the method returns the single_price() method result.
  • get_bundle_items() - returns cart items which represent bundle items for this cart item. Returns an array of Shop_CartItem objects.
  • get_quantity() - returns cart item quantity for displaying on pages. For regular items returns the total quantity of the item in the cart. For bundle items returns the quantity of the item in the parent bundle.
  • bundle_total_price() - returns total bundle price. The price includes the price of the base bundle products and all its bundle items. If the cart item does not represent a bundle product, the method returns the total_price() method result.
  • bundle_item_total_price() - returns total price of a bundle item cart item (total price of the bundle item in a single base product). If the cart item does not represent a bundle item product, the method returns the total_price() method result.
  • bundle_total_discount() - returns total discount of a single item of the bundle product cart item. If the cart item does not represent a bundle product, the method returns the total_discount() method result.
  • is_bundle_item() - returns TRUE if this cart item represents a bundle item.
  • get_bundle_item() - returns a bundle item object (Shop_ProductBundleItem) this cart item refers to. If this cart item does not represent a bundle item product, returns null.
  • get_bundle_item_product() - returns a bundle item product object (Shop_BundleItemProduct) this cart item refers to. If this cart item does not represent a bundle item product, returns null.
  • get_master_bundle_item() - returns a cart item object (Shop_CartItem) representing a master bundle product for this item. The result value could be null in case if the item is not a bundle item or if the master cart item cannot be found.

Next: Shop_Category
Previous: Shop_Cart
Return to Reference