This is the API docs for LemonStand V1, which has been discontinued. LemonStand is now a cloud based platform, available at lemonstand.com.

LemonStand API

Shop_Cart class

Defined in /modules/shop/classes/shop_cart.php, lines 18-1438
Author LemonStand eCommerce Inc.
Represents a visitor's shopping cart. The class has static methods for accessing the cart contents and evaluating the total price, dimensions and weight of the cart items. Please read the Creating the Cart page article for examples of the class usage.
All methods of this class accept the $cart_name parameter, which default value is main. You can implement multiple shopping carts with LemonStand. You can post the cart_name parameter to the shop:on_addToCart handler in order to place an item into a specific cart. By default LemonStand always work with the shopping cart named main.

Public methods

Method Description Defined By
add_cart_item() adds an item to the cart. Shop_Cart
add_item() adds an item to the cart. Shop_Cart
find_by_product_sku() finds active cart items by the product SKU. Shop_Cart
find_item() finds a cart item by its key. Shop_Cart
get_content_id() returns the unique cart content identifier. Shop_Cart
get_item_total_num() returns a total number of all active items in the shopping cart. Shop_Cart
list_active_items() returns a list of active (not postponed) cart items. Shop_Cart
list_postponed_items() returns a list of postponed cart items. Shop_Cart
remove_active_items() removes all active items from the cart. Shop_Cart
remove_item() returns an item from the cart. Shop_Cart
set_quantity() sets cart item quantity. Shop_Cart
total_depth() returns the total depth of active cart items. Shop_Cart
total_height() returns the total height of active cart items. Shop_Cart
total_price() returns total price of all items in the cart. Shop_Cart
total_price_no_tax() returns total price of all items in the cart without any taxes applied. Shop_Cart
total_tax() returns total tax amount applied to the cart items. Shop_Cart
total_volume() returns a total volume of active cart items. Shop_Cart
total_weight() returns a total weight of all active items in the cart. Shop_Cart
total_width() returns the total width of active cart items. Shop_Cart

Events

Event Description
shop:onAfterAddToCart Triggered after a product has been added to the cart.
shop:onAfterRemoveFromCart Triggered after an item is removed from the shopping cart.
shop:onAfterSetCartQuantity Triggered after a product quantity in the cart has been changed.
shop:onBeforeAddToCart Triggered before a product is added to the cart.
shop:onBeforeRemoveFromCart Triggered before an item is removed from the shopping cart.
shop:onBeforeSetCartQuantity Triggered before a product quantity in the cart is changed.
shop:onPreProcessProductCustomData The event allows you to modify custom (API) product parameters before product is added to the cart.

Method details

add_cart_item() method

public static Shop_CartItem add_cart_item(Shop_Product $product, array $parameters)
$product Shop_Product specifies the product to add.
$parameters array specifies the operation parameters.
{return} Shop_CartItem returns the added cart item object.
Adds an item to the cart. Use this method to add new cart items programmatically. Pass an array of parameters to the second parameter. The array can contain the following elements:
  • quantity - number of items to add, by default 1.
  • cart_name - the cart name, by default main.
  • extra_options - an array of product extra options in the following format: [option_key_1, option_key_2].
  • options - an array of product options in the following format: [option_key=>option_value].
  • custom_data - an array of custom API field names and values.
  • bundle_data - an array containing bundle product data.
  • uploaded_files - a collection of files to assign with the item.

add_item() method

public static Shop_CartItem add_item(Shop_Product $product, array $options, array $extra_options, integer $quantity, string $cart_name='main', array $custom_data=array())

This method is deprecated. Use add_cart_item() method.

$product Shop_Product specifies the product to add.
$options array specifies a list of product options.
$extra_options array specifies a list of product extra options.
$quantity integer specifies the item quantity.
$cart_name string specifies the cart name.
$custom_data array contains item custom fields data.
{return} Shop_CartItem returns the added cart item object.
Adds an item to the cart.

find_by_product_sku() method

public static array find_by_product_sku(string $sku, string $cart_name='main')
$sku string specifies the product SKU.
$cart_name string specifies the cart name,
{return} array returns an array of Shop_CartItem objects.
Finds active cart items by the product SKU.

find_item() method

