Gestion de la référence vide interdite
This commit is contained in:
parent
7e03483539
commit
935b717c66
@ -69,7 +69,10 @@ class Product
|
|||||||
var $multilangs=array();
|
var $multilangs=array();
|
||||||
|
|
||||||
var $typeprodserv;
|
var $typeprodserv;
|
||||||
|
//! Intitule de l'erreur
|
||||||
var $error;
|
var $error;
|
||||||
|
//! Numero de l'erreur
|
||||||
|
var $errno = 0;
|
||||||
//! Canevas a utiliser si le produit n'est pas un produit generique
|
//! Canevas a utiliser si le produit n'est pas un produit generique
|
||||||
var $canvas;
|
var $canvas;
|
||||||
//! Nombre de piece en commande, non expedie
|
//! Nombre de piece en commande, non expedie
|
||||||
@ -148,73 +151,84 @@ class Product
|
|||||||
|
|
||||||
dolibarr_syslog("Product::Create ref=".$this->ref." Categorie : ".$this->catid);
|
dolibarr_syslog("Product::Create ref=".$this->ref." Categorie : ".$this->catid);
|
||||||
|
|
||||||
$this->db->begin();
|
if (strlen($this->ref) > 0)
|
||||||
|
{
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "SELECT count(*)";
|
$sql = "SELECT count(*)";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."product WHERE ref = '" .$this->ref."'";
|
$sql .= " FROM ".MAIN_DB_PREFIX."product WHERE ref = '" .$this->ref."'";
|
||||||
|
|
||||||
$result = $this->db->query($sql) ;
|
$result = $this->db->query($sql) ;
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$row = $this->db->fetch_array($result);
|
$row = $this->db->fetch_array($result);
|
||||||
if ($row[0] == 0)
|
if ($row[0] == 0)
|
||||||
{
|
{
|
||||||
// Produit non deja existant
|
// Produit non deja existant
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product ";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product ";
|
||||||
$sql.= " (datec, ";
|
$sql.= " (datec, ";
|
||||||
if ($this->ref) $sql.= "ref, ";
|
if ($this->ref) $sql.= "ref, ";
|
||||||
$sql.= "fk_user_author, fk_product_type, price, canvas)";
|
$sql.= "fk_user_author, fk_product_type, price, canvas)";
|
||||||
$sql.= " VALUES (now(), ";
|
$sql.= " VALUES (now(), ";
|
||||||
if ($this->ref) $sql.= "'".$this->ref."', ";
|
if ($this->ref) $sql.= "'".$this->ref."', ";
|
||||||
$sql.= $user->id.", ".$this->type.", '" . $this->price . "','".$this->canvas."')";
|
$sql.= $user->id.", ".$this->type.", '" . $this->price . "','".$this->canvas."')";
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ( $result )
|
if ( $result )
|
||||||
{
|
{
|
||||||
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."product");
|
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."product");
|
||||||
|
|
||||||
if ($id > 0)
|
if ($id > 0)
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->_log_price($user);
|
$this->_log_price($user);
|
||||||
if ( $this->update($id, $user) > 0)
|
if ( $this->update($id, $user) > 0)
|
||||||
{
|
{
|
||||||
if ($this->catid > 0)
|
if ($this->catid > 0)
|
||||||
{
|
{
|
||||||
$cat = new Categorie ($this->db, $this->catid);
|
$cat = new Categorie ($this->db, $this->catid);
|
||||||
$cat->add_product($this);
|
$cat->add_product($this);
|
||||||
}
|
}
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $id;
|
return $id;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->db->rollback();
|
||||||
|
return -5;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$this->db->rollback();
|
|
||||||
return -5;
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
$this->db->rollback();
|
||||||
$this->db->rollback();
|
return -4;
|
||||||
return -4;
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
$this->error=$this->db->error()." - sql=".$sql;
|
||||||
$this->error=$this->db->error()." - sql=".$sql;
|
$this->db->rollback();
|
||||||
$this->db->rollback();
|
return -3;
|
||||||
return -3;
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
// Produit existe deja
|
||||||
// Produit existe deja
|
$this->error=$langs->trans("ErrorProductAlreadyExists", $this->ref);
|
||||||
$this->error=$langs->trans("ErrorProductAlreadyExists");
|
$this->errno = 257;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->error=$this->db->error();
|
$this->error=$this->db->error();
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Produit existe deja
|
||||||
|
$this->error=$langs->trans("ErrorProductBadRefOrLabel");
|
||||||
|
$this->errno = 257;
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2401,5 +2415,9 @@ class Product
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function assign_smarty_values(&$smarty)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user