Jason Beebe wrote:
> 
> Hey,
> 
> I'm looking for little information from those who have coded their own shopping cart 
>apps. what would you say the best way to setup a cart would be? more specificly, the 
>method for adding items to the cart.
> 
> say the user is broswing around. when they entered the website a new session was 
>created. when they go to add an item, what is the best way store variables (such as 
>what they bought and quantity) in the session. i have read that it is possible to put 
>all of your session variables in a single associative array. however, i have not had 
>any luck doing this myself. Under such a method of an array, how would i store each 
>item (product id and quantity, possibly price as well) in the cart into the session. 
>obviously i don't expect anyone to write an entire app. i am comfortable starting the 
>session, and doing th db extraction and presentation. i just need to know how to 
>store a variable in a session (passed through post) and how to extract it when need 
>be (considering it is an array). Thanks a lot!

A session cookie can be of max 4096 bytes, so there is a limit to what
you can set. Also it is (I'm not sure if this is part of the cookie
standard) a general standard that only the supplier sites name and the
user's ID should be stored, nothing else.

Instead you can use the session id as the id of tables used for storing
info:

session_id
key
value

Then you could store key value pairs in say a database. The above
example is, btw, a misuse of relational databases, and should not be
taken as the way of doing things.

You should use a databaase in the background and store info in tables, a
structure might be something like:

customer_history
-----------
session_id
cart_id

cart
-----
id
total
date

cart_item
-------
cart_id
item_id
quantity
price_pr_unit

item
-------
id
name

In this structure you can give each customer a number of carts (ie,
previous orders), you can let each cart have several items, you will
know the quantity of each item, and the item price for this (allowing
for prices which are variable with price/discounts).

You should also consider that you don't want people to register until
checkout (just to mention this), if they aren't registered customers
from before.

If you want to read more about this, take a look at
http://developer.ez.no where you can learn about eZ trade which has
implemented such a shopping cart system. You'll find code, examples,
design documents, administration documents and discussions covering this
software. The software is free under the GNU GPL.

-- 
Paul K Egell-Johnsen
Developer/PR Manager
eZ systems as
http://ez.no/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to