0

I'm customizing OpenCart3. For some reasons I have to save contents of cart table in a session, then re-insert them back, but while adding session data using $this->cart->add(...) extra codes are added to options which I don't know how to prevent.

foreach($this->session->data['in_cart']['rows'] as $key => $row){
    if ($row['store_id'] != $this->session->data['cart_store_id']) {
        $this->cart->add($row['product_id'], $row['quantity'], $row['option'],  $row['recurring_id'], $row['store_id']);
    }
}

Originally options should be saved like:

{"90":["263"],"89":["260"]}

But they get saved as:

"{\"142\":[\"494\"],\"141\":[\"492\"]}"

Thanks for any kind help, but not down voting.

Kardo
  • 1,658
  • 4
  • 32
  • 52

1 Answers1

0

I fixed the problem by decoding the saved string into array, then adding it:

foreach($this->session->data['in_cart_total_products_all_stores']['rows'] as $key => $row){
    if ($row['store_id'] != $this->session->data['cart_store_id']) {
        $options = json_decode($row['option']);
        $this->cart->add($row['product_id'], $row['quantity'], $options,  $row['recurring_id'], $row['store_id']);
    }
}
Kardo
  • 1,658
  • 4
  • 32
  • 52