Update Cart.php

JSON encode to fix issue with data not being saved properly in the content column
This commit is contained in:
2022-04-23 18:36:50 +01:00
committed by GitHub
parent 98b3a95fad
commit 4a1ffe122e

View File

@@ -646,7 +646,7 @@ class Cart
$this->getConnection()->table($this->getTableName())->insert([ $this->getConnection()->table($this->getTableName())->insert([
'identifier' => $identifier, 'identifier' => $identifier,
'instance' => $instance, 'instance' => $instance,
'content' => serialize($content), 'content' => json_encode(serialize($content)),
'created_at' => $this->createdAt ?: Carbon::now(), 'created_at' => $this->createdAt ?: Carbon::now(),
'updated_at' => Carbon::now(), 'updated_at' => Carbon::now(),
]); ]);
@@ -676,7 +676,7 @@ class Cart
$stored = $this->getConnection()->table($this->getTableName()) $stored = $this->getConnection()->table($this->getTableName())
->where(['identifier'=> $identifier, 'instance' => $currentInstance])->first(); ->where(['identifier'=> $identifier, 'instance' => $currentInstance])->first();
$storedContent = unserialize(data_get($stored, 'content')); $storedContent = unserialize(json_decode(data_get($stored, 'content')));
$this->instance(data_get($stored, 'instance')); $this->instance(data_get($stored, 'instance'));
@@ -741,7 +741,7 @@ class Cart
$stored = $this->getConnection()->table($this->getTableName()) $stored = $this->getConnection()->table($this->getTableName())
->where(['identifier'=> $identifier, 'instance'=> $instance])->first(); ->where(['identifier'=> $identifier, 'instance'=> $instance])->first();
$storedContent = unserialize($stored->content); $storedContent = unserialize(json_decode($stored->content));
foreach ($storedContent as $cartItem) { foreach ($storedContent as $cartItem) {
$this->addCartItem($cartItem, $keepDiscount, $keepTax, $dispatchAdd); $this->addCartItem($cartItem, $keepDiscount, $keepTax, $dispatchAdd);