Results 1 to 3 of 3

Thread: [Shopping Cart] Hot Ones

  1. #1
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default [Shopping Cart] Hot Ones

    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

  2. #2
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 9 Times in 9 Posts

    Default

    1. Yes it is possible.

    First of all, regarding the use of session_register().
    Quote Originally Posted by PHP Manual
    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.
    PHP Code:
    session_start();

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

    $_SESSION['cart'] = serialize($cart); 
    The array is now stored in $_SESSION['cart']. To retrieve it:
    PHP Code:
    $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.

  3. #3
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •