From fd989230a4b439c90b3e5b88bf8d7cd5fda209f2 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Thu, 18 Oct 2018 09:09:42 +0200 Subject: [PATCH 1/6] New: works with variants: -Child label change if parent changes --- htdocs/variants/class/ProductCombination.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 8908bfa4d2d..77acc80483c 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -330,6 +330,7 @@ class ProductCombination $child->price_autogen = $parent->price_autogen; $child->weight = $parent->weight + $this->variation_weight; $child->weight_units = $parent->weight_units; + $child->label = $parent->label; if ($child->update($child->id, $user) > 0) { From 6c76f9517f259c14a4dc89121b846aabed2c2dbf Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Thu, 18 Oct 2018 10:26:21 +0200 Subject: [PATCH 2/6] New: works with variants: -Child label with combination labels --- .../class/ProductCombination.class.php | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 77acc80483c..5385664abd4 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -330,7 +330,8 @@ class ProductCombination $child->price_autogen = $parent->price_autogen; $child->weight = $parent->weight + $this->variation_weight; $child->weight_units = $parent->weight_units; - $child->label = $parent->label; + $varlabel = $this->getLabelOfCombination($this->fk_product_child); + $child->label = $parent->label.$varlabel; if ($child->update($child->id, $user) > 0) { @@ -683,4 +684,39 @@ WHERE c.fk_product_parent = ".(int) $productid." AND p.tosell = 1"; return 1; } + + /** + * Return label for combinations + * @param int $prod_child id of child + * @return string combination label + */ + public function getLabelOfCombination($prod_child) + { + $label = ''; + $sql = 'SELECT pav.value AS label'; + $sql.= ' FROM llx_product_attribute_combination pac'; + $sql.= ' INNER JOIN llx_product_attribute_combination2val pac2v ON pac2v.fk_prod_combination=pac.rowid'; + $sql.= ' INNER JOIN llx_product_attribute_value pav ON pav.rowid=pac2v.fk_prod_attr_val'; + $sql.= ' WHERE pac.fk_product_child='.$prod_child; + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + $i = 0; + + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + + if ($obj->label) + { + $label.=' '.$obj->label; + } + $i++; + } + + } + return $label; + } } From c588f5e6c09ee98d586818dcdfe8f4bfae8599a6 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Thu, 18 Oct 2018 10:55:27 +0200 Subject: [PATCH 3/6] New: works with variants: -Child label with combination labels --- htdocs/variants/class/ProductCombination.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 5385664abd4..130b18dafc5 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -694,9 +694,9 @@ WHERE c.fk_product_parent = ".(int) $productid." AND p.tosell = 1"; { $label = ''; $sql = 'SELECT pav.value AS label'; - $sql.= ' FROM llx_product_attribute_combination pac'; - $sql.= ' INNER JOIN llx_product_attribute_combination2val pac2v ON pac2v.fk_prod_combination=pac.rowid'; - $sql.= ' INNER JOIN llx_product_attribute_value pav ON pav.rowid=pac2v.fk_prod_attr_val'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'product_attribute_combination pac'; + $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'product_attribute_combination2val pac2v ON pac2v.fk_prod_combination=pac.rowid'; + $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'product_attribute_value pav ON pav.rowid=pac2v.fk_prod_attr_val'; $sql.= ' WHERE pac.fk_product_child='.$prod_child; $resql = $this->db->query($sql); From 52ad5c5565a8b3eabb0e253d26fc2deec48a6dce Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Thu, 18 Oct 2018 12:21:39 +0200 Subject: [PATCH 4/6] New: works with variants: -To edit child price and weight impacts better to see in tab the father price and weight --- htdocs/variants/combinations.php | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php index 848e5ee70fe..fb23921be25 100644 --- a/htdocs/variants/combinations.php +++ b/htdocs/variants/combinations.php @@ -318,6 +318,66 @@ if (! empty($id) || ! empty($ref)) dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref', '', '', '', 0, '', '', 1); + print '
'; + + print '
'; + print ''; + + // TVA + print ''; + + // Price + print ''; + + // Price minimum + print ''; + + // Weight + print '\n"; + + + + + print "
' . $langs->trans("DefaultTaxRate") . ''; + + $positiverates=''; + if (price2num($object->tva_tx)) $positiverates.=($positiverates?'/':'').price2num($object->tva_tx); + if (price2num($object->localtax1_type)) $positiverates.=($positiverates?'/':'').price2num($object->localtax1_tx); + if (price2num($object->localtax2_type)) $positiverates.=($positiverates?'/':'').price2num($object->localtax2_tx); + if (empty($positiverates)) $positiverates='0'; + echo vatrate($positiverates.($object->default_vat_code?' ('.$object->default_vat_code.')':''), '%', $object->tva_npr); + /* + if ($object->default_vat_code) + { + print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; + } + else print vatrate($object->tva_tx, true, $object->tva_npr, true);*/ + print '
' . $langs->trans("SellingPrice") . ''; + if ($object->price_base_type == 'TTC') { + print price($object->price_ttc) . ' ' . $langs->trans($object->price_base_type); + } else { + print price($object->price) . ' ' . $langs->trans($object->price_base_type); + } + print '
' . $langs->trans("MinPrice") . ''; + if ($object->price_base_type == 'TTC') { + print price($object->price_min_ttc) . ' ' . $langs->trans($object->price_base_type); + } else { + print price($object->price_min) . ' ' . $langs->trans($object->price_base_type); + } + print '
'.$langs->trans("Weight").''; + if ($object->weight != '') + { + print $object->weight." ".measuring_units_string($object->weight_units,"weight"); + } + else + { + print ' '; + } + print "
\n"; + + print '
'; + print '
'; + dol_fiche_end(); From 1714bce8a1fb67b1175e7ef52e45649bce5993a2 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 19 Oct 2018 08:53:01 +0200 Subject: [PATCH 5/6] New: works with variants: - Better function name --- htdocs/variants/class/ProductCombination.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 130b18dafc5..c2e378d045d 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -330,7 +330,7 @@ class ProductCombination $child->price_autogen = $parent->price_autogen; $child->weight = $parent->weight + $this->variation_weight; $child->weight_units = $parent->weight_units; - $varlabel = $this->getLabelOfCombination($this->fk_product_child); + $varlabel = $this->getCombinationLabel($this->fk_product_child); $child->label = $parent->label.$varlabel; if ($child->update($child->id, $user) > 0) { @@ -688,9 +688,9 @@ WHERE c.fk_product_parent = ".(int) $productid." AND p.tosell = 1"; /** * Return label for combinations * @param int $prod_child id of child - * @return string combination label + * @return string combination label */ - public function getLabelOfCombination($prod_child) + public function getCombinationLabel($prod_child) { $label = ''; $sql = 'SELECT pav.value AS label'; From 34118bcf200100a63e45853b8349d56d26f33eba Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 19 Oct 2018 12:02:14 +0200 Subject: [PATCH 6/6] New: works with variants: - Multiprices compatibility --- .../class/ProductCombination.class.php | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index c2e378d045d..a0aed832eac 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -340,14 +340,33 @@ class ProductCombination // MultiPrix if (! empty($conf->global->PRODUIT_MULTIPRICES)) { - $new_type = $parent->multiprices_base_type[1]; - $new_min_price = $parent->multiprices_min[1]; - $new_psq = $parent->multiprices_recuperableonly[1]; + for ($i=1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) + { + if ($parent->multiprices[$i] != '') { + $new_type = $parent->multiprices_base_type[$i]; + $new_min_price = $parent->multiprices_min[$i]; + if ($parent->prices_by_qty_list[$i]) { + $new_psq = 1; + } else { + $new_psq = 0; + } - if ($new_type == 'TTC') { - $new_price = $parent->multiprices_ttc[1]; - } else { - $new_price = $parent->multiprices[1]; + if ($new_type == 'TTC') { + $new_price = $parent->multiprices_ttc[$i]; + } else { + $new_price = $parent->multiprices[$i]; + } + + if ($this->variation_price_percentage) { + if ($new_price != 0) { + $new_price *= 1 + ($this->variation_price / 100); + } + } else { + $new_price += $this->variation_price; + } + + $child->updatePrice($new_price, $new_type, $user, $new_vat, $new_min_price, $i, $new_npr, $new_psq); + } } } else { $new_type = $parent->price_base_type; @@ -359,15 +378,17 @@ class ProductCombination } else { $new_price = $parent->price; } - } - if ($this->variation_price_percentage) { - $new_price *= 1 + ($this->variation_price/100); - } else { - $new_price += $this->variation_price; - } + if ($this->variation_price_percentage) { + if ($new_price != 0) { + $new_price *= 1 + ($this->variation_price / 100); + } + } else { + $new_price += $this->variation_price; + } - $child->updatePrice($new_price, $new_type, $user, $new_vat, $new_min_price, 1, $new_npr, $new_psq); + $child->updatePrice($new_price, $new_type, $user, $new_vat, $new_min_price, 1, $new_npr, $new_psq); + } $this->db->commit();