Chapter 5: Building a Shopping Cart
108
You ’ re going to combine the two approaches. Your more sensitive data are going to go into PHP sessions.
Other data, like a flag that indicates whether there are any items in the Shopping Cart, will go into the
CodeIgniter session.
Before going any further, it ’ s a good idea to review what the expectations are concerning the
Shopping Cart.
The first thing to notice when reviewing the diagrams is that you need to change the “ buy now ” links
in your views to “ add to cart. ” If you recall, early in the diagramming process, Claudia asked you
to change the potentially confusing “ buy now ” links with a more accurate “ add to cart ”. Making this
change is easy enough, implemented with a simple search and replace in any text editor.
The second thing is that the process of adding a product to a shopping cart doesn ’ t really involve a view.
Instead, it can simply use a status message to provide the user with visual confirmation, as pictured in
Figure 5 - 1.
Figure 5 - 1
This status message can be achieved with very little effort in the controller cart() function.
Finally, the third thing to consider (and this is also illustrated in Figure 5 - 1 ) is that once a user has added
items to her cart, a third navigation option (called “ view cart ” ) is dynamically added to the main
navigation. When the user clicks this link, she can view and manipulate items in her Shopping Cart, as
illustrated in Figure 5 - 2.