SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Shopping Cart - empty error

    I have a site I maintain, mostly from a design standpoint. I know some PHP, enough to make some changes but am having an issue that I cannot figure out and hoping someone here can help me.

    From what I know, this seems to be happening only in Firefox.

    They add an item(s) to the cart > click Proceed to Checkout > it says "You have no items in your cart."

    <snip />

    Thank you for any assistance or guidance you can give me to resolve this.
    Last edited by cpradio; Mar 25, 2013 at 09:32. Reason: Link to site is unnecessary

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,066
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Post your code, otherwise, there isn't much we can do. Please remove any confidential information (usernames, passwords, etc).
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Suppose that would help. Here it is:


    PHP Code:
    <?

    function check_if_empty($orderid$orderitems_table)
    {
        
    $query "SELECT * FROM {$orderitems_table} WHERE item_orderid = {$orderid}";
        
    $items doSelect($query);
        if(
    count($items) < 1)
        {
            
    setcookie("orderid"0time()-(3600*48), '/');
        }
    }

    $price_to_use "prod_price";
    $checkout "checkout";
    $order_table "orders";
    $orderitems_table "orderitems";

    foreach(
    $_POST as $name => $value){ $$name $value; }




    if (
    $mode == "add"){
        
        if(!
    $orderid)
        {
            
    $query "insert into orders (order_id, order_startdate) values ('', date_sub(now(), interval 2 hour))";
            
    $i doInsert($query);
            
    $orderid mysql_insert_id();
            
    setcookie("orderid"$orderidtime()+(3600*12), '/');
        }
        
        
    $qty 0;
        if (isset(
    $_POST['qty'])) { $qty numberfy($_POST['qty']); }

        if (
    $qty 1){ $qty 1; }

        
    $query "select * from products where prod_id = $prodid";
        
    $results doSelect($query);
        foreach(
    $results[0] as $name => $value){
            $
    $name $value;
        }
        
    $prod_name addslashes($prod_name);
        
    $actual_price = $$price_to_use;

        
    $count 1;
        
    $name "optionset_$count";
        while (
    $_POST[$name]){
            
    $value htmlspecialchars($_POST[$name]);
            
    $prod_name .= ", $value";
            
    $count++;
            
    $name "optionset_$count";
        }
            
        
    $oldqty 0;
        
    // Check to see if item (with same attributes) is already in cart
        
    $query "select item_qty from $orderitems_table where item_prodid = $prod_id and item_name = '$prod_name' and item_orderid = $orderid";
        
    $results doSelect($query);
        
    $oldqty $results[0][0];

        echo 
    "oldqty = " $oldqty '<br />';
        if (
    $oldqty){  // Add qty to existing item
            
    $newqty $qty $oldqty;
            
    $query "update $orderitems_table set item_qty = $newqty where item_prodid = $prod_id and item_name = '$prod_name' and item_orderid = $orderid";
            
    $u doUpdate($query);
            echo 
    "update";
        } else {  
    // Add new item
            
    $query "insert into $orderitems_table (item_id, item_prodid, item_orderid, item_name, item_sku, item_priceeach, item_qty) ";
            
    $query .= "values ('', $prod_id$orderid, '$prod_name', '$prod_sku', $actual_price$qty)";
            
    $i doInsert($query);
            echo 
    "insert";
        }
        
    header("Location: /cart/");
        exit();
    }

    if (
    $mode == "update"){
        
    $query "select item_id, item_qty, item_wrap from $orderitems_table where item_orderid = $orderid";
        
    $items doSelect($query);
        foreach(
    $items as $item){
            
    $newqty numberfy($_POST["item_qty_$item[0]"]);
            if (
    $newqty && $newqty 1000 && $newqty != $item[1]){
                
    $query "update $orderitems_table set item_qty = $newqty where item_id = $item[0]";
                
    $u doUpdate($query);
            }
            
    $newwrap numberfy($_POST["item_wrap_$item[0]"]);
            if ((
    $newwrap == || $newwrap == 1) && $newwrap != $item[2]){
                
    $query "update $orderitems_table set item_wrap = $newwrap where item_id = $item[0]";
                
    $u doUpdate($query);
            }
        }
        
    check_if_empty($orderid$orderitems_table);
        
    header("Location: /cart/");
    }

    if (
    $mode == "remove"){
        
    $itemid numberfy($_GET['var2']);
        
    $query "delete from $orderitems_table where item_id = $itemid and item_orderid = $orderid";
        
    $d doDelete($query);
        
    check_if_empty($orderid$orderitems_table);
        
    header("Location: /cart/");
    }

    if (
    $orderid){
        
    $query "select * from $orderitems_table where item_orderid = $orderid";
        
    $items doSelect($query);
    }

    $pagetitle "Cart";
    include(
    "template_main-top.php");
    include(
    'mainmenu.php');
    ?>

    <div id="topbar">&nbsp;</div>

    <img src="/images/cart_header.gif">

    <div id="cart">
        
        <form action="updatecart/" method="post" id="cartform">
        <input type="hidden" name="func" value="cart" />
        <input type="hidden" name="mode" value="update" />
        <input type="hidden" name="catid" value="<? echo $catid?>" />
        <input type="hidden" name="page" value="<? echo $page?>" />
        <input type="hidden" name="subcatid" value="<? echo $subcatid ?>" />
        
        <? if($items): ?>
            <div id="top_buttons">
                <a href="/shop" class="shop"><img src="/images/button_keepshopping.gif"></a>
                <a href="#" onClick="document.forms['cartform'].submit(); return false;" class="update"><img src="/images/button_updatecart.gif"></a><br/>
            </div>
        <? endif; ?>
        
        <table id="cart">
            <tr id="cartbar">
                <td class="desc" colspan="2"><strong>ITEM DESCRIPTION</strong></td>
                <td class="price"><strong>PRICE</strong></td>
                <td class="qty"><strong>QTY</strong></td>
                <td class="subtot"><strong>SUBTOTAL</strong></td>
                <td class="remove">&nbsp;</td>
            </tr>
            <?
            $subtotal2 
    0;
            if(
    $items){
                foreach (
    $items as $item){
                    foreach(
    $item as $name => $value){ $$name $value; }
                    
    $subtotal = ($item_qty $item_priceeach);
                    
    $subtotal2 $subtotal2 $subtotal;
                    
                    
    // Get main picnum
                    
    $query "select prodpics_picnum from prodpics where prodpics_prodsku = '$item_sku' order by prodpics_order limit 1";
                    
    $results doSelect($query);
                    
    $mainpic $results[0][0];
                    
    ?>
                    <tr>
                        <td><img src="/prod_images/<? echo $item_sku?>__<? echo $mainpic?>-tiny.jpg" /></td>
                        <td><?= $item_name ?></td>
                        <td>$<?= $item_priceeach ?></td>
                        <td><input type="text" name="item_qty_<?= $item_id ?>" value="<?= $item_qty ?>" size="2" maxlength="3" /></td>
                        <td><? printf("\$%.2f"$subtotal); ?></td>
                        <td><a href="/cart/remove/<?=$item_id?>/">remove</a></td>
                    </tr>
                    <?
                
    }
            } else {
                
    ?>
                <tr>
                    <td colspan="6">You have no items in your cart.</td>
                </tr>
                <?
            
    }
            
    $total $subtotal2;
            
    ?>
        </table>
        
        <? if($items): ?>
            <div id="subtotal"><strong>Subtotal:</strong> <em>$<? printf("%.2f"$subtotal2); ?></em></div>
            <div id="proceed_button">
                <a href="https://<?= $root ?>/checkout/" class="checkout"><img src="/images/button_proceedtocheckout.gif"></a>
            </div>
        <? endif; ?>
        
        </form>

    </div>

    <?
    include("template_main-bottom.php");
    ?>
    Last edited by cpradio; Mar 25, 2013 at 10:33. Reason: Added php tags

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi cpradio - did you add to my code above? Trying to see if it's different, if so, where.

    Thx.

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If this helps at all, yesterday I added one item and when I clicked to checkout it said no items in the cart. If I click back on the "Shop" link, which takes me back to the main shopping page, it shows 0 items in the cart, but if I click "continue shopping" it will still show 1 item in the shopping cart.

    If I then add a second item, then click "Proceed to checkout" it gives me the form to complete with name, address, etc.

  6. #6
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Could be that you're starting at www.example.com and your checkout link goes to example.com (no www). This would put you in a different session. I've seen this before. If so, the solution would be to force all traffic to either with or without www (which may be a good idea regardless).
    - Robert

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see in the code where it is specifying the domain, just the code for the cart, items, etc.

  8. #8
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Your Proceed button has
    href="https://<?= $root ?>/checkout/"

    but nothing else uses that $root variable. I can't be sure that's the issue, but check it out.
    - Robert

  9. #9
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    hmm how interesting!

    OK, it works for me in Firefox on the Mac but NOT in Firefox on PC (Win7) .

    As QMonkey points out - you are going from http to https and no www. to https://www. so your cookie may not be respecting the domain change.
    Var_dump the cookie contents on the cart page and see if they are there.

    I would point to the cookie as being the issue and how its being read my FF on PC.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  10. #10
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks QMonkey and spikeZ.

    My homework now - to figure out how to do this. A bit beyond my knowledge at this point, but every day is a learning day. I'll let you know how it goes.

  11. #11
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code is in my globals.php - does this help at all?

    <?

    $root = "www.shoplilygirl.com";


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
  •