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