Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. <?php
  2.  
  3. Class Cart
  4. {
  5.     public $cart = [];
  6.     public $product = [];
  7.  
  8.     public function __construct(){
  9.  
  10.     }
  11.  
  12.     public function add($id, $quantity){
  13.         $this->product['id'] = $id;
  14.         $this->product['quantity'] = $quantity;
  15.  
  16.         $this->cart[] = $this->product;
  17.     }
  18.  
  19.     public function update($id, $quantity){
  20.         if(!empty($this->cart[$id]['quantity'])){
  21.             $this->cart[$id]['quantity'] += $quantity;
  22.         }
  23.     }
  24.  
  25.     public function delete($id){
  26.         unset($this->$cart[$id]);
  27.     }
  28.  
  29.     public function empty(){
  30.         unset($this->$cart);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement