SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 35 of 35
  1. #26
    Non-Member Big Fat Bob's Avatar
    Join Date
    Sep 2004
    Location
    United Kingdom (Come)
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yo

    or should I put the product name and price
    in the orders table as well.
    I wouldn't as then you'd have repeatitive data, breaking the 3 normalisation rules.

    I would keep the parts and orders in their own tables, using keys to relate the data in a seperate table.

  2. #27
    Non-Member Gator99's Avatar
    Join Date
    Sep 2004
    Location
    Florida
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sojomy
    Accessing a session variable is quicker than making a database connection, making an sql query and closing the database connection from what I've read.
    Probably, but I don't know how much overhead is involved in using sessions. However, if your catalog/products are pulled from the database, the connection is already made.

  3. #28
    Non-Member Big Fat Bob's Avatar
    Join Date
    Sep 2004
    Location
    United Kingdom (Come)
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yo

    Little overhead whilst using sessions provided that your sessions file size is not too big, for example larger than 4K.

    Never really a problem with a shopping basket, unless of course you're expecting tens of thousands of visitors every other minute ?

    On the matter of database reads, you do not need to store your visitors basket to the database on every page load; that's why you have sessions, if this is what your wondering ?

  4. #29
    Non-Member Gator99's Avatar
    Join Date
    Sep 2004
    Location
    Florida
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Big Fat Bob
    Yo
    On the matter of database reads, you do not need to store your visitors basket to the database on every page load; that's why you have sessions, if this is what your wondering ?
    We be talkin about readin not writing.

  5. #30
    SitePoint Zealot itwebsolution's Avatar
    Join Date
    Jun 2003
    Location
    Richmond, VA
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sojomy
    How do sites like sitepoint keep you logged in? Do they pull your cookie from your computer on every page load? Or
    do they check for a session variable, and if there isn't one, then they load it from the cookie and store it in a session
    variable? Is there any advantage for one or the other, either pulling the cookie on every page load, or using the session
    variable on every page load and if there isn't one, then load it from the cookie?
    I think sites like this pull your session data from a cookie, but also keep some profile information in the database under your user profile.

  6. #31
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't as then you'd have repeatitive data, breaking the 3 normalisation rules.
    There is nothing wrong with duplicating data for performance reasons. But remember that you are then responsible for keeping it synchronized. If the normalization does not cause a performance problem, it is better not to duplicate.

  7. #32
    Non-Member
    Join Date
    Sep 2004
    Location
    India
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    After an extensive research and development i came to know that using databas with session id's is the best practice to create shopping carts. Also if you just use sessions or cookies to store cart information then that info. can be easily amnipulated with the cookie editors available on the internet.

    So a secure cart is a cart which does everything at server end and nothing at client end. Even a basic shopping carts needs to be secured. ;-)

    Thanks!

  8. #33
    SitePoint Addict
    Join Date
    Dec 2002
    Location
    Philadelphia
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use a $cart object. Here is my logic on the shopping page where it displays a minicart for the user:

    1. if there is no cart, then try to get one from database if the person is logged in....

    2. if they are logged in, but have no cart stored in the database profile, then create a new cart object.

    3. Otherwise, just create a new cart object.

    This code works beautifully....I came up with this because I wanted "persistent carts" for people who log out and return to the store later.



    PHP Code:
    <?php 
    if (isset ($_SESSION['cart'])){
    $cart=($_SESSION['cart']);
    session_register('cart');
    //if there is no cart, then try to get one from database if the person is logged in....
    }else if (isset ($_SESSION['memberid'])){
          
    $theid=$_SESSION['memberid'];
       
    $link mysql_connect($host,$user,$password)or die('Cannot retrieve Taui shopping cart'.mysql_error());
       
    mysql_select_db($DBName,$link);
       
    $query "select  id, cartcontents  from  $tablename11 where id='$theid' ";
       
    $result mysql_query($query$link) or die('Cannot run this query'.mysql_error());
             
       while(
    $Row mysql_fetch_assoc ($result)) {
       
    $cartobject=$Row['cartcontents'];
       
    //this is of course assuming that if they're logged in, they have a cart active!
         
         
    $cart=unserialize("$cartobject");
         
    //check what we got from the database and see if its an actual cart, or just garbage.
         
    if(is_object($cart)){
         
    session_register('cart');
         }else{
         
    $cart= new ShoppingCart();
         
    $flag=true;
         }
       
        }
    //end while
    }else{
        
     
     
    $cart= new ShoppingCart();
     
    }
    //$cart->displaycart();
    $cart->displayminicart();
    ?>

  9. #34
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Big Fat Bob
    PHP Code:
    class basket
    {
    function 
    basket()
    {
    if(isset(
    $HTTP_COOKIE_VARS["OrderID"]))
    {
    return 
    $HTTP_COOKIE_VARS["OrderID"];
    }
    else
    {
    session_start();
    setcookie("OrderID"session_id(), time() + ((3600 24) * 30));
     
    return 
    session_id();
    }

    For me that's (cookies) a big NoNo.
    Common trend is that more and more people are switching off all cookies (but session cookies).

    As a seller i don't want to lock off people (and so loosing sales) just because of not enough thought-out programming.

    As for storing the cart data i use just a session.
    A user doesn't has to log in as well. Whzy should he? Just a quick purchase without any complications and anyoing, too many questions.
    IMHO best example of how not to do it is osC.

    The user has the option to register and only then his personal and cart data are stored in the database.

    But how to handle a ecommerce site is a philosophy of its own with so many different opinions which also have to vary due to different rules and regulation in different countries.

    BTW, there's an ecommerce forum here at sitepoint as well. Some interesting topics there...
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  10. #35
    SitePoint Addict
    Join Date
    Dec 2002
    Location
    Philadelphia
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with Frezno (who does not play well with others)

    Look at my example above...my code does that.


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
  •