Debug module variant

This commit is contained in:
Laurent Destailleur 2017-11-26 15:08:00 +01:00
parent 0b470bef80
commit 2c07886360
3 changed files with 35 additions and 17 deletions

View File

@ -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');
}
}
}

View File

@ -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;

View File

@ -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)."',