mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
add better livewire support
- and reset collection indexes properly
This commit is contained in:
+11
-3
@@ -340,7 +340,7 @@ public function condition(array|CartCondition $condition): self
|
||||
*
|
||||
* @param bool $active - If true, only conditions actually applied on the cart are returned
|
||||
*/
|
||||
public function getConditions(bool $active = false): CartConditionCollection
|
||||
public function getConditions(bool $array = false, bool $active = false): CartConditionCollection|array
|
||||
{
|
||||
$conditions = new CartConditionCollection(
|
||||
$this->session->get($this->sessionKeyCartConditions)
|
||||
@@ -358,7 +358,9 @@ public function getConditions(bool $active = false): CartConditionCollection
|
||||
});
|
||||
}
|
||||
|
||||
return $conditions;
|
||||
return $array ? $conditions->map(function (CartCondition $condition) {
|
||||
return $condition->toArray();
|
||||
})->toArray() : $conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -404,6 +406,9 @@ public function removeCartCondition($conditionName)
|
||||
|
||||
$conditions->pull($conditionName);
|
||||
|
||||
// reset indexes
|
||||
$conditions = $conditions->values();
|
||||
|
||||
$this->saveConditions($conditions);
|
||||
}
|
||||
|
||||
@@ -456,6 +461,9 @@ public function removeItemCondition($itemId, $conditionName)
|
||||
}
|
||||
}
|
||||
|
||||
// reset indexes
|
||||
$item['conditions'] = array_values($item['conditions']);
|
||||
|
||||
$this->update($itemId, [
|
||||
'conditions' => $item['conditions'],
|
||||
]);
|
||||
@@ -728,7 +736,7 @@ protected function addItem($id, $item)
|
||||
/**
|
||||
* save the cart
|
||||
*
|
||||
* @param $cart CartCollection
|
||||
* @param $cart CartCollection
|
||||
*/
|
||||
protected function save($cart)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user