SHARE
TWEET

Untitled

a guest Jan 27th, 2020 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function addToCart($id, $name, $price)
  2.     {
  3.         $is_in_cart = false;
  4.         $index = 0;
  5.         foreach ($_SESSION['cart'] as $key => $arr) {
  6.             if ($arr['id'] == $id) {
  7.                 $is_in_cart = true;
  8.                 $index = $key;
  9.             break;
  10.             }
  11.         }
  12.         if ($is_in_cart) {
  13.             $_SESSION['cart'][$index]['quantity']++;
  14.         } else {
  15.             array_push($_SESSION['cart'], array('id' => $id, 'name' => $name, 'price' => $price, 'quantity' => 1));
  16.         }
  17.         self::$cart = $_SESSION['cart'];
  18.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top