FIX better fix for compatibility

This commit is contained in:
Regis Houssin 2022-10-08 07:49:02 +02:00
parent 4bb4d2dc64
commit 53502ccd70
4 changed files with 24 additions and 17 deletions

View File

@ -75,12 +75,7 @@ if ($prodattr->fetch($id) < 0) {
$prodattrval = new ProductAttributeValue($db);
$res = $prodattrval->fetchAllByProductAttribute($id);
// Remove db for avoid error with postgresql
foreach ($res as $key => $val) {
unset($res[$key]->db);
}
$res = $prodattrval->fetchAllByProductAttribute($id, false, 1);
if ($res == -1) {
print json_encode(array(

View File

@ -107,9 +107,10 @@ class ProductAttribute extends CommonObject
/**
* Returns an array of all product variants
*
* @return ProductAttribute[]
* @param int $returnonlydata 0: return object, 1: return only data
* @return ProductAttribute[]
*/
public function fetchAll()
public function fetchAll($returnonlydata = 0)
{
$return = array();
@ -118,7 +119,13 @@ class ProductAttribute extends CommonObject
$query = $this->db->query($sql);
if ($query) {
while ($result = $this->db->fetch_object($query)) {
$tmp = new ProductAttribute($this->db);
if (empty($returnonlydata)) {
$tmp = new ProductAttribute($this->db);
} else {
$tmp = new stdClass();
}
$tmp->id = $result->rowid;
$tmp->ref = $result->ref;
$tmp->ref_ext = $result->ref_ext;

View File

@ -99,11 +99,12 @@ class ProductAttributeValue extends CommonObject
/**
* Returns all product attribute values of a product attribute
*
* @param int $prodattr_id Product attribute id
* @param bool $only_used Fetch only used attribute values
* @return ProductAttributeValue[]
* @param int $prodattr_id Product attribute id
* @param bool $only_used Fetch only used attribute values
* @param int $returnonlydata 0: return object, 1: return only data
* @return ProductAttributeValue[]
*/
public function fetchAllByProductAttribute($prodattr_id, $only_used = false)
public function fetchAllByProductAttribute($prodattr_id, $only_used = false, $returnonlydata = 0)
{
$return = array();
@ -130,7 +131,13 @@ class ProductAttributeValue extends CommonObject
$query = $this->db->query($sql);
while ($result = $this->db->fetch_object($query)) {
$tmp = new ProductAttributeValue($this->db);
if (empty($returnonlydata)) {
$tmp = new ProductAttributeValue($this->db);
} else {
$tmp = new stdClass();
}
$tmp->fk_product_attribute = $result->fk_product_attribute;
$tmp->id = $result->rowid;
$tmp->ref = $result->ref;

View File

@ -467,7 +467,7 @@ if (!empty($id) || !empty($ref)) {
}
if ($action == 'add') {
$prodattr_all = $prodattr->fetchAll();
$prodattr_all = $prodattr->fetchAll(1);
if (!$selected) {
$selected = $prodattr_all[key($prodattr_all)]->id;
@ -477,8 +477,6 @@ if (!empty($id) || !empty($ref)) {
foreach ($prodattr_all as $each) {
$prodattr_alljson[$each->id] = $each;
// Remove db for avoid error with postgresql
unset($prodattr_alljson[$each->id]->db);
}
?>