Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function addToCart($id, $name, $price)
- {
- $is_in_cart = false;
- $index = 0;
- foreach ($_SESSION['cart'] as $key => $arr) {
- if ($arr['id'] == $id) {
- $is_in_cart = true;
- $index = $key;
- break;
- }
- }
- if ($is_in_cart) {
- $_SESSION['cart'][$index]['quantity']++;
- } else {
- array_push($_SESSION['cart'], array('id' => $id, 'name' => $name, 'price' => $price, 'quantity' => 1));
- }
- self::$cart = $_SESSION['cart'];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement