Skip to content

Commit 30c1903

Browse files
committed
fix bug
1 parent 4c0a6ad commit 30c1903

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/CartService.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,15 @@ public function moveSessionToDatabase()
144144
if ($this->hasSession() && $this->storage instanceof Model) {
145145
$session = \Session::get($this->instanceName);
146146
\Session::forget($this->instanceName);
147-
$this->cart = $this->cart->merge($session->toArray());
147+
$session->each(function ($item) {
148+
$cart=$this->cart->where("cartable_id", $item["cartable_id"])->where("cartable_type", $item["cartable_type"])->first();
149+
if (!is_null($cart)) {
150+
$item["id"]=$cart["id"];
151+
$item["quantity"]+=$cart["quantity"];
152+
$item["price"]=$cart["price"];
153+
}
154+
$this->cart->put($item["id"], $item);
155+
});
148156
$this->save();
149157
}
150158

0 commit comments

Comments
 (0)