Page 1 of 1
Shopping Cart Setup
Posted: Mon Mar 10, 2008 11:30 am
by kendall
Hi,
I have built my own custom shopping cart using PHP OOP. How i built it is by using a basic class and using an extended class to handle and manage whatever functions "specifically" needed for the particular application needs.
No i have come across a dilemma (well it is a question that was posed)...currently when adding "products" to the cart i basically pass an id and have my extended class customized to query a database table to retrieve the relative information (name, product, price...etc) for the item to be put into shopping cart. I am now faced with a scenario which involves one off times that may not be in the database and more possibly not necessary to be stored in the database (its only going to be used one time and one time only). So im faced with the following scenarios
1) modify my extended class to query the respective database tables to retrieve the information needed to be put into the cart
2) eliminate the process of querying the database tables and have the information relevant information beforehand to be put into the cart
Is it the norm to have your shopping cart application query a database to retrieve the information needed or should it be done before passing it on to shopping cart?
Re: Shopping Cart Setup
Posted: Mon Mar 10, 2008 1:51 pm
by alex.barylski
Can I ask for the sake of curiosity: Why do you all of a sudden have this requirement to add "one off" items to your shopping cart???
What exactly are you adding now? If they are temporary, why not store product ID's in cookies or sessions and lookup the actual product table? I think I'm mis-understanding your dilema.

