|
Shop_CartItem class
Represents an item in the shopping cart.
Normally you don't 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.
See AlsoPublic properties
Public methods
Events
Property details¶ cart_name propertypublic string $cart_name;
Specifies a name of the cart the item belongs to.
¶ extra_options propertypublic array $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.
¶ key propertypublic string $key;
Specifies the item key.
Item keys are used for identifying items in the cart.
¶ options propertypublic array $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')
¶ order_item propertypublic Shop_OrderItem $order_item;
Specifies a reference to the original order item object.
This property is not empty in case if the cart item was created by converting an order item to the cart item.
¶ postponed propertypublic boolean $postponed;
Determines whether the cart item is postponed.
¶ product propertypublic Shop_Product $product;
A product object corresponding to the cart item.
¶ quantity propertypublic integer $quantity;
Specifies the product quantity.
Method details¶ bundle_item_total_price() methodpublic Returns 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_single_price() methodpublic float 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.
¶ bundle_total_discount() methodpublic float 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.
¶ bundle_total_price() methodpublic float 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.
¶ get_bundle_item() methodpublic Shop_ProductBundleItem get_bundle_item()
Returns a bundle item object this cart item refers to.
If this cart item does not represent a bundle item product, returns NULL.
¶ get_bundle_items() methodpublic Returns get_bundle_items()
Returns cart items which represent bundle items for this cart item.
¶ get_bundle_item_product() methodpublic Shop_BundleItemProduct get_bundle_item_product()
Returns a bundle item product object this cart item refers to.
If this item does not represent a bundle item product, returns NULL.
¶ get_data_field() methodpublic Returns get_data_field(string $field_name, mixed $default=NULL)
Extracts a custom data field value by the field name.
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 read 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> ¶ get_data_fields() methodpublic array get_data_fields()
Returns all custom data field values assigned with the cart item.
¶ get_master_bundle_item() methodpublic Shop_CartItem get_master_bundle_item()
Returns a cart item object 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.
¶ get_quantity() methodpublic Returns get_quantity()
Returns 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. For example, if there was a computer bundle product in the cart and its
quantity was 2 and it had a bundle item CPU with quantity 2, the actual quantity
for CPU would be 4, while the visible quantity, returned by this method, would be 2.
¶ get_tax_rates() methodpublic array get_tax_rates()
Returns a list of taxes applied to the cart item.
The method 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 ?> ¶ is_bundle_item() methodpublic boolean is_bundle_item()
Returns TRUE if the cart item represents a bundle item.
¶ item_description() methodpublic Returns item_description(string $options_delimiter='; ', boolean $lowercase_options=true, boolean $as_html=true)
Returns the item options and extra options description.
This method simplifies front-end coding.
¶ list_uploaded_files() methodpublic array list_uploaded_files()
Returns a list of files uploaded by the customer on the Product Details page.
Use this method to display files assigned with items on the Cart page.
The method returns an array of arrays with the following keys: name, size, path.
¶ om() methodpublic mixed om(string $property_name)
Returns Option Matrix product property.
If Option Matrix product is not associated with the cart item, returns property value of
the base product. Specify the property name in the first parameter. Use the method on the Cart page to output
Option Matrix specific parameters, for example product images. The following example outputs a product
image in the cart item list.
<? $images = $item->om('images'); $image_url = $images->count ? $images->first->getThumbnailPath(60, 'auto') : null; ?> <? if ($image_url): ?> <img class="product_image" src="<?= $image_url ?>" alt="<?= h($item->product->name) ?>"/> <? endif ?> ¶ options_str() methodpublic string options_str(string $delimiter='; ', boolean $lowercase_values=false)
Returns a string, describing selected product options.
The returned string has the following format: Color: white; Size: M.
Use this method to simplify the code for displaying the shopping cart content.
¶ single_price() methodpublic float single_price(boolean $include_extras=true)
Returns price of a single unit of the cart item, taking into account extra paid options.
The discount value is not subtracted from the single price.
Behavior of this method can be altered by shop:onGetCartItemPrice and shop:onUpdateCartItemPrice event handlers.
¶ total_depth() methodpublic float total_depth()
Returns the total depth of the cart item.
The total depth is unit depth * quantity.
¶ total_discount() methodpublic float total_discount()
Returns the cart item discount.
¶ total_height() methodpublic float total_height()
Returns the total width of the cart item.
The total height is unit height * quantity.
¶ total_price() methodpublic float total_price(boolean $apply_catalog_price_rules=true, boolean $force_tax=false, integer $quantity=NULL)
Returns total price of the item.
The method takes into account the item quantity, extra options and discounts value.
Adds tax to the result if the
Display catalog/cart prices including tax
option is enabled or $force_tax parameter is TRUE.
¶ total_volume() methodpublic float total_volume()
Returns the total volume of the cart item.
The total depth is unit volume * quantity.
¶ total_weight() methodpublic float total_weight()
Returns the total weight of the cart item.
The total depth is unit weight * quantity.
¶ total_width() methodpublic float total_width()
Returns the total width of the cart item.
The total depth is unit depth * quantity.
|