Hi All,
I am hoping to finish this feature on a shopping cart soon - just one thing im not sure how to create.
Basically: 1 hour after a user has put the very first item into the shopping cart - (items are stored in the database) I want to create an event, that after one hour empties the cart table WHERE user_id = '$user_id';
All items in the cart are to be deleted, and then two other tables need to be updated based on the content of the basket.
1) Table "sizes" - needs to be updated, and have "antal" (means stock..) set to the number of that particular number that was in the cart before, and WHERE size = '$size'; So if the cart had 2 * Large, I need to update the "sizes" table with 2 * Large where product_id = $some_id;
2) Table "products" - Needs to be updated and set "stock" = the number of goods that was in the cart of that particular product_id. So if the basket had 3 items of product_id = 1, Then I need to add this back to the products table where product_id = $some_id;
_______________________________________________
I am doing this when the customer is viewing his cart - And it is exactly these 3 calls which needs to be executed after one hour of the first item inserted. - Only here these actions are triggered after a customer has clicked a link ("Remove all items from cart, red").
I need them to be executed if the customer left the site and the cart without deleting them
<?PHP // This happens if a link is clicked in the cart of the website:
// Delete from cart, and update "sizes" and "products":
$REMOVE_sql = mysqli_query($connection, "
DELETE FROM cart WHERE id = '".$FJERN_alt_kurv_id."' AND user_id = '".$user_id."'");
// Update products, and set stock = the number of goods deleted from the cart:
$plus_SQL_products = mysqli_query($connection, "
UPDATE products SET stock = stock + '".$FJERN_alt_antal."' WHERE produkt_id = '".$FJERN_alt_id."'");
// Update sizes and set the stock of the particular size = number of goods from the cart in that size:
$plus_SQL_sizes = mysqli_query($connection, "
UPDATE sizes SET antal = antal + '".$FJERN_alt_antal."' WHERE product_id = '".$FJERN_alt_id."' AND size = '".$FJERN_alt_str."'");
header('location: /indkoebskurv');
?>
So, if the user has items in the cart, and leaves the site without removing the items, I need the items to be autimatically removed after an hour, and execute these three calls.
I have read that I cant use parameters in an EVENT, but that I can call a stored procedure which has got parameters.
- It might be a little messy, but I hope I have made my intentions clear.
As I havent created events before, neither have I created stored procedures - and never even been close on combining those :-)
Can someone point me in the right direction on how to do this?
Regards, Klemme