I'm using laravel 5.5 with darryldecode/cart 3.0. It's working good with the first item added to the cart, but can't understand why from the 2nd the item is not added and managed by the cart.
addToCart function in Controller:
if(Cart::session($userid)->get($itemid)){
Cart::session($userid)->update($itemid, array('quantity' => $quantity));
}else{
Cart::session($userid)->add(array(
'id' => $vino->articolo,
'name' => $vino->descrizione,
'price' => $vino->prezzo_vendita,
'quantity' => $quantity,
//'attributes' => array(),
));
}
$cart = Cart::session($userid)->getContent();
$cart['total'] = Cart::session($userid)->getTotal();
I'm using the userID for the user and the item ID (SKU) as rowID. The first item added to the session is working good, if I try to update the quantity by the rowID is ok. But whatever I add after the first item is not being added to the session and not recognized anymore by the update code.
So I end with something like this:
{"SCR06":{"id":"SCR06","name":"Amarone Classico della Valpolicella DOCG Magnum","price":68.5,"quantity":10,"attributes":[],"conditions":[]},"CCE10":{"id":"CCE10","name":"Cabernet Sauvignon Palazzo del Principe","price":8.9,"quantity":1,"attributes":[],"conditions":[]},"total":693.9}
The first item added, SRC06, is being updated correctly...the second one is not really registered in the session and I'm not able to update it. If I refresh and try $cart = Cart::session($userid)->getContent(); without the add, the first item appears correctly, the second one no.
How can I manage multiple item in the same session cart?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire