I am using SpeckCart shopping cart module in my ZF2 project. I have setup the module and it adds item to the cart successfully, but it overwrites the same item on every call instead of adding new items. Please guide me where I am doing anything wrong, here is the code:
public function addAction(){
$prod_id = $this->params()->fromPost('prod_id');
$product = $this->getProductTable()->getProduct($prod_id);
$item = new CartItem();
$item->setDescription($product->name);
$item->setCartItemId($prod_id);
$item->setPrice($product->price);
$cs = $this->getServiceLocator()->get('SpeckCart\Service\CartService');
$cart = $cs->getSessionCart(true);
// I think the above line is creating a new cart every time and this is where the problem lies. I am unable to know how to make it use the existing cart created in previous call.
$cs->addItemToCart($item, $cart);
I am a newbie regarding ZF, please let me know how should I use this cart module properly. The above code is from an action of my application that is called every time the 'add to cart' button is pressed.