From 4e1f554c15b0368a43fa2eb56fca821801d9cea5 Mon Sep 17 00:00:00 2001 From: John Botella Date: Thu, 13 Aug 2020 11:43:33 +0200 Subject: [PATCH] Fix - add variation price fallback behavior --- .../class/ProductCombination.class.php | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 777cb136b05..0b3b3843867 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -138,6 +138,8 @@ class ProductCombination */ public function fetchCombinationPriceLevels($fk_price_level = 0, $useCache = true) { + global $conf; + // Check cache if(!empty($this->combination_price_levels) && $useCache){ if((!empty($fk_price_level) && isset($this->combination_price_levels[$fk_price_level])) || empty($fk_price_level)){ @@ -154,10 +156,31 @@ class ProductCombination $staticProductCombinationLevel = new ProductCombinationLevel($this->db); $combination_price_levels = $staticProductCombinationLevel->fetchAll($this->id, $fk_price_level); - if (!$combination_price_levels || !is_array($combination_price_levels)) { + if (!is_array($combination_price_levels)) { return -1; } + if(empty($combination_price_levels)){ + + /** + * for auto retrocompatibility with last behavior + */ + $productCombinationLevel = new ProductCombinationLevel($this->db); + $productCombinationLevel->fk_price_level = intval($fk_price_level); + $productCombinationLevel->fk_product_attribute_combination = $this->id; + $productCombinationLevel->variation_price = $this->variation_price; + $productCombinationLevel->variation_price_percentage = $this->variation_price_percentage; + + if($fk_price_level>0){ + $combination_price_levels[$fk_price_level] = $productCombinationLevel; + } + else{ + for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++){ + $combination_price_levels[$i] = $productCombinationLevel; + } + } + } + $this->combination_price_levels = $combination_price_levels; return 1; @@ -1032,17 +1055,19 @@ class ProductCombinationLevel $combination_price_levels = $this->db->getRows($sql); - if (!$combination_price_levels || !is_array($combination_price_levels)) { + if (!is_array($combination_price_levels)) { return -1; } $result = array(); - // For more simple usage set level as array key - foreach($combination_price_levels as $k => $row){ - $productCombinationLevel = new ProductCombinationLevel($this->db); - $productCombinationLevel->fetchFormObj($row); - $result[$row->fk_price_level] = $productCombinationLevel; + if(!empty($combination_price_levels)) { + // For more simple usage set level as array key + foreach($combination_price_levels as $k => $row){ + $productCombinationLevel = new ProductCombinationLevel($this->db); + $productCombinationLevel->fetchFormObj($row); + $result[$row->fk_price_level] = $productCombinationLevel; + } } return $result;