From ec58ee940a8de664875d826f2c9ac3eca4b612d5 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:09:48 +0100 Subject: [PATCH 1/3] FIX: product variants copy: also copy multiprice variations --- .../class/ProductCombination.class.php | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 42e3bdc1530..fa642dc2765 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -702,16 +702,16 @@ class ProductCombination * [...] * ) * - * @param User $user Object user - * @param Product $product Parent product - * @param array $combinations Attribute and value combinations. - * @param array $variations Price and weight variations - * @param bool|array $price_var_percent Is the price variation a relative variation? - * @param bool|float $forced_pricevar If the price variation is forced - * @param bool|float $forced_weightvar If the weight variation is forced - * @param bool|string $forced_refvar If the reference is forced - * @param string $ref_ext External reference - * @return int <0 KO, >0 OK + * @param User $user Object user + * @param Product $product Parent product + * @param array $combinations Attribute and value combinations. + * @param array $variations Price and weight variations + * @param bool|array $price_var_percent Is the price variation a relative variation? + * @param bool|float|array $forced_pricevar If the price variation is forced + * @param bool|float $forced_weightvar If the weight variation is forced + * @param bool|string $forced_refvar If the reference is forced + * @param string $ref_ext External reference + * @return int <0 KO, >0 OK */ public function createProductCombination(User $user, Product $product, array $combinations, array $variations, $price_var_percent = false, $forced_pricevar = false, $forced_weightvar = false, $forced_refvar = false, $ref_ext = '') { @@ -752,8 +752,8 @@ class ProductCombination $price_impact = $forced_pricevar; } - if (!array($price_var_percent)) { - $price_var_percent[1] = (float) $price_var_percent; + if (!is_array($price_var_percent)) { + $price_var_percent = array(1 => (float) $price_var_percent); } $newcomb = new ProductCombination($this->db); @@ -840,12 +840,7 @@ class ProductCombination $productCombinationLevel->fk_product_attribute_combination = $newcomb->id; $productCombinationLevel->fk_price_level = $i; $productCombinationLevel->variation_price = $price_impact[$i]; - - if (is_array($price_var_percent)) { - $productCombinationLevel->variation_price_percentage = (empty($price_var_percent[$i]) ? false : $price_var_percent[$i]); - } else { - $productCombinationLevel->variation_price_percentage = $price_var_percent; - } + $productCombinationLevel->variation_price_percentage = (empty($price_var_percent[$i]) ? false : $price_var_percent[$i]); $newcomb->combination_price_levels[$i] = $productCombinationLevel; } @@ -955,13 +950,26 @@ class ProductCombination $variations[$tmp_pc2v->fk_prod_attr] = $tmp_pc2v->fk_prod_attr_val; } + $variation_price_percentage = $combination->variation_price_percentage; + $variation_price = $combination->variation_price; + + if (getDolGlobalInt('PRODUIT_MULTIPRICES') && getDolGlobalInt('PRODUIT_MULTIPRICES_LIMIT') > 1) { + $variation_price_percentage = [ ]; + $variation_price = [ ]; + + foreach ($combination->combination_price_levels as $productCombinationLevel) { + $variation_price_percentage[$productCombinationLevel->fk_price_level] = $productCombinationLevel->variation_price_percentage; + $variation_price[$productCombinationLevel->fk_price_level] = $productCombinationLevel->variation_price; + } + } + if ($this->createProductCombination( $user, $destProduct, $variations, array(), - $combination->variation_price_percentage, - $combination->variation_price, + $variation_price_percentage, + $variation_price, $combination->variation_weight ) < 0) { return -1; From 3ef6299c839aa0e1ae473e65942a6ace54dc6644 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:20:57 +0100 Subject: [PATCH 2/3] FIX: phpcs --- htdocs/variants/class/ProductCombination.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index fa642dc2765..e41325f6efb 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -950,8 +950,8 @@ class ProductCombination $variations[$tmp_pc2v->fk_prod_attr] = $tmp_pc2v->fk_prod_attr_val; } - $variation_price_percentage = $combination->variation_price_percentage; - $variation_price = $combination->variation_price; + $variation_price_percentage = $combination->variation_price_percentage; + $variation_price = $combination->variation_price; if (getDolGlobalInt('PRODUIT_MULTIPRICES') && getDolGlobalInt('PRODUIT_MULTIPRICES_LIMIT') > 1) { $variation_price_percentage = [ ]; From ef564caf28bafb827aec71697e58f2a0e4302fca Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:37:30 +0100 Subject: [PATCH 3/3] FIX: qual --- htdocs/variants/class/ProductCombination.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index e41325f6efb..163ea7be5bd 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -753,7 +753,7 @@ class ProductCombination } if (!is_array($price_var_percent)) { - $price_var_percent = array(1 => (float) $price_var_percent); + $price_var_percent = array(1 => (bool) $price_var_percent); } $newcomb = new ProductCombination($this->db); @@ -840,7 +840,7 @@ class ProductCombination $productCombinationLevel->fk_product_attribute_combination = $newcomb->id; $productCombinationLevel->fk_price_level = $i; $productCombinationLevel->variation_price = $price_impact[$i]; - $productCombinationLevel->variation_price_percentage = (empty($price_var_percent[$i]) ? false : $price_var_percent[$i]); + $productCombinationLevel->variation_price_percentage = $price_var_percent[$i]; $newcomb->combination_price_levels[$i] = $productCombinationLevel; }