0

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.

akond
  • 15,865
  • 4
  • 35
  • 55
Khalid Amin
  • 872
  • 3
  • 12
  • 26
  • 1
    Speck is under heavy development, and many parts may still be in an "alpha" stage. You should be able to contact the speck devs directly via their IRC channel, #speckcommerce, on freenode. – David Jan 07 '13 at 15:27
  • Thanks @David, however I have implemented my own mechanism using session container, and this is working pretty good ;-) – Khalid Amin Jan 10 '13 at 16:59

1 Answers1

0

Just came across this after trying the speckcart module out for the first time. I think your problem here is that you are trying to set the CartItemId. The database code (provided within the module) makes the cart item Id an auto-incremented primary key field, which therefore should not be set as the database should create it automatically.

Also, you must supply a quantity as the quantity's database field is set to not accept null values.

Other than that, everything should work.

Hope this helps.

Jamie Mclaughlan
  • 845
  • 2
  • 10
  • 29