Class: Cart
Properties
$items = array ()
The list of items in the cart. Keys are the sku's, values are
Item objects.
$tax = 1.0
The tax is a number that the prices are simply multiplied by,
so to assign 15% tax, you would set $tax to 1.15
$price_column = 'price'
In order to calculate subtotals and totals, Cart needs to know
which property of Item contains the prices of the items. This defaults
to 'price'.
$customer_id = ''
To identify a customer, we assign them a $customer_id. This
can be generated randomly, set to be some other identifying value,
such as the $session object's id property, or whatever you want.
$view_tpl = '<a href="{link}">View Cart</a>'
If you call the view_button () method, it uses this template
to generate a 'View Cart' link.
$checkout_tpl = '<a href="{link}">Check Out</a>'
If you call the checkout_button () method, it uses this
template to generate a 'Check Out' link.
$link = '/index'
This property is necessary in order to create a proper
'View Cart' or 'Check Out' link with the view_button () and
checkout_button () methods.
Return to Top
Methods
Cart ($customer_id = '')
Constructor method.
total_items ($tpl)
Returns the number of items in the cart.
subtotal ($tpl)
Adds up all of the prices of the items, not including taxes.
add_tax ($tpl)
Returns the total of the prices, plus taxes.
view_button ($tpl)
Generates a 'View Cart' button. Requires a global
$simple SimpleTemplate object.
checkout_button ($tpl)
Generates a 'Check Out' button.
&add_item ($sku, $item)
- Access: public
- Return: object
Adds an item to the cart.
store ()
Empty method - to be defined when subclassed. Store the cart
somewhere for another script to retrive it.
retrieve ()
Empty method - to be defined when subclassed. Retrive the cart
from wherever it was stored before.
checkout ()
Empty method - to be defined when subclassed. Check the person
out, we have led them to buy.
save ()
Empty method - to be defined when subclassed. Save the cart for
later, without purchasing anything. Sort of a 'save as wishlist' option.
valid ()
Empty method - to be defined when subclassed. Check if the
information (contact, credit cart, whatever) provided is valid.
error ()
Empty method - to be defined when subclassed. Report
something gone wrong.
Return to Top