From 6fda3ac74107b100db8dcc183f9431d0733b9881 Mon Sep 17 00:00:00 2001 From: Andre Cianfarani Date: Wed, 22 Mar 2006 06:24:21 +0000 Subject: [PATCH] debug sousproduits --- htdocs/product.class.php | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/htdocs/product.class.php b/htdocs/product.class.php index c3120f45761..02f866ca061 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -1100,7 +1100,7 @@ class Product function add_sousproduit($id_pere, $id_fils,$qty) { - $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.'"'; if (! $this->db->query($sql)) { @@ -1109,8 +1109,8 @@ class Product } else { - $sql = 'insert into '.MAIN_DB_PREFIX.'product_association(fk_product_pere,fk_product_fils,qty)'; - $sql .= ' VALUES ("'.$id_pere.'","'.$id_fils.'","'.$qty.'")'; + $sql = 'select fk_product_pere from '.MAIN_DB_PREFIX.'product_association'; + $sql .= ' WHERE fk_product_pere = "'.$id_fils.'" and fk_product_fils = "'.$id_pere.'"'; if (! $this->db->query($sql)) { dolibarr_print_error($this->db); @@ -1118,8 +1118,32 @@ class Product } else { - return 1; + $result = $this->db->query($sql) ; + if ($result) + { + $num = $this->db->num_rows($result); + if($num > 0) + { + $this->error="isFatherOfThis"; + return -1; + } + else + { + $sql = 'insert into '.MAIN_DB_PREFIX.'product_association(fk_product_pere,fk_product_fils,qty)'; + $sql .= ' VALUES ("'.$id_pere.'","'.$id_fils.'","'.$qty.'")'; + if (! $this->db->query($sql)) + { + dolibarr_print_error($this->db); + return -1; + } + else + { + return 1; + } + } + } } + } } /**