Skip to content
Snippets Groups Projects
Commit ca6fd04a authored by Regis Houssin's avatar Regis Houssin
Browse files

Fix: uniformize code

parent ba32176b
No related branches found
No related tags found
No related merge requests found
...@@ -545,6 +545,7 @@ class Product extends CommonObject ...@@ -545,6 +545,7 @@ class Product extends CommonObject
function setMultiLangs() function setMultiLangs()
{ {
global $langs; global $langs;
$langs_available = $langs->get_available_languages(); $langs_available = $langs->get_available_languages();
$current_lang = $langs->getDefaultLang(); $current_lang = $langs->getDefaultLang();
...@@ -609,6 +610,7 @@ class Product extends CommonObject ...@@ -609,6 +610,7 @@ class Product extends CommonObject
function getMultiLangs($langue='') function getMultiLangs($langue='')
{ {
global $langs; global $langs;
$langs_available = $langs->get_available_languages(); $langs_available = $langs->get_available_languages();
if ( $langue != '') if ( $langue != '')
...@@ -1533,45 +1535,44 @@ class Product extends CommonObject ...@@ -1533,45 +1535,44 @@ class Product extends CommonObject
} }
/** /**
* \brief retire le lien entre un sousproduit et un produit/service * \brief Retire le lien entre un sousproduit et un produit/service
* \param id_pere Id du produit auquel ne sera plus li le produit li * \param fk_parent Id du produit auquel ne sera plus lie le produit lie
* \param id_fils Id du produit ne plus li * \param fk_child Id du produit a ne plus lie
* \return int < 0 si erreur, > 0 si ok * \return int < 0 si erreur, > 0 si ok
*/ */
function del_sousproduit($id_pere, $id_fils) function del_sousproduit($fk_parent, $fk_child)
{ {
$sql = 'delete from '.MAIN_DB_PREFIX.'product_association'; $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association";
$sql .= ' WHERE fk_product_pere = "'.$id_pere.'" and fk_product_fils = "'.$id_fils.'"'; $sql.= " WHERE fk_product_pere = '".$fk_parent."'";
$sql.= " AND fk_product_fils = '".$fk_child."'";
if (! $this->db->query($sql)) if (! $this->db->query($sql))
{ {
dol_print_error($this->db); dol_print_error($this->db);
return -1; return -1;
} }
else
return 1; return 1;
} }
/** /**
* \brief retire le lien entre un sousproduit et un produit/service * \brief Verifie si c'est un sous-produit
* \param id_pere Id du produit auquel ne sera plus li� le produit li * \param fk_parent Id du produit auquel le produit est lie
* \param id_fils Id du produit � ne plus li * \param fk_child Id du produit lie
* \return int < 0 si erreur, > 0 si ok * \return int < 0 si erreur, > 0 si ok
*/ */
function is_sousproduit($id_pere, $id_fils) function is_sousproduit($fk_parent, $fk_child)
{
$sql = 'select fk_product_pere,qty from '.MAIN_DB_PREFIX.'product_association';
$sql .= ' WHERE fk_product_pere = "'.$id_pere.'" and fk_product_fils = "'.$id_fils.'"';
if (! $this->db->query($sql))
{
dol_print_error($this->db);
return -1;
}
else
{ {
$sql = "SELECT fk_product_pere, qty";
$sql.= " FROM ".MAIN_DB_PREFIX."product_association";
$sql.= " WHERE fk_product_pere = '".$fk_parent."'";
$sql.= " AND fk_product_fils = '".$fk_child."'";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
if($num > 0) if($num > 0)
{ {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
...@@ -1580,9 +1581,15 @@ class Product extends CommonObject ...@@ -1580,9 +1581,15 @@ class Product extends CommonObject
return true; return true;
} }
else else
{
return false; return false;
} }
} }
else
{
dol_print_error($this->db);
return -1;
}
} }
/** /**
...@@ -1594,8 +1601,9 @@ class Product extends CommonObject ...@@ -1594,8 +1601,9 @@ class Product extends CommonObject
$this->subproducts_id = array(); $this->subproducts_id = array();
$i = 0; $i = 0;
$sql = "SELECT fk_product_subproduct FROM ".MAIN_DB_PREFIX."product_subproduct"; $sql = "SELECT fk_product_subproduct";
$sql .= " WHERE fk_product=$this->id;"; $sql.= " FROM ".MAIN_DB_PREFIX."product_subproduct";
$sql.= " WHERE fk_product = ".$this->id;
if ($result = $this->db->query($sql)) if ($result = $this->db->query($sql))
{ {
...@@ -1616,7 +1624,7 @@ class Product extends CommonObject ...@@ -1616,7 +1624,7 @@ class Product extends CommonObject
/** /**
* \brief Lie un sous produit au produit/service * \brief Lie un sous produit au produit/service
* \param id_sub Id du produit lier * \param id_sub Id du produit a lier
* \return int < 0 si erreur, > 0 si ok * \return int < 0 si erreur, > 0 si ok
*/ */
function add_subproduct($id_sub) function add_subproduct($id_sub)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment