Inserting Order Problem.
Posted: Wed Feb 02, 2005 4:34 pm
HI guys, I got a slight problem with one of my scripts. What I want to do is for each item that is in the cart I would like to be able to check each individual items stock_level. Now if that stock_level is below a certain threshold then it will have different data put into the database i.e preorder, processing, awaiting stock etc. The problem is that I can get the information about stock level I want however if I enter two items or more it gives me both values of the stock level for eg. 0 for vinyl A and 2 for vinyl B. This means that I can’t check both in isolation as they spit our the stock_level for both. This is because im using a function to get the details of the vinyls in the cart. Is there anyway I can get these and check them one by one after the get_vinyls_function using an array or something? Any actually code tips would be much appreciated or a point in the right direction.
Code is
Code is
Code: Select all
function insert_order($order_details)
{
//function inserts the order details into the order table.
extract($order_details);
if(!$delivery&&!$name&&!$title&&!$surname&&!$address1&&!$town&&!$town&&!$city&&!$county&&!$postcode&&!$total&&!$customer_id&&!$number&&!$expiry&&!$start&&!$issue&&!$type&&!$cardname)
{
$delivery = $_SESSIONї'shipping'];
$name = $ship_name;
$title = $ship_title;
$surname = $ship_surname;
$address1 = $ship_address_1;
$town = $ship_town;
$city = $ship_city;
$county = $ship_county;
$postcode = $ship_postcode;
$total = ($_SESSIONї'total_price']+$_SESSIONї'shipping']);
$customer_id = $_SESSIONї'customer_id'];
$number = $card_number;
$expiry = $expiry_date;
$start = $start_date;
$issue = $issue_number;
$type = $card_type;
$cardname = $card_name;
}
//-----------------------------------Insert Order into Database---------------------------------------------
$link_id = db_connect();
$date = date('Y-m-d-H-i-s');//get current date
//insert order into orders table.
$query = "insert into orders (order_id, customer_id, order_status, date_order_placed, delivery_charge, ship_name, ship_surname,
ship_title, ship_address1, ship_address2, ship_city, ship_county, ship_postcode, order_note, total)
values(NULL, '$customer_id', 'Processing Order', '$date', '$delivery','$name','$surname','$title','$address1',
'$town','$city','$county','$postcode', NULL,'$total')";
$result = @mysql_query($query, $link_id) or die(mysql_error());
if (!$result)
return false;
//<!-----------------------------------Get Order_id for current order--------------------------------------------->
//now we want to put each item into the ordered_items table so we must make sure we get the right order and do a query to retirieve the order.
$query = "select order_id from orders where customer_id = '$customer_id' and date_order_placed = '$date'";
$result = @mysql_query($query) or die(mysql_error());
var_export($query);
$order_id = mysql_result($result, 0, 'order_id');
if(!$result)
return false;
//<!-----------------------------------Insert Payment Details into Database--------------------------------------------->
//do the query and insert the values
$query = "insert into payments values('".$_SESSIONї'customer_id']."','$order_id','$total','$number','00-00',
'$issue','00-00','$type','$cardname')";
$result = @mysql_query($query, $link_id) or die(mysql_error());
if(!$result)
return false;
//<!-----------------------------------Loop through each item in the ordered items table and insert--------------------------------------------->
foreach($_SESSIONї'cart'] as $catno => $qty)
{
$detail = get_vinyl_details($catno);
$query = "delete from ordered_items where order_id = '$order_id' and cat_no = '$catno'";
$result = mysql_query($query);
//var_export($detail);
print $detailї'stock_level'];
//if($detailї'stock_level'] < 0);
// {
$query = "insert into ordered_items values ('$catno','$order_id','On Order', '".$detailї'price']."','$qty')";
$result = @mysql_query($query, $link_id) or die(mysql_error());
//}
//if($detailї'stock_level'] > 0);
//{
// $query = "insert into ordered_items values ('$catno','$order_id','Processing', '".$detailї'price']."','$qty')";
// $result = @mysql_query($query, $link_id) or die(mysql_error());
//}
if (!$result)
return false;
}
return $order_id;
}