1

I'm trying to make editing options on the checkout page. Added function by analogy with quantity

    public function update_two($cart_id, $option = array()) {
    $this->db->query("UPDATE " . DB_PREFIX . "cart SET option =  '" . $this->db->escape(json_encode($option)) . "'  WHERE cart_id = '" . (int)$cart_id . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
}

Then there is an error

 Uncaught exception 'Exception' with message 'Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option = '{\"232\":[\"23\"],\"228\":[\"19\"]}' WHERE cart_id = '198' AND custo' at line 1<br />Error No: 1064<br />

UPDATE: line ~ 283

    public function updatetwo($cart_id, $option = array()) {
    $this->db->query("UPDATE " . DB_PREFIX . "cart SET `option` = '" . $this->db->escape(serialize(json_encode($option))) . "' WHERE cart_id = '" . (int)$cart_id . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
}

Line ~ 50 : $options_alt = unserialize($cart['option']); foreach (json_decode($options_alt) as $product_option_id => $value) { If anyone needs - everything works

  • the issue seems to be with the options `array`. try only `json_encode($option)` instead of `$this->db->escape(json_encode($option))`. – Rohit Batra Feb 26 '18 at 04:20
  • Tried it. I get this error again. If instead of adding any other number - the result will be the same – Alexander Kuzin Feb 26 '18 at 12:22
  • try this `$this->db->query("UPDATE " . DB_PREFIX . "cart SET \`option\` = '" . $this->db->escape(serialize($option)) . "' WHERE cart_id = '" . (int)$cart_id . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");` – Rohit Batra Feb 26 '18 at 12:25
  • Thank you so much. Is there a result. ! – Alexander Kuzin Feb 26 '18 at 13:37

0 Answers0