laravelshoppingcart
laravelshoppingcart copied to clipboard
The order of the items after updating always changes
The cause of the always changing order is the pull method
https://github.com/darryldecode/laravelshoppingcart/blob/7f1581d64184575384d1a09924e45142e3bc58ed/src/Darryldecode/Cart/Cart.php#L242
If updating the first item will move to the lowest order, this causes the Frontend to always move.
Same for me, how to fix?
This is the normal behavior when updating. If you would like to maintain the order somehow check this for solution -> https://github.com/darryldecode/laravelshoppingcart/issues/47
This is the normal behavior when updating. If you would like to maintain the order somehow check this for solution -> #47
Because I want the order based on the time of adding to the shopping cart.
===
Same for me, how to fix?
temporary and possibly permanent solutions: D
Cart::add([
'id' => $product->id,
'name' => $product->name,
'price' => $product->getActualPrice()->getValue(),
'quantity' => $request->input('quantity', 1),
'attributes' => [
'added_at' => Carbon::now(),
],
'associatedModel' => $product,
]);
and then
$contents = Cart::getContent()->sortBy(function ($cart) {
return $cart->attributes->get('added_at');
});