View Single Post
Old 08-30-2005, 01:55 PM   #1 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 124
metazai is on a distinguished road
Beware the multiple option shopping cart . . .

Some extra eyes needed on this . . .

I'm writing my first shopping cart, and using a table in mysql that will store the orders until they are finalized.
I have two kinds of products to deal with -- one is the standard, no variables kind of product, and that's been easy.
I decided to have it run a different block of code if it's the second kind of product, however -- in this type there is a price break based on the quantity of that item that you order . . . AND it has variables. So, you could order a blanket (part number 0001), and get a price break at 12 . . . but if you order 6 blue ones, then go back and add another 6 PINK blankets, the price needs to be lessened for the existing item and the new one.

I came up with a way of storing the different price rules and amounts, and that part works fine. Additionally, you can add items with the same color and part number, and the price breaks correctly.
When you add a like item with a DIFFERENT color, however, my code gets wacky. I'm not sure if this is too much to post here (I've edited out the way it determines the price amount), but I've got a feeling it may just be some stupid logical PHP grammar error I'm missing and just can't see. Any comments at all would be appreciated.

PHP Code:
// pull all temp_orders with same session and item number; get total of existing items with same item_number
$total_exis_items=0;
$query_pre "SELECT item_number,quantity,sessionid,variableone,variabl  etwo FROM temp_orders WHERE sessionid='$cust_session' AND item_number='$cust_item_number'";
$result_pre mysql_db_query($dbname$query_pre);
while (
$row_pre mysql_fetch_array($result_pre)) {
  
$total_exis_items=($row_pre['quantity'] + $total_exis_items);
}

// check for no items matching (therefore new item entered into the order)
if ($total_exis_items == 0) {
  if (
$cust_quantity <= $base_amount)
    
    ======
EXTERNAL FUNCTION THAT GIVES ME $cust_orderprice========
      
      
$query5="INSERT temp_orders SET item_name='$cust_item_name', quantity='$cust_quantity', item_number='$cust_item_number', orderprice='$cust_orderprice', variableone='$cust_variableone', variabletwo='$cust_variabletwo', pricetype='$cust_pricetype', sessionid='$cust_session'";
  
mysql_query($query5) or die(mysql_error());
  echo(
"<meta http-equiv=\"refresh\" content=\"0;URL=../cart/display_cart.php\">");
} else {
  
$query_ninety "SELECT item_number,quantity,sessionid,variableone,variabl  etwo FROM temp_orders WHERE sessionid='$cust_session' AND item_number='$cust_item_number'";
  
$result_ninety mysql_db_query($dbname$query_ninety);
  while (
$row_ninety=mysql_fetch_array($result_ninety)) {
    
$ravvarone=$row_ninety['variableone'];
    
$ravvartwo=$row_ninety['variabletwo'];
    
// check for items matching with same variables
    
if ($ravvarone $cust_variableone && $ravvartwo $cust_variabletwo) {
      
$final_exis_items=($total_exis_items $cust_quantity);
      
      ======
EXTERNAL FUNCTION THAT GIVES ME $cust_orderprice========
          
          
$updated_quantity=($row_ninety['quantity'] + $cust_quantity);
      
$query6="UPDATE temp_orders SET orderprice='$cust_orderprice', quantity='$updated_quantity' WHERE sessionid='$cust_session' AND item_number='$ravvarone' AND variableone='$ravvartwo' AND variabletwo='$cust_variabletwo'";
      
mysql_query($query6) or die(mysql_error());
      
$querysix="UPDATE temp_orders SET orderprice='$cust_orderprice' WHERE sessionid='$cust_session' AND item_number='$cust_item_number'";
      
mysql_query($querysix) or die(mysql_error());
      echo(
"<meta http-equiv=\"refresh\" content=\"0;URL=../cart/display_cart.php\">");
    }
    
    else {
      
$final_exis_items=($total_exis_items $cust_quantity);
      
      ======
EXTERNAL FUNCTION THAT GIVES ME $new_orderprice========
          
          
$query5="INSERT temp_orders SET item_name='$cust_item_name', quantity='$cust_quantity', item_number='$cust_item_number', orderprice='$new_orderprice', variableone='$ravvarone', variabletwo='$ravvartwo', pricetype='$cust_pricetype', sessionid='$cust_session'";
      
mysql_query($query5) or die(mysql_error());
      
$queryextra3="UPDATE temp_orders SET orderprice='$new_orderprice' WHERE sessionid='$cust_session' AND item_number='$cust_item_number'";
      
mysql_query($queryextra3) or die(mysql_error());
      echo(
"<meta http-equiv=\"refresh\" content=\"0;URL=../cart/display_cart.php\">");
    }
  }

And don't laugh at my variable names, or I'll cry like a little girl.

Last edited by redhead; 08-30-2005 at 02:12 PM. Reason: Indentation fixed to an extend
metazai is offline   Reply With Quote