1 year ago

Add to cart qty not working,

Posted 1 year ago by tehseen

Hi, Below was the code i add product to cart it works fine when in add product to card with no specific quantity (only one product at once),


public function add($item, $id){
        $storedItem = ['qty' => 0, 'price' => $item->price, 'item' => $item];
        if($this->items) {
            if(array_key_exists($id, $this->items)) {
                $storedItem = $this->items[$id];
        $storedItem['price'] = $item->price * $storedItem['qty'];
        $this->items[$id] = $storedItem;
        $this->totalPrice += $item->price;

But when i pass third parameter $qty in my add function (e.g i add 3) it become add the 4 product i know it increment one as it was fine. but the total quantity is not incremented why?

Please advice

Please sign in or create an account to participate in this conversation.