May 14, 2010 07:26 AM|chilluk|LINK
I work on a large b2c ecomm site and need to upgrade / improve the shopping cart that I have previously built as we are about to offer a whole new range of delivery services and I want to take the chance to package it all up the best way possible, and make
my life easier in the future by coding it in such a way that I can just access properties and methods of a class to determine whats going on inside each customers cart.
Current cart is bespoke, uses SQL table for storage and cookie for state management - this will not change I think as it works well and allows us to see what is going on, abandonments etc. I have a basic Cart class that handles adding / removing and updating
the cart contents. The actual cart page just uses a repeater bound to the results of a stored procedure to output the contents, and subsequent checkout pages where I need to reexamine the cart contents do similar.
What I'd like to do is beef up the cart class so that I can just call a "get" or "populate" method and then loop through the contents and show on screen - probably still in a repeater as I like to have control over the output.
Also then because the class will effectively hold the contents of the cart, and know details about each and every item I can immediately and easily detect if for example all items are currently in stock, and react accordingly. Also I could access one property
that gives me the total, or tells me if the products have a mixed availability - that sort of thing. Essentially I will flesh it out so that the class can tell me everything about the contents of someones cart in a simplistic way - sometimes at an item level,
sometimes at a summary level.
I think the bit I am not sure about is the best way to hold, and then iterate through the actual items within the cart? Should I create a cart item class and then create a collection of items within the main cart class? I've also seen some suggestions about
returning data tables etc? I've not done that within a class before. One thing that may dictate this, is that I need to be able to sort the items (most recently added first) although I do that at the database level at the moment anyway.
I want to do this properly as I have masses of work to completely overhaul cart / checkout areas of the site and want to give myself the best possible start.