I am new to opencart, and trying to update Products option "giftmsg", which are added to the cart. I am posting my code here. I am currently facing an error, just quickly after the error cart automatically removes all the items including updated ones.

Opencart version: 2.x
file path: /catalog/controller/checkout/cart.php
Code: Select all
public function edit() {
$this->load->language('checkout/cart');
$json = array();
// Update
if (!empty($this->request->post['quantity'])) {
foreach ($this->request->post['quantity'] as $key => $value) {
$this->cart->update($key, $value);
}
if(!empty($this->request->post['giftmsg'])) {
$product = $this->request->post['giftmsg'];
foreach($product as $item => $value) {
$xItem = unserialize(base64_decode($item));
$xItem['option'][9] = $value;
$xItem = base64_encode(serialize($xItem));
$this->session->data['cart'][$xItem] = 1;///$this->session->data['cart'][$item];
$this->cart->remove($item);
}
}
//die();
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['reward']);
$this->response->redirect($this->url->link('checkout/cart'));
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}