Update ProductCombination.class.php

This commit is contained in:
Cédric 2020-09-17 12:37:20 +02:00 committed by GitHub
parent 67b565df6b
commit 0d20b6645d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -234,15 +234,18 @@ class ProductCombination
} }
/** /**
* Return the product id of the parent product of a variant product (Get fk_product_parent by fk_product_child) * Retrieves information of a variant product and ID of its parent product.
* *
* @param int $fk_child Product row id * @param int $productid Product ID of variant
* @return int >0 if OK, 0 if product is not a variant, <0 if KO * @param int $donotloadpricelevel Avoid loading price impact for each level. If PRODUIT_MULTIPRICES is not set, this has no effect.
* @return int <0 if KO, 0 if product ID is not ID of a variant product (so parent not found), >0 if OK (ID of parent)
*/ */
public function getFkProductParentByFkProductChild($fk_child) public function fetchByFkProductChild($productid, $donotloadpricelevel = 0)
{ {
$sql = "SELECT fk_product_parent FROM ".MAIN_DB_PREFIX."product_attribute_combination"; global $conf;
$sql .= " WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').") LIMIT 1";
$sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight";
$sql .= " FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".((int) $productid)." AND entity IN (".getEntity('product').")";
$query = $this->db->query($sql); $query = $this->db->query($sql);
@ -254,50 +257,20 @@ class ProductCombination
return 0; return 0;
} }
$row = $this->db->fetch_object($query); $result = $this->db->fetch_object($query);
return (int) $row->fk_product_parent; $this->id = $result->rowid;
} $this->fk_product_parent = $result->fk_product_parent;
$this->fk_product_child = $result->fk_product_child;
/** $this->variation_price = $result->variation_price;
* Retrieves all product combinations by the child product row id $this->variation_price_percentage = $result->variation_price_percentage;
* $this->variation_weight = $result->variation_weight;
* @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').")";
$query = $this->db->query($sql);
if (!$query) {
return -1;
}
$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;
if (empty($donotloadpricelevel) && !empty($conf->global->PRODUIT_MULTIPRICES)) { if (empty($donotloadpricelevel) && !empty($conf->global->PRODUIT_MULTIPRICES)) {
$tmp->fetchCombinationPriceLevels(); $this->fetchCombinationPriceLevels();
} }
$return[] = $tmp; return (int) $this->fk_product_parent;
}
return $return;
} }
/** /**