Shopping Cart Revision

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Swede78 wrote:Database Table 1 - "shopping_cart":
CartID | UserID (Customer Account ID or NULL) | LastUpdate (TimeStamp)

Database Table 2 - "shopping_cart_items":
CartID | ProductID | Quantity | other fields needed for extra shopping features (not planned out yet)
Database Table 3
ProductID | ProductName | ProductDescription | ...

I guess you just "implyed" that this table existed, if not, well I think it's better to put all relevent stuff together.I would also Create another table with
ProductID | Discount

because then you have so muchmore "flexibility"
When you do a discount you change it in one place (table 4) and it does the job everywhere else.

PS : this' isn't accurate if you have "categories" of product, because then you would need the field category. It might sound stupide to make bunch of table like that, but worked pretty well in the end :).
Swede78
Forum Contributor
Posts: 198
Joined: Wed Mar 12, 2003 12:52 pm
Location: IL

Post by Swede78 »

For the shopping cart, I won't use a table with the Product Name and Description. When showing the contents of the cart, I'll simply look that up in the permanent Products table. Now in the Orders Received table, I do store a product title in case it changes over time. That way I'll have a record of it as it was when they bought it. But, I figure that while shopping, they should see the most current description anyway, so I figure why bother storing it twice.

As for my promotional discounts and so on... yes, I'll probably have a table that stores all the current promo offers and what is needed to qualify. In the cart, I'll need to store with each item a promo code that it belongs to, if it belongs to any. I haven't fully thought this part through yet. I'm going to start working on all this in a couple weeks.
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

If you ave a set of discount always applyable whatever the product is, I would suggest
DiscountID | Discount
1 | 10%
2 | 15%

so you just apply an id in the main table..

just a suggestion..
Swede78
Forum Contributor
Posts: 198
Joined: Wed Mar 12, 2003 12:52 pm
Location: IL

Post by Swede78 »

Thanks for the suggestion. What I want to do with promotional discounts gets much more complicated than a percent off or sale price of an item or category of items. That's not a problem, as I already have that done in a similar fassion. I want to have complicated discounts, applied automatically for promotions such as:

example A) Buy an item from category 1, and pick 2 free items from category 33.

example B) Buy an item from category 1, 2, and 10, and get $X or X% off

example C) Buy any 5 items from categories 5, 7, or 12, and get $X off of each item.

Doing this without using a database driven cart, would be very difficult if not impossible.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

Swede78 wrote:
What information do you store in sessions?
as far as the shopping cart goes, pretty much everything. I actually just store the entire object into the session, makes it super easy.
but that may not be the best thing for a high traffic site...

Code: Select all

<?php

require_once 'lib/shoppingcart.inc.php';

session_start();

$ShoppingCart =& $_SESSION['ShoppingCart'];

if (!is_object($ShoppingCart)) {
    $ShoppingCart = new ShoppingCart();
}

?>
Post Reply