Last active
December 25, 2015 22:19
-
-
Save fabiocarneiro/7048644 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class cart { | |
public $item; | |
public function getItem() { | |
return $this->item; | |
} | |
public function setItem(&$item) { | |
$this->item = $item; | |
} | |
public function addItem($id, $quantity = 1){ | |
$array = array( | |
'id' => $id, | |
'quantity' => $quantity | |
); | |
if($this->checkStock($id, $array['quantity'])){ | |
$this->item[] = $array; | |
var_dump($this->item); | |
return true; | |
} | |
return false; | |
} | |
public function getItems(){ | |
var_dump($this->item); | |
return $this->item; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$cart = new cart(); | |
if(!isset($_SESSION['cart'])){ | |
$_SESSION['cart'] = array(); | |
} | |
$cart->setItem($_SESSION['cart']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi i have corrected the error it was in setItem function you can find it here https://gist.github.com/usm4n/7049339