Post by riwakawebsitedesigns » Sun Feb 01, 2015 1:06 am

Hello I have notice when learning way open cart 2 code is there seems to be a lot of inserts where should be updates. Like for example in model setting editSetting you have a delete and insert. If it is a edit it should be a update. I have notice a lot of that on other models. I do not know why it is done this way

Can some one explain why?

Its makes more sense to be a UPDATE rather than INSERT INTO

Code: Select all

public function editSetting($code, $data, $store_id = 0) {
		$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");

		foreach ($data as $key => $value) {
			if (substr($key, 0, strlen($code)) == $code) {
				if (!is_array($value)) {
					$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape($value) . "'");
				} else {
					$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape(serialize($value)) . "', serialized = '1'");
				}
			}
		}
	}


Posts

Joined
Fri Dec 20, 2013 11:05 am
Who is online

Users browsing this forum: No registered users and 3 guests