Clean code

This commit is contained in:
Laurent Destailleur 2021-11-07 18:14:49 +01:00
parent 5d4cf586d6
commit f5edd25f6d

View File

@ -1061,37 +1061,33 @@ class ProductCombinationLevel
*/
public function fetchAll($fk_product_attribute_combination, $fk_price_level = 0)
{
$result = array();
$sql = "SELECT rowid, fk_product_attribute_combination, fk_price_level, variation_price, variation_price_percentage";
$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " WHERE fk_product_attribute_combination = ".intval($fk_product_attribute_combination);
if (!empty($fk_price_level)) {
$sql .= ' AND fk_price_level = '.intval($fk_price_level);
}
$combination_price_levels = $this->db->getRows($sql);
if (!is_array($combination_price_levels)) {
return -1;
}
$result = array();
if (!empty($combination_price_levels)) {
// For more simple usage set level as array key
foreach ($combination_price_levels as $k => $row) {
$productCombinationLevel = new ProductCombinationLevel($this->db);
$productCombinationLevel->fetchFormObj($row);
$result[$row->fk_price_level] = $productCombinationLevel;
$res = $this->db->query($sql);
if ($res) {
if ($this->db->num_rows($res) > 0) {
while ($obj = $this->db->fetch_object($res)) {
$productCombinationLevel = new ProductCombinationLevel($this->db);
$productCombinationLevel->fetchFormObj($obj);
$result[$obj->fk_price_level] = $productCombinationLevel;
}
}
} else {
return -1;
}
return $result;
}
/**
* assign vars form an stdclass like sql obj
* Assign vars form an stdclass like sql obj
*
* @param int $obj Object resultset
* @return int <0 KO, >0 OK