public static Shop_CartItem find_item(string $key, string $cart_name='main', boolean $auto_remove_items=true)
$key string specifies the item key.
$cart_name string specifies the cart name.
$auto_remove_items boolean determines whether cart items corresponding to disabled products should be removed from the cart automatically.
{return} Shop_CartItem returns the cart item object. Returns NULL if the item cannot be found.
Finds a cart item by its key.

get_content_id() method

public static string get_content_id(string $cart_name='main')
$cart_name string specifies the cart name.
{return} string returns the content identifier.
Returns the unique cart content identifier. The content identifier changes each time when a customer changes the cart content.

get_item_total_num() method

public static integer get_item_total_num(string $cart_name='main', boolean $count_bundle_items=true)
$cart_name string specifies the cart name.
$count_bundle_items boolean determines whether bundle item counts should be added to the result.
{return} integer returns the total item number.
Returns a total number of all active items in the shopping cart.

list_active_items() method

public static array list_active_items(string $cart_name='main')
$cart_name string specifies the cart name.
{return} array returns an array of Shop_CartItem objects.
Returns a list of active (not postponed) cart items.

list_postponed_items() method

public static array list_postponed_items(string $cart_name='main')
$cart_name string specifies the cart name.
{return} array returns an array of Shop_CartItem objects.
Returns a list of postponed cart items.

remove_active_items() method

public static void remove_active_items(string $cart_name='main')
$cart_name string specifies the cart name.
Removes all active items from the cart.

remove_item() method

public static void remove_item(string $key, string $cart_name='main')
$key string specifies the item key.
$cart_name string specifies the cart name.
Returns an item from the cart.

set_quantity() method

public static void set_quantity(string $key, integer $value, string $cart_name='main')
$key string specifies the cart item key.
$value integer specifies the cart item quantity.
$cart_name string specifies the cart name.
Sets cart item quantity.

total_depth() method

public static float total_depth(string $cart_name='main')
$cart_name string specifies the cart bane.
{return} float returns the total depth value.
Returns the total depth of active cart items.

total_height() method

public static float total_height(string $cart_name='main')
$cart_name string specifies the cart bane.
{return} float returns the total height value.
Returns the total height of active cart items.

total_price() method

public static float total_price(string $cart_name='main', boolean $apply_cart_discounts=true, array $items=NULL, boolean $force_tax=false)
$cart_name string specifies the cart name.
$apply_cart_discounts boolean determines whether discounts should be applied to the result.
$items array an optional array to cart items. If the array is provided its elements will be used instead of the items contained by the cart.
$force_tax boolean determines whether the tax should be applied regardless of whether front-end taxes are enabled.
{return} float returns the total price.
Returns total price of all items in the cart. Adds tax to the result if the Display catalog/cart prices including tax feature is enabled. Pass FALSE value to the second parameter in order to get the cart total before discounts applied.

total_price_no_tax() method

public static float total_price_no_tax(string $cart_name='main', boolean $apply_cart_discounts=true, array $items=NULL)
$cart_name string specifies the cart name.
$apply_cart_discounts boolean determines whether discounts should be applied to the result.
$items array an optional array to cart items. If the array is provided its elements will be used instead of the items contained by the cart.
{return} float returns the total price without tax.
Returns total price of all items in the cart without any taxes applied. This method is identical to total_price() method, but it never adds tax to the result regardless of whether the Display catalog/cart prices including tax feature is enabled.

total_tax() method

public static float total_tax(string $cart_name, array $items=NULL)
$cart_name string specifies the cart name.
$items array an optional array to cart items. If the array is provided its elements will be used instead of the items contained by the cart.
{return} float returns the total tax amount.
Returns total tax amount applied to the cart items.

total_volume() method

public static float total_volume(string $cart_name='main')
$cart_name string specifies the cart name.
{return} float returns the total volume.
Returns a total volume of active cart items.

total_weight() method

public static float total_weight(string $cart_name='main')
$cart_name string specifies the cart name.
{return} float returns the total weight.
Returns a total weight of all active items in the cart.

total_width() method

public static float total_width(string $cart_name='main')
$cart_name string specifies the cart bane.
{return} float returns the total width value.
Returns the total width of active cart items.