I’m using laravel cart by Crinsane https://github.com/Crinsane/LaravelShoppingcart
I wanna update options cart, I have many options inside, but I just want only one option to change, and I cannot do it
Here’s my code
Cart::add([ 'id' => 1, 'name' => 'Keyboard', 'qty' => 30, 'price' => 399, 'options' => [ 'item_code' => 'KEY01', 'dimension' => '30cm x 60cm', ...etc] ]);
and then I want to change options
Here’s my code
Cart::update( $rowId, [ 'qty' => 60, 'price' => 299, 'options' => [ 'item_code' => 'KEY02'] ]);
and then the result options only item_code, and others are disappear I want the others options still there, how to handle this?
Sorry for bad English
Thanks for Answer
Advertisement
Answer
Please try by following code.
$item = Cart::get($rowId); $option = $item->option->merge(['item_code' => 'KEY02']); Cart::update( $rowId, [ 'qty' => 60, 'price' => 299, 'options' => $option ]);