Cart
in package
Shop Cart
Tags
Table of Contents
Properties
- $products : array<string|int, mixed>
- The extensive Cart information with more Product details
Methods
- add_product() : mixed
- Adds a single Product to the Cart
- checkProductStockStatus() : mixed
- Check the cart product stock status If any of the product is out of stock then return error message
- destroy() : mixed
- Destroys the Cart's contents
- from_order() : mixed
- Restores the Cart from the Order ID given
- get_discount_amount() : float
- Returns the current total discount amount of all items in the Cart
- get_item_count() : int
- Returns the current total number of items in the Cart
- get_options_array() : array<string|int, mixed>
- Returns the Options array for the given Cart and Attribute ID
- get_price() : float
- Returns the current total price of all items in the Cart
- get_product_id() : int
- Returns the Product ID for the given Cart ID
- get_products_array() : array<string|int, mixed>
- Returns the Product array
- get_quantity_by_cart_id() : int
- Returns the quantity set for the given Cart ID
- get_vat_amount() : float
- Returns the current total VAT amount of all items in the Cart
- get_weight() : int
- Returns the current total weight of all items in the Cart
- getCoupon() : Coupon
- Get currently redeemed coupon
- init() : mixed
- Initialises the Cart
- is_empty() : bool
- Returns true if there are no Products in the Cart
- needs_shipment() : bool
- Returns true if at least one item in the Cart needs shipment
- receive_json() : array<string|int, mixed>
- Receives a product sent in JSON
- receive_post() : array<string|int, mixed>
- Gets a product that has been sent through a POST request
- restored_order_id() : int
- Returns the original Order ID from which the Cart has been restored
- send_json() : mixed
- Sends the cart in JSON
- update() : bool
- Updates values in the session array with the current Cart contents, and returns an array of Product data
- update_quantity() : mixed
- Updates a Products' quantity in the Cart
- view() : mixed
- The Cart view
Properties
$products
The extensive Cart information with more Product details
private
static array<string|int, mixed>
$products
= null
Methods
add_product()
Adds a single Product to the Cart
public
static add_product(array<string|int, mixed> $arrNewProduct[, int $old_cart_id = null ]) : mixed
Parameters
- $arrNewProduct : array<string|int, mixed>
-
The array of Product data
- $old_cart_id : int = null
-
The optional Cart ID (index)
Tags
checkProductStockStatus()
Check the cart product stock status If any of the product is out of stock then return error message
public
static checkProductStockStatus() : mixed
Return values
mixed —null|string
destroy()
Destroys the Cart's contents
public
static destroy() : mixed
Calls update() after flushing the items.
from_order()
Restores the Cart from the Order ID given
public
static from_order(int $order_id[, bool $editable = false ]) : mixed
Redirects to the login when nobody is logged in. Redirects to the history overview when the Order cannot be loaded, or when it does not belong to the current Customer. When $editable is true, redirects to the detail view of the first Item for editing. Editing will be disabled otherwise.
Parameters
- $order_id : int
-
The Order ID
- $editable : bool = false
-
Items in the Cart are editable iff true
Tags
get_discount_amount()
Returns the current total discount amount of all items in the Cart
public
static get_discount_amount() : float
Take care that the Cart is update()d first, if necessary.
Return values
float —The current total discount amount
get_item_count()
Returns the current total number of items in the Cart
public
static get_item_count() : int
Take care that the Cart is update()d first, if necessary.
Return values
int —The current total number of items
get_options_array()
Returns the Options array for the given Cart and Attribute ID
public
static get_options_array(mixed $cart_id, mixed $attribute_id) : array<string|int, mixed>
If there is no such array, returns null.
Parameters
- $cart_id : mixed
- $attribute_id : mixed
Return values
array<string|int, mixed> —The options array
get_price()
Returns the current total price of all items in the Cart
public
static get_price() : float
Take care that the Cart is update()d first, if necessary. No discount is applied; subtract it when needed; see get_discount_amount().
Return values
float —The current total price
get_product_id()
Returns the Product ID for the given Cart ID
public
static get_product_id(mixed $cart_id) : int
If there is no Product for that Cart ID, returns null.
Parameters
- $cart_id : mixed
Return values
int —The Product ID, if present, or null
get_products_array()
Returns the Product array
public
static get_products_array() : array<string|int, mixed>
Do not call this before init(). Mind that that array may be empty. If present, the Product data is indexed by the cart ID. If there is no such array, returns null.
Return values
array<string|int, mixed> —The products array
get_quantity_by_cart_id()
Returns the quantity set for the given Cart ID
public
static get_quantity_by_cart_id(int $cart_id) : int
If the Cart ID is invalid, returns 0 (zero).
Parameters
- $cart_id : int
-
The Cart ID
Return values
int —The quantity
get_vat_amount()
Returns the current total VAT amount of all items in the Cart
public
static get_vat_amount() : float
Take care that the Cart is update()d first, if necessary.
Return values
float —The current total VAT amount
get_weight()
Returns the current total weight of all items in the Cart
public
static get_weight() : int
Take care that the Cart is update()d first, if necessary.
Return values
int —The current total weight
getCoupon()
Get currently redeemed coupon
public
static getCoupon() : Coupon
Return values
Coupon —The redeemed coupon or NULL
init()
Initialises the Cart
public
static init() : mixed
Doesn't change anything if it already exists. Otherwise, resets the Cart array in $_SESSION['shop']['cart']. Thank you for respecting its privacy.
Tags
is_empty()
Returns true if there are no Products in the Cart
public
static is_empty() : bool
Return values
bool —True on empty Cart, false otherwise
needs_shipment()
Returns true if at least one item in the Cart needs shipment
public
static needs_shipment() : bool
Take care that the Cart is update()d first, if necessary.
Return values
bool —True if shipment is necessary, false otherwise
receive_json()
Receives a product sent in JSON
public
static receive_json() : array<string|int, mixed>
The parameter $old_cart_id specifies the Product index in the cart.
Tags
Return values
array<string|int, mixed> —Array of the product
receive_post()
Gets a product that has been sent through a POST request
public
static receive_post() : array<string|int, mixed>
The reference parameter $old_cart_id specifies the product ID of the cart and is changed to the first key found in $_REQUEST['updateProduct'], if any.
Tags
Return values
array<string|int, mixed> —Product array of the product that has been specified by the productId field in a (POST) request.
restored_order_id()
Returns the original Order ID from which the Cart has been restored
public
static restored_order_id([int $order_id = null ]) : int
Optionally sets the given Order ID. Set to 0 (zero) in order to mark the Cart as changed (different from the original Order, apart from single item quantities)
Parameters
- $order_id : int = null
-
The optional original Order ID, or 0 (zero)
Tags
Return values
int —The original Order ID
send_json()
Sends the cart in JSON
public
static send_json() : mixed
Tags
update()
Updates values in the session array with the current Cart contents, and returns an array of Product data
public
static update(Customer $objCustomer) : bool
Called right after a Product has been added by add_product() or quantities changed by update_quantity(). Also computes the new count of items in the cart and calculates the amount. Stores details of the Products in the Cart in $products. Note that the $objCustomer parameter is mandatory, but may be empty in case it is a new Customer shopping.
Parameters
- $objCustomer : Customer
-
The Customer
Tags
Return values
bool —True on success, false otherwise
update_quantity()
Updates a Products' quantity in the Cart
public
static update_quantity() : mixed
Picks all quantities from the $_REQUEST['quantity'] array, where Products are listed by their Cart IDs, like: $_REQUEST = array( 'quantity' => array( cart_id => quantity, [... more ...] ), [... more ...] );
Tags
view()
The Cart view
public
static view([Sigma $objTemplate = null ]) : mixed
Mind that the Cart needs to be update()d before calling this method.
Parameters
- $objTemplate : Sigma = null
-
The optional Template