mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
Fix products sequence after changing cart item options
This commit is contained in:
11
src/Cart.php
11
src/Cart.php
@@ -180,6 +180,8 @@ class Cart
|
||||
$content = $this->getContent();
|
||||
|
||||
if ($rowId !== $cartItem->rowId) {
|
||||
$itemOldIndex = $content->keys()->search($rowId);
|
||||
|
||||
$content->pull($rowId);
|
||||
|
||||
if ($content->has($cartItem->rowId)) {
|
||||
@@ -193,7 +195,14 @@ class Cart
|
||||
|
||||
return;
|
||||
} else {
|
||||
$content->put($cartItem->rowId, $cartItem);
|
||||
if (isset($itemOldIndex))
|
||||
{
|
||||
$content = $content->slice(0, $itemOldIndex)
|
||||
->merge([$cartItem->rowId => $cartItem])
|
||||
->merge($content->slice($itemOldIndex));
|
||||
} else {
|
||||
$content->put($cartItem->rowId, $cartItem);
|
||||
}
|
||||
}
|
||||
|
||||
$this->events->dispatch('cart.updated', $cartItem);
|
||||
|
||||
Reference in New Issue
Block a user