Log in

View Full Version : [Shopping Cart] Hot Ones



sysout
02-11-2009, 08:56 AM
I wanna ask about Shopping Carts ^^

The Case :

I use 2 sessions for this cart :
- $cart = session_register("cart");
- $qty= session_register("qty");

An example :
when a customer choose an item (item code : TS0001) and he buys 3pcs for that items, and then add an item again (item code : TS0002) and he puts 2pcs into the cart.

I wanna add this items to $cart, but, I want the format to be like this :
$cart = ("TS0001 => 3, TS0002 => 2");
yeap, into an array.

Questions :

I wanna make the shopping cart to be like this, is it possible? :(

-------------------------------------------------------------------------
Another Case (Session Lifetime) :

A customer goes shopping for quite long (just say, about 37 munites), after 28 munites, he was surprised because he was logged out automatically (the session expired after 28 munites, and destroy all of it).

The matter is :
The customer can log in again, but..all items in his cart was disapper.
Another matter, everytime he adds items to his cart, I update my stock (stock-qty), so that if the stock <= 0, it will display "SOLD OUT".
If the session like this, it would make a big problem to my database and of course, customer satisfaction.


Can anybody help me for this?
I really appreciate if anyone do :)

BabblingIdjit
02-11-2009, 06:01 PM
1. Yes it is possible.

First of all, regarding the use of session_register().

Warning

This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.



session_start();

$cart = ("TS0001 => 3, TS0002 => 2");

$_SESSION['cart'] = serialize($cart);

The array is now stored in $_SESSION['cart']. To retrieve it:


$cart_contents = unserialize($_SESSION['cart']);

2. You can:

a) If you have access to your php.ini file, you can adjust the session.gc_maxlifetime directive.
b) Use cookies instead of sessions
c) Use a temporary table to store the cart instead of sessions. You'd still need a cookie to identify the record if the user comes back.

sysout
02-12-2009, 11:34 PM
2. You can:

a) If you have access to your php.ini file, you can adjust the session.gc_maxlifetime directive.
b) Use cookies instead of sessions
c) Use a temporary table to store the cart instead of sessions. You'd still need a cookie to identify the record if the user comes back.

Any examples palz? Thanks before