Re: Shopping Cart Setup
Posted: Mon Mar 10, 2008 2:09 pm
by kendall
Can I ask for the sake of curiosity: Why do you all of a sudden have this requirement to add "one off" items to your shopping cart???
because the item/ service in question has parameters (price, name, description) that are based on the user information. after which the parameters (price) cant be used again or may differ at another point in time(if ever). There is no standard values for this item.
What exactly are you adding now? If they are temporary, why not store product ID's in cookies or sessions and lookup the actual product table? I think I'm mis-understanding your dilema.
Well this is what i am doing now. but what i realize is that the item cant really be re-used after it is added to the table and that new items will be added each time for each custom item which is usually based on user information after the fact.
so i'm not really aware of the price, or the name or the description until the user enters the information...
hope this helps...i'm thinking passing the values rather than retrieving the information from a database is not such a good idea?
Re: Shopping Cart Setup
Posted: Mon Mar 10, 2008 2:17 pm
by alex.barylski
So you have a products database, which hold known or existing products and you need some secondary table to hold unknown or user entered items?
Why not use the same table with a 'type' attribute to distinguish between your items and your user items?
Re: Shopping Cart Setup
Posted: Mon Mar 10, 2008 4:56 pm
by kendall
Hockey wrote:So you have a products database, which hold known or existing products and you need some secondary table to hold unknown or user entered items? Why not use the same table with a 'type' attribute to distinguish between your items and your user items?
Well firstly i have done that but this is a new "product item" whose price varies on user input (there is no "standard" value) so i'm like what do i put?....i mean to say....
a product would have title, price of 12.00 and a description
this particular item is a service...it has a title yes...but the price cud be 12.00 or it cud be 3.99 and the description for it is....i dont know
this particular item is based on the customer...so meaning another customer is not going to come and purchase this item...the other customer is going to create this product which has its own title....its price can be 9.99 and well i dont know what its description...
so now i would have 2 product items in my table that aren't going to be "restocked" or instock after it is bought....
in other words people...the application is going to be used to charge the customer for a product it doesn't know the price for until the customer inputs that information. since this is the case i was wondering if it would be feasible to just send this information on the fly to be insert into the cart (not a table). Problem is my shopping cart class assumes that every item passed to it has information which it would retrieve from a table which IS NOT the case in this scenario...so i am asking
should i modify the shopping cart to ...
1) switch between table and passed variables....
2) or have it received passed variables instead of looking up a database
to get the item's information to be stored in the shopping cart session...
and what is the normal procedure...is it to usually lookup product info on a passed id....or is it usually passed variables
Re: Shopping Cart Setup
Posted: Mon Mar 10, 2008 5:09 pm
by alex.barylski
I think your question is outside the scope of general application design and/or architecture. Dealing with variances in pricing, etc is pretty specific to a shopping cart. Obviously you know this, I'm just letting out hot air.
Maybe you could ask the guys over at Magento how they solved the problem and borrow ideas from them?
http://www.magentocommerce.com/
Re: Shopping Cart Setup
Posted: Mon Mar 10, 2008 7:15 pm
by kendall
[quote="Hockey"]I think your question is outside the scope of general application design and/or architecture. Dealing with variances in pricing, etc is pretty specific to a shopping cart. Obviously you know this, I'm just letting out hot air.
uhmmmm it is? why do you think that?
Re: Shopping Cart Setup
Posted: Mon Mar 10, 2008 8:03 pm
by alex.barylski
Perhaps I just misunderstood. I don't mean that your question should *not* be posted here -- just that people already experienced in commerce applications might be better able to answer your question.
in other words people...the application is going to be used to charge the customer for a product it doesn't know the price for until the customer inputs that information
I have to admit to being confused by that statement. I just don't understand the process I guess.
Your users enter the product, set the price and description, then buy it? Alternatively, you or another admin adds products which are held in "stock".
I don't see why you couldn't just throw all that stuff into a single table and use flags to indicate the type:
1) Inhouse product
2) External product
3) Service
4) Time limited
Re: Shopping Cart Setup
Posted: Tue Mar 11, 2008 10:49 am
by kendall
Hockey,
Yeah i find it a bit confusing myself...maybe i'm using the wrong terminology but its basically what you are saying. is pretty much it.
but is it the standard to have the shopping cart query the database table?
i mean right now my shopping cart application process is as follows:-
1) list items from database
2) onAdd2Cart pass id off to the shopping cart
3) shopping cart queries database/ retrieves relevant info
4) info gets registered in the shopping cart session
but due to my recent developments it probably would be better to
1) get item input from customer
2) pass id price title description to the shopping cart
3) info gets registered in the shopping cart session
now given that if the latter process is within normal shopping cart development standards maybe the following process can work for products within the database as well where by
1) list items from database
2) onAdd2Cart pass off relevant item information to shopping cat
3) info gets registered in the shopping cart session
I'm really trying to standardize my coding practices with the rest of the development community.
Re: Shopping Cart Setup
Posted: Tue Mar 11, 2008 5:40 pm
by alex.barylski
but is it the standard to have the shopping cart query the database table?
Well a shopping cart is similar to an anonymous bookmark -- so I assume that most implementations just store the product ID in a SESSION or COOKIE.
You still need to query the products table though when you wish to retreive informaiton about a particular product or service.
Re: Shopping Cart Setup
Posted: Tue Mar 11, 2008 6:48 pm
by Christopher
Whether you store the cart in the database or the session, you should probably keep the data normalized. That means not duplicating information that is elsewhere in the database and having keys in each cart item/record to the related information. The cart would therefore contain information that is not in the product data -- like the quantity the customer wants to purchase.
Re: Shopping Cart Setup
Posted: Wed Mar 12, 2008 6:22 pm
by blueyon
Check mine out:
http://www.opencart.com
I tried to make the classes as simple as possible.
Re: Shopping Cart Setup
Posted: Wed Mar 12, 2008 7:39 pm
by blueyon
arborint,
Would you put the shopping cart, tax, weight, customer, currency classes in the models folder or as an extended library?
Re: Shopping Cart Setup
Posted: Wed Mar 12, 2008 9:34 pm
by Christopher
blueyon wrote:Would you put the shopping cart, tax, weight, customer, currency classes in the models folder or as an extended library?
Not sure exactly sure I know what you mean because your list contains different sorts of things (to me). I consider the product pages, shopping cart itself and the checkout pages to be Controllers. Tax and weight are properties of an item in the Cart as well as saved in an Order, a customer is associated with the cart itself as well as an Order, and currency is probably a View setting. I generally think of the main Models in an ecommerce system as Products, Cart and Orders.
That's one way of thinking about then, but you might have meant something different. Tax is also related to Plugins/Helpers that calculate tax and implement custom rules for different locales and types of products. Currency is also related to locale. Customer is a Model itself that is also used for authentication, personalization settings, etc.