Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement