From cefd287668421467d9fbd69ae37d388121d1185d Mon Sep 17 00:00:00 2001 From: objecttothis <17935339+objecttothis@users.noreply.github.com> Date: Mon, 9 Mar 2020 15:11:33 +0400 Subject: [PATCH] Resolve bug not updating attributes correctly Prior to this fix, if the attribute was of DECIMAL or DATE type and the action was an UPDATE, then it would try to update the attribute_value, not the corresponding attribute_decimal or attribute_date. --- application/models/Attribute.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/application/models/Attribute.php b/application/models/Attribute.php index cc595b9a1..d0905f6e8 100644 --- a/application/models/Attribute.php +++ b/application/models/Attribute.php @@ -530,7 +530,7 @@ class Attribute extends CI_Model if(empty($attribute_id) || empty($item_id)) { - if($definition_type == TEXT || $definition_type == DROPDOWN) + if(in_array($definition_type, [TEXT, DROPDOWN], TRUE)) { $attribute_id = $this->value_exists($attribute_value); @@ -558,7 +558,19 @@ class Attribute extends CI_Model else { $this->db->where('attribute_id', $attribute_id); - $this->db->update('attribute_values', array('attribute_value' => $attribute_value)); + + if(in_array($definition_type, [TEXT, DROPDOWN], TRUE)) + { + $this->db->update('attribute_values', array('attribute_value' => $attribute_value)); + } + else if($definition_type == DECIMAL) + { + $this->db->update('attribute_values', array('attribute_decimal' => $attribute_value)); + } + else + { + $this->db->update('attribute_values', array('attribute_date' => date('Y-m-d', strtotime($attribute_value)))); + } } $this->db->trans_complete();