Bir kullanıcı bir ürünü (onlar 3 ürün var diyelim) satın alıyor ve onların bilgi yazdığınız zaman, ürün otomatik olarak = 0 durumu ile veritabanına girer.
Kullanıcı uzakta sepetten gidiyor ise, (ve şimdi onlar sepette 4 ürün var, extra ürün satın alma) ürün genel olarak varsayalım.
Ben veritabanına yeni bir ürün eklemek yerine ürünlerin 3 zaten takılı olduğu için, tüm ürünleri + yeni bir ekleme nasıl bulmak zorunda.
$_SESSION['inserted_ids'] = array();
$id = '';
if( in_array( $id, $_SESSION['inserted_ids']) ){
return;
}else{
$id = $db->Insert("INSERT INTO orders SET
name = '". $_SESSION['information']['name'] ."',
address = '". $_SESSION['information']['address'] ."',
date = '". Database::Now() ."',
phone = '". (isset($_SESSION['information']['phone']) ? $_SESSION['information']['phone']:'') ."',
email = '". $_SESSION['information']['email'] ."',
city = '". $_SESSION['information']['city'] ."',
zipcode = '". $_SESSION['information']['zipcode']."'
");
$_SESSION['inserted_ids'][] = (int) $id;
# lists products
$list = '';
$grand_total = '';
$res = $db->Execute("sql with product_id");
while($row = $res->GetNext()){
if( $row['product_id'] == $_SESSION['inserted_ids'] ){
$db->Execute("INSERT INTO order_lines SET
price = '$round_price',
order_id = $id,
product_id = $product_id,
product_name = '$product_name',
units = '$grand_units',
status = '0',
date = '".Database::Now()."',
item_num = '".$item_num."';
ON DUPLICATE KEY UPDATE SET
units = '$grand_units'
WHERE order_id = $id
LIMIT 1;
");
}
}
}