From 2c07886360b14f2e0450c08b231add1be553a60a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 26 Nov 2017 15:08:00 +0100 Subject: [PATCH] Debug module variant --- htdocs/variants/card.php | 28 ++++++++++++++----- .../variants/class/ProductAttribute.class.php | 8 ++++-- .../class/ProductAttributeValue.class.php | 16 ++++++----- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/htdocs/variants/card.php b/htdocs/variants/card.php index c191c1fd4c3..547a82d0f63 100644 --- a/htdocs/variants/card.php +++ b/htdocs/variants/card.php @@ -46,10 +46,10 @@ if ($_POST) { if ($action == 'edit') { - $object->label = $label; $object->ref = $ref; + $object->label = $label; - if ($object->update() < 1) { + if ($object->update($user) < 1) { setEventMessage($langs->trans('CoreErrorMessage'), 'errors'); } else { setEventMessage($langs->trans('RecordSaved')); @@ -61,12 +61,26 @@ if ($_POST) { if ($objectval->fetch($valueid) > 0) { $objectval->ref = $ref; - $objectval->value = GETPOST('value'); + $objectval->value = GETPOST('value','alpha'); - if ($objectval->update() > 0) { - setEventMessage($langs->trans('RecordSaved')); - } else { - setEventMessage($langs->trans('CoreErrorMessage'), 'errors'); + if (empty($objectval->ref)) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors'); + } + if (empty($objectval->value)) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + } + + if (! $error) + { + if ($objectval->update($user) > 0) { + setEventMessage($langs->trans('RecordSaved')); + } else { + setEventMessage($langs->trans('CoreErrorMessage'), 'errors'); + } } } diff --git a/htdocs/variants/class/ProductAttribute.class.php b/htdocs/variants/class/ProductAttribute.class.php index 7995dc89919..03440d0520b 100644 --- a/htdocs/variants/class/ProductAttribute.class.php +++ b/htdocs/variants/class/ProductAttribute.class.php @@ -149,12 +149,14 @@ class ProductAttribute /** * Updates a product attribute * - * @return int <0 KO, >0 OK + * @param User $user Object user + * @return int <0 KO, >0 OK */ - public function update() + public function update(User $user) { //Ref must be uppercase - $this->ref = strtoupper($this->ref); + $this->ref = trim(strtoupper($this->ref)); + $this->label = trim($this->label); $sql = "UPDATE ".MAIN_DB_PREFIX."product_attribute SET ref = '".$this->db->escape($this->ref)."', label = '".$this->db->escape($this->label)."', rang = ".(int) $this->rang." WHERE rowid = ".(int) $this->id; diff --git a/htdocs/variants/class/ProductAttributeValue.class.php b/htdocs/variants/class/ProductAttributeValue.class.php index 02ef86a9222..9c9d9929f46 100644 --- a/htdocs/variants/class/ProductAttributeValue.class.php +++ b/htdocs/variants/class/ProductAttributeValue.class.php @@ -102,11 +102,11 @@ class ProductAttributeValue $return = array(); $sql = 'SELECT '; - + if ($only_used) { $sql .= 'DISTINCT '; } - + $sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value v '; if ($only_used) { @@ -114,9 +114,9 @@ class ProductAttributeValue $sql .= 'LEFT JOIN '.MAIN_DB_PREFIX.'product_attribute_combination c ON c.rowid = c2v.fk_prod_combination '; $sql .= 'LEFT JOIN '.MAIN_DB_PREFIX.'product p ON p.rowid = c.fk_product_child '; } - + $sql .= 'WHERE v.fk_product_attribute = '.(int) $prodattr_id; - + if ($only_used) { $sql .= ' AND c2v.rowid IS NOT NULL AND p.tosell = 1'; } @@ -168,12 +168,14 @@ class ProductAttributeValue /** * Updates a product attribute value * - * @return int + * @param User $user Object user + * @return int <0 if KO, >0 if OK */ - public function update() + public function update(User $user) { //Ref must be uppercase - $this->ref = strtoupper($this->ref); + $this->ref = trim(strtoupper($this->ref)); + $this->value = trim($this->value); $sql = "UPDATE ".MAIN_DB_PREFIX."product_attribute_value SET fk_product_attribute = '".(int) $this->fk_product_attribute."', ref = '".$this->db->escape($this->ref)."',