diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index d65f9120c09..aaf3ae0bb9d 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -102,10 +102,13 @@ function product_prepare_head($object) $prodcomb = new ProductCombination($db); - if ($prodcomb->fetchByFkProductChild($object->id) == -1) { + if ($prodcomb->fetchByFkProductChild($object->id) == -1) + { $head[$h][0] = DOL_URL_ROOT."/variants/combinations.php?id=".$object->id; $head[$h][1] = $langs->trans('ProductCombinations'); $head[$h][2] = 'combinations'; + $nbVariant = $prodcomb->countNbOfCombinationForFkProductParent($object->id); + if ($nbVariant > 0) $head[$h][1].= ' '.$nbVariant.''; } $h++; diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 457354813e8..9897facb0bb 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -288,7 +288,8 @@ DoNotRemovePreviousCombinations=Do not remove previous variants UsePercentageVariations=Use percentage variations PercentageVariation=Percentage variation ErrorDeletingGeneratedProducts=There was an error while trying to delete existing product variants -NbProducts=No. of products +NbOfDifferentValues=Nb of different values +NbProducts=Nb. of products ParentProduct=Parent product HideChildProducts=Hide child products ConfirmCloneProductCombinations=Would you like to copy all the product variant to the product with the given reference? diff --git a/htdocs/variants/card.php b/htdocs/variants/card.php index a80b6b982e3..ae921114d6b 100644 --- a/htdocs/variants/card.php +++ b/htdocs/variants/card.php @@ -36,6 +36,7 @@ if ($prodattr->fetch($id) < 1) { exit(); } + /* * Actions */ @@ -110,6 +111,11 @@ if ($confirm == 'yes') { } } + +/* + * View + */ + $langs->load('products'); $title = $langs->trans('ProductAttributeName', dol_htmlentities($prodattr->label)); diff --git a/htdocs/variants/class/ProductAttribute.class.php b/htdocs/variants/class/ProductAttribute.class.php index e9027444e5c..bbfc655a0bd 100644 --- a/htdocs/variants/class/ProductAttribute.class.php +++ b/htdocs/variants/class/ProductAttribute.class.php @@ -73,9 +73,7 @@ class ProductAttribute return -1; } - require_once DOL_DOCUMENT_ROOT.'/variants/lib/product_variants.lib.php'; - - $sql = "SELECT rowid, ref, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE rowid = ".(int) $id." AND entity IN (".getProductEntities($this->db).")"; + $sql = "SELECT rowid, ref, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product', 1).")"; $query = $this->db->query($sql); @@ -100,11 +98,9 @@ class ProductAttribute */ public function fetchAll() { - require_once DOL_DOCUMENT_ROOT.'/variants/lib/product_variants.lib.php'; - $return = array(); - $sql = 'SELECT rowid, ref, label, rang FROM '.MAIN_DB_PREFIX."product_attribute WHERE entity IN (".getProductEntities($this->db).')'; + $sql = 'SELECT rowid, ref, label, rang FROM '.MAIN_DB_PREFIX."product_attribute WHERE entity IN (".getEntity('product', 1).')'; $sql .= $this->db->order('rang', 'asc'); $query = $this->db->query($sql); if ($query) @@ -183,6 +179,21 @@ class ProductAttribute return -1; } + /** + * Returns the number of values for this attribute + * + * @return int + */ + public function countChildValues() + { + $sql = "SELECT COUNT(*) count FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE fk_product_attribute = ".(int) $this->id; + + $query = $this->db->query($sql); + $result = $this->db->fetch_object($query); + + return $result->count; + } + /** * Returns the number of products that are using this attribute * @@ -190,10 +201,8 @@ class ProductAttribute */ public function countChildProducts() { - require_once __DIR__.'/../lib/product_variants.lib.php'; - $sql = "SELECT COUNT(*) count FROM ".MAIN_DB_PREFIX."product_attribute_combination2val pac2v - LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac2v.fk_prod_combination = pac.rowid WHERE pac2v.fk_prod_attr = ".(int) $this->id." AND pac.entity IN (".getProductEntities($this->db).")"; + LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac2v.fk_prod_combination = pac.rowid WHERE pac2v.fk_prod_attr = ".(int) $this->id." AND pac.entity IN (".getEntity('product', 1).")"; $query = $this->db->query($sql); @@ -202,6 +211,7 @@ class ProductAttribute return $result->count; } + /** * Reorders the order of the variants. * This is an internal function used by moveLine function diff --git a/htdocs/variants/class/ProductAttributeValue.class.php b/htdocs/variants/class/ProductAttributeValue.class.php index e11f612c26a..399137dca18 100644 --- a/htdocs/variants/class/ProductAttributeValue.class.php +++ b/htdocs/variants/class/ProductAttributeValue.class.php @@ -68,9 +68,7 @@ class ProductAttributeValue */ public function fetch($valueid) { - require_once __DIR__.'/../lib/product_variants.lib.php'; - - $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE rowid = ".(int) $valueid." AND entity IN (".getProductEntities($this->db).")"; + $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE rowid = ".(int) $valueid." AND entity IN (".getEntity('product', 1).")"; $query = $this->db->query($sql); @@ -101,8 +99,6 @@ class ProductAttributeValue */ public function fetchAllByProductAttribute($prodattr_id, $only_used = false) { - require_once __DIR__.'/../lib/product_variants.lib.php'; - $return = array(); $sql = 'SELECT '; diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 240fda0e911..155d92af532 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -86,9 +86,7 @@ class ProductCombination */ public function fetch($rowid) { - require_once __DIR__.'/../lib/product_variants.lib.php'; - - $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE rowid = ".(int) $rowid." AND entity IN (".getProductEntities($this->db).")"; + $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE rowid = ".(int) $rowid." AND entity IN (".getEntity('product', 1).")"; $query = $this->db->query($sql); @@ -120,9 +118,7 @@ class ProductCombination */ public function fetchByFkProductChild($fk_child) { - require_once __DIR__.'/../lib/product_variants.lib.php'; - - $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getProductEntities($this->db).")"; + $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product', 1).")"; $query = $this->db->query($sql); @@ -154,9 +150,7 @@ class ProductCombination */ public function fetchAllByFkProductParent($fk_product_parent) { - require_once __DIR__.'/../lib/product_variants.lib.php'; - - $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_parent = ".(int) $fk_product_parent." AND entity IN (".getProductEntities($this->db).")"; + $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_parent = ".(int) $fk_product_parent." AND entity IN (".getEntity('product', 1).")"; $query = $this->db->query($sql); @@ -182,6 +176,26 @@ class ProductCombination return $return; } + /** + * Retrieves all product combinations by the product parent row id + * + * @param int $fk_product_parent Id of parent product + * @return int Nb of record + */ + public function countNbOfCombinationForFkProductParent($fk_product_parent) + { + $nb = 0; + $sql = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_parent = ".(int) $fk_product_parent." AND entity IN (".getEntity('product', 1).")"; + + $resql = $this->db->query($sql); + if ($resql) { + $obj = $this->db->fetch_object($resql); + if ($obj) $nb = $obj->nb; + } + + return $nb; + } + /** * Creates a product attribute combination * diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php index 477108f9998..dc1edd01ef0 100644 --- a/htdocs/variants/combinations.php +++ b/htdocs/variants/combinations.php @@ -52,6 +52,7 @@ if ($id > 0 || $ref) $object->fetch($id, $ref); } + /* * Actions */ diff --git a/htdocs/variants/lib/product_variants.lib.php b/htdocs/variants/lib/product_variants.lib.php deleted file mode 100644 index 9ced646cb01..00000000000 --- a/htdocs/variants/lib/product_variants.lib.php +++ /dev/null @@ -1,31 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * Returns the entity of the products. - * @param DoliDB $db Database handler - * @return mixed - */ -function getProductEntities(DoliDB $db) -{ - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - - $product = new Product($db); - - return getEntity($product->element, 1); -} \ No newline at end of file diff --git a/htdocs/variants/list.php b/htdocs/variants/list.php index 6a6d02178e8..7b8855c1c4e 100644 --- a/htdocs/variants/list.php +++ b/htdocs/variants/list.php @@ -18,7 +18,7 @@ require '../main.inc.php'; require DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php'; -$rowid = GETPOST('rowid'); +$id = GETPOST('id'); $action = GETPOST('action'); $object = new ProductAttribute($db); @@ -109,14 +109,16 @@ $forcereloadpage=empty($conf->global->MAIN_FORCE_RELOAD_PAGE)?0:1; trans('Ref') ?> trans('Label') ?> - trans('NbProducts') ?> + trans('NbOfDifferentValues') ?> + trans('NbProducts') ?> $attribute): ?> > ref) ?> label) ?> - countChildProducts() ?> + countChildValues() ?> + countChildProducts() ?>