Create the Cart and Cart_Item classes. The Cart class must contain methods for adding and removing Cart_Items, which are stored in an array in the Cart class. Also create a save method that serializes the state of the basket in the session, I also like to serialize the basket to the database table using the standard Zend_Db_Table_Abstract model.
I create controller actions that take the identifier and quantity of the product and pass them to the Cart class add / remove methods, after which the carts are saved.
I find it useful to implement a singleton pattern for this type of system, especially if Cart is updating itself from the design database.
As Alex said, helpers are useful, I like to use the view assistant, which will retrieve the current instance of the basket and allow you to easily pull out subtotals and a summary ect. in view.
In addition, condsider uses the Iterator, Countable, and ArrayAccess interfaces so you can navigate your cart to get all of your items.
Hope this helps!
source share