diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index e9e71b41c4a..cdf8e470a00 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -233,72 +233,72 @@ class ProductCombination } } - /** - * Return the product id of the parent product of a variant product (Get fk_product_parent by fk_product_child) - * - * @param int $fk_child Product row id - * @return int >0 if OK, 0 if product is not a variant, <0 if KO - */ - public function getFkProductParentByFkProductChild($fk_child) - { - $sql = "SELECT fk_product_parent FROM ".MAIN_DB_PREFIX."product_attribute_combination"; - $sql .= " WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').") LIMIT 1"; + /** + * Return the product id of the parent product of a variant product (Get fk_product_parent by fk_product_child) + * + * @param int $fk_child Product row id + * @return int >0 if OK, 0 if product is not a variant, <0 if KO + */ + public function getFkProductParentByFkProductChild($fk_child) + { + $sql = "SELECT fk_product_parent FROM ".MAIN_DB_PREFIX."product_attribute_combination"; + $sql .= " WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').") LIMIT 1"; - $query = $this->db->query($sql); + $query = $this->db->query($sql); - if (!$query) { - return -1; - } + if (!$query) { + return -1; + } - if (!$this->db->num_rows($query)) { - return 0; - } + if (!$this->db->num_rows($query)) { + return 0; + } - $row = $this->db->fetch_object($query); + $row = $this->db->fetch_object($query); - return (int) $row->fk_product_parent; - } + return (int) $row->fk_product_parent; + } - /** - * Retrieves all product combinations by the child product row id - * - * @param int $fk_child Product row id - * @param int $donotloadpricelevel Avoid loading price impact for each level. If PRODUIT_MULTIPRICES is not set, this has no effect. - * @return int|ProductCombination[] <0 KO - */ - public function fetchAllByFkProductChild($fk_child, $donotloadpricelevel = 0) - { - global $conf; + /** + * Retrieves all product combinations by the child product row id + * + * @param int $fk_child Product row id + * @param int $donotloadpricelevel Avoid loading price impact for each level. If PRODUIT_MULTIPRICES is not set, this has no effect. + * @return int|ProductCombination[] <0 KO + */ + public function fetchAllByFkProductChild($fk_child, $donotloadpricelevel = 0) + { + global $conf; - $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight, variation_ref_ext FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').")"; + $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight, variation_ref_ext FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').")"; - $query = $this->db->query($sql); + $query = $this->db->query($sql); - if (!$query) { - return -1; - } + if (!$query) { + return -1; + } - $return = array(); + $return = array(); - while ($result = $this->db->fetch_object($query)) { - $tmp = new ProductCombination($this->db); - $tmp->id = $result->rowid; - $tmp->fk_product_parent = $result->fk_product_parent; - $tmp->fk_product_child = $result->fk_product_child; - $tmp->variation_price = $result->variation_price; - $tmp->variation_price_percentage = $result->variation_price_percentage; - $tmp->variation_weight = $result->variation_weight; - $tmp->variation_ref_ext = $result->variation_ref_ext; + while ($result = $this->db->fetch_object($query)) { + $tmp = new ProductCombination($this->db); + $tmp->id = $result->rowid; + $tmp->fk_product_parent = $result->fk_product_parent; + $tmp->fk_product_child = $result->fk_product_child; + $tmp->variation_price = $result->variation_price; + $tmp->variation_price_percentage = $result->variation_price_percentage; + $tmp->variation_weight = $result->variation_weight; + $tmp->variation_ref_ext = $result->variation_ref_ext; - if (empty($donotloadpricelevel) && !empty($conf->global->PRODUIT_MULTIPRICES)) { - $tmp->fetchCombinationPriceLevels(); - } + if (empty($donotloadpricelevel) && !empty($conf->global->PRODUIT_MULTIPRICES)) { + $tmp->fetchCombinationPriceLevels(); + } - $return[] = $tmp; - } + $return[] = $tmp; + } - return $return; - } + return $return; + } /** * Retrieves all product combinations by the product parent row id