Skip to content

Instantly share code, notes, and snippets.

@fabiocarneiro
Last active December 25, 2015 22:19
Show Gist options
  • Save fabiocarneiro/7048644 to your computer and use it in GitHub Desktop.
Save fabiocarneiro/7048644 to your computer and use it in GitHub Desktop.
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;
}
}
$cart = new cart();
if(!isset($_SESSION['cart'])){
$_SESSION['cart'] = array();
}
$cart->setItem($_SESSION['cart']);
@usm4n
Copy link

usm4n commented Oct 18, 2013

hi i have corrected the error it was in setItem function you can find it here https://gist.github.com/usm4n/7049339

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment