Advertisement
Socialking

Untitled

Jul 27th, 2021
1,387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. if (isset($_POST["add_to_cart"])) {
  2.     if ($_GET["action"] == "add") {
  3.         if (isset($_SESSION["cart"])) {
  4.             $item_array_id = array_column($_SESSION["cart"], "id");
  5.             $count = count($_SESSION["cart"]) + 1;
  6.             $item_array = array(
  7.                 'id' => generate_random_letters(5),
  8.                 'name' => $_POST["product_name"],
  9.                 'price' => $_POST["product_price"],
  10.                 'quantity' => $_POST["product_quantity"],
  11.                 'description' => $_POST["product_description"],
  12.                 'product_additional_info' => $_POST['product_additional_info'],
  13.                 'salate_sauce' => $_POST['salate_sauce'],
  14.             );
  15.             $_SESSION["cart"][$count] = $item_array;
  16.             header("Location: app_orders.php?action=product_added");
  17.         } else {
  18.             $item_array = array(
  19.                 'id' => generate_random_letters(5),
  20.                 'name' => $_POST["product_name"],
  21.                 'price' => $_POST["product_price"],
  22.                 'quantity' => $_POST["product_quantity"],
  23.                 'description' => $_POST["product_description"],
  24.                 'product_additional_info' => $_POST['product_additional_info'],
  25.                 'salate_sauce' => $_POST['salate_sauce'],
  26.             );
  27.             $_SESSION["cart"][0] = $item_array;
  28.         }
  29.     }
  30. }
  31.  
  32. if ($_GET["action"] == "delete") {
  33.     foreach ($_SESSION["cart"] as $keys => $value) {
  34.         if ($value["id"] == $_GET["id"]) {
  35.             unset($_SESSION["cart"][$keys]);
  36.             header("Location: app_orders.php?action=product_deleted");
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement