From 3d9557331192472fd83695fe423868ed768a1a95 Mon Sep 17 00:00:00 2001 From: Richard Brown Date: Tue, 26 Mar 2019 22:36:30 +0000 Subject: [PATCH 1/7] Fix pricing when using with&without tax with customer groups When using prices with and without taxes, there are multiple entries in the $fields array. When looping through the groups $product->getPriceModel()->getFinalPrice() is called for each group. This sets the data['final_price'] on the product model each time it is called. This means that on the second loop of the field array, when the call to set $special_price uses $product->getFinalPrice() it is getting value set for the final group in the previous iteration. This patch changes the assignment of special_price to recalculate the final_price everytime, it also moves it out of the currency loop because the result doesn't depend on the currency. (cherry picked from commit 77dad50c58c81b6e95772230bad89e05b60c9b2e) (cherry picked from commit 6731ddb4105bec9263a62a81c5fa5bba9a2ea271) --- .../Algolia/Algoliasearch/Helper/Config.php | 2 + .../Helper/Entity/Producthelper.php | 145 +++++++++--------- .../internals/configuration.phtml | 2 +- js/algoliasearch/internals/frontend/common.js | 37 +++-- 4 files changed, 105 insertions(+), 81 deletions(-) diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Config.php b/app/code/community/Algolia/Algoliasearch/Helper/Config.php index e8a3dec3..5c7a4bcf 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Config.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Config.php @@ -484,6 +484,8 @@ public function getAttributesToRetrieve($groupId, $store) foreach ($currencies as $currency) { $attributes[] = $price.'.'.$currency.'.default'; $attributes[] = $price.'.'.$currency.'.default_formated'; + $attributes[] = $price.'.'.$currency.'.default_original'; + $attributes[] = $price.'.'.$currency.'.default_original_formated'; $attributes[] = $price.'.'.$currency.'.group_'.$groupId; $attributes[] = $price.'.'.$currency.'.group_'.$groupId.'_formated'; $attributes[] = $price.'.'.$currency.'.group_'.$groupId.'_original_formated'; diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php index 02b0c260..d4086f2c 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php @@ -176,6 +176,7 @@ public function getProductCollectionQuery($storeId, $productIds = null, $only_vi } $products = $products + ->addAttributeToSelect('special_price') ->addAttributeToSelect('special_from_date') ->addAttributeToSelect('special_to_date') ->addAttributeToSelect('visibility') @@ -496,14 +497,22 @@ protected function formatPrice($price, $includeContainer, $currency_code) protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_products, &$customData) { + /** @var Mage_Directory_Model_Currency $directoryCurrency */ + $directoryCurrency = Mage::getModel('directory/currency'); + + /** @var Mage_Tax_Helper_Data $taxHelper */ + $taxHelper = Mage::helper('tax'); + + /** @var Mage_Directory_Helper_Data $directoryHelper */ + $directoryHelper = Mage::helper('directory'); + $fields = $this->getFields($product->getStore()); $customer_groups_enabled = $this->config->isCustomerGroupsEnabled($product->getStoreId()); $store = $product->getStore(); $type = $this->config->getMappedProductType($product->getTypeId()); - /** @var Mage_Directory_Model_Currency $directoryCurrency */ - $directoryCurrency = Mage::getModel('directory/currency'); $currencies = $directoryCurrency->getConfigAllowCurrencies(); + $baseCurrencyCode = $store->getBaseCurrencyCode(); if (Mage::helper('core')->isModuleEnabled('Mage_Weee') && Mage::helper('weee')->getPriceDisplayType($product->getStore()) == 0) { @@ -512,96 +521,91 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $weeeTaxAmount = 0; } - $baseCurrencyCode = $store->getBaseCurrencyCode(); - - $groups = array(); - if ($customer_groups_enabled) { $groups = Mage::getModel('customer/group')->getCollection(); + } else { + $groups = array(); + } + $special_price = $product->getSpecialPrice(); + $special_from_date = $product->getSpecialFromDate(); + $special_to_date = $product->getSpecialToDate(); + + // There is a special_price and either no to date or a to date in the future + // start date is irrelevant + if ($special_price && Mage::app()->getLocale()->isStoreDateInInterval($store, null, $special_to_date)) { + $canSpecialBeValid = true; + $special_price += $weeeTaxAmount; } - - /** @var Mage_Tax_Helper_Data $taxHelper */ - $taxHelper = Mage::helper('tax'); - - /** @var Mage_Directory_Helper_Data $directoryHelper */ - $directoryHelper = Mage::helper('directory'); foreach ($fields as $field => $with_tax) { $customData[$field] = array(); + $field_price = (double) $taxHelper->getPrice($product, $product->getPrice() + $weeeTaxAmount, $with_tax, null, null, null, $store, null); + if ($canSpecialBeValid) { + $field_special_price = (double) $taxHelper->getPrice($product, $special_price, $with_tax, null, null, null, $store, null); + } foreach ($currencies as $currency_code) { - $customData[$field][$currency_code] = array(); + $cdfc = array(); - $price = (double) $taxHelper->getPrice($product, $product->getPrice(), $with_tax, null, null, null, $product->getStore(), null); - $price = $directoryHelper->currencyConvert($price, $baseCurrencyCode, $currency_code); - $price += $weeeTaxAmount; + $price = $directoryHelper->currencyConvert($field_price + $weeeTaxAmount, $baseCurrencyCode, $currency_code); - $customData[$field][$currency_code]['default'] = $price; - $customData[$field][$currency_code]['default_formated'] = $this->formatPrice($price, false, $currency_code); + $cdfc['default'] = $price; + $cdfc['default_formated'] = $this->formatPrice($price, false, $currency_code); - $special_price = (double) $taxHelper->getPrice($product, $product->getFinalPrice(), $with_tax, null, null, null, $product->getStore(), null); - $special_price = $directoryHelper->currencyConvert($special_price, $baseCurrencyCode, $currency_code); - $special_price += $weeeTaxAmount; + if ($canSpecialBeValid) { + $special_price = $directoryHelper->currencyConvert($field_special_price + $weeeTaxAmount, $baseCurrencyCode, $currency_code); + // this needs moving up a few levels + $cdfc['special_from_date'] = Mage::app()->getLocale()->storeDate($store, $special_from_date)->getTimestamp(); + //if special_to_date is null this will default to today + $cdfc['special_to_date'] = Mage::app()->getLocale()->storeDate($store, $special_to_date)->getTimestamp(); + } if ($customer_groups_enabled) { // If fetch special price for groups foreach ($groups as $group) { $group_id = (int) $group->getData('customer_group_id'); + $group_str = 'group_' . $group_id; $product->setCustomerGroupId($group_id); - $discounted_price = $product->getPriceModel()->getFinalPrice(1, $product); - $discounted_price = $directoryHelper->currencyConvert($discounted_price, $baseCurrencyCode, $currency_code); - $discounted_price += $weeeTaxAmount; - - if ($discounted_price !== false) { - $customData[$field][$currency_code]['group_'.$group_id] = (double) $taxHelper->getPrice($product, - $discounted_price, - $with_tax, null, - null, null, - $product->getStore(), - null); - $customData[$field][$currency_code]['group_'.$group_id] = $directoryHelper->currencyConvert($customData[$field][$currency_code]['group_'.$group_id], - $baseCurrencyCode, - $currency_code); - $customData[$field][$currency_code]['group_'.$group_id.'_formated'] = $store->formatPrice($customData[$field][$currency_code]['group_'.$group_id], - false, $currency_code); + $group_price = $product->getGroupPrice(); + $group_price += $weeeTaxAmount; + + if ($group_price !== false) { + $cdfc[$group_str] = $directoryHelper->currencyConvert( + (double) $taxHelper->getPrice($product, + $group_price, + $with_tax, null, + null, null, + $store, + null), + $baseCurrencyCode, + $currency_code); } else { - $customData[$field][$currency_code]['group_'.$group_id] = $customData[$field][$currency_code]['default']; - $customData[$field][$currency_code]['group_'.$group_id.'_formated'] = $customData[$field][$currency_code]['default_formated']; + $cdfc[$group_str] = $cdfc['default']; } - } - $product->setCustomerGroupId(null); - } - - $customData[$field][$currency_code]['special_from_date'] = strtotime($product->getSpecialFromDate()); - $customData[$field][$currency_code]['special_to_date'] = strtotime($product->getSpecialToDate()); - - if ($customer_groups_enabled) { - foreach ($groups as $group) { - $group_id = (int) $group->getData('customer_group_id'); - - if ($special_price && $special_price < $customData[$field][$currency_code]['group_'.$group_id]) { - $customData[$field][$currency_code]['group_'.$group_id.'_original_formated'] = - $customData[$field][$currency_code]['default_formated']; - - $customData[$field][$currency_code]['group_'.$group_id] = $special_price; - $customData[$field][$currency_code]['group_'.$group_id.'_formated'] = $this->formatPrice( - $special_price, + if ($canSpecialBeValid && $special_price < $cdfc[$group_str]) { + $cdfc[$group_str .'_original_formated'] = $this->formatPrice( + $cdfc[$group_str], false, $currency_code ); + $cdfc[$group_str .'_original'] = $cdfc[$group_str]; + + $cdfc[$group_str] = $special_price; } + $cdfc[$group_str .'_formated'] = $store->formatPrice($cdfc[$group_str], false, $currency_code); } + $product->setCustomerGroupId(null); } - if ($special_price && $special_price < $customData[$field][$currency_code]['default']) { - $customData[$field][$currency_code]['default_original_formated'] = - $customData[$field][$currency_code]['default_formated']; + if ($canSpecialBeValid && $special_price < $cdfc['default']) { + $cdfc['default_original_formated'] = $cdfc['default_formated']; + $cdfc['default_original'] = $cdfc['default']; - $customData[$field][$currency_code]['default'] = $special_price; - $customData[$field][$currency_code]['default_formated'] = $this->formatPrice( + $cdfc['default'] = $special_price; + $cdfc['default_formated'] = $this->formatPrice( $special_price, false, $currency_code @@ -659,14 +663,15 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc if ($customer_groups_enabled) { foreach ($groups as $group) { $group_id = (int) $group->getData('customer_group_id'); + $group_str = 'group_' . $group_id; - if ($min != $max && $min <= $customData[$field][$currency_code]['group_'.$group_id]) { - $customData[$field][$currency_code]['group_'.$group_id] = 0; + if ($min != $max && $min <= $customData[$field][$currency_code][$group_str]) { + $customData[$field][$currency_code][$group_str] = 0; } else { - $customData[$field][$currency_code]['group_'.$group_id] = $customData[$field][$currency_code]['default']; + $customData[$field][$currency_code][$group_str] = $customData[$field][$currency_code]['default']; } - $customData[$field][$currency_code]['group_'.$group_id.'_formated'] = $dashed_format; + $customData[$field][$currency_code][$group_str .'_formated'] = $dashed_format; } } } @@ -683,17 +688,19 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc if ($customer_groups_enabled) { foreach ($groups as $group) { $group_id = (int) $group->getData('customer_group_id'); + $group_str = 'group_' . $group_id; - if ($customData[$field][$currency_code]['group_'.$group_id] == 0) { - $customData[$field][$currency_code]['group_'.$group_id] = $min; + if ($customData[$field][$currency_code][$group_str] == 0) { + $customData[$field][$currency_code][$group_str] = $min; if ($min === $max) { - $customData[$field][$currency_code]['group_'.$group_id.'_formated'] = $customData[$field][$currency_code]['default_formated']; + $customData[$field][$currency_code][$group_str .'_formated'] = $customData[$field][$currency_code]['default_formated']; } } } } } + $customData[$field][$currency_code] = $cdfc; } } } diff --git a/app/design/frontend/base/default/template/algoliasearch/internals/configuration.phtml b/app/design/frontend/base/default/template/algoliasearch/internals/configuration.phtml index 325906d3..b9a0fc27 100644 --- a/app/design/frontend/base/default/template/algoliasearch/internals/configuration.phtml +++ b/app/design/frontend/base/default/template/algoliasearch/internals/configuration.phtml @@ -35,7 +35,7 @@ $session = Mage::getSingleton('customer/session'); $customerGroupId = $session->getCustomerGroupId(); $priceKey = '.'.$currencyCode.'.default'; -if ($config->isCustomerGroupsEnabled($storeId) && $customerGroupId !== 0) { +if ($config->isCustomerGroupsEnabled($storeId)) { $priceKey = '.'.$currencyCode.'.group_'.$customerGroupId; } diff --git a/js/algoliasearch/internals/frontend/common.js b/js/algoliasearch/internals/frontend/common.js index ef6c2aa0..6b56744f 100644 --- a/js/algoliasearch/internals/frontend/common.js +++ b/js/algoliasearch/internals/frontend/common.js @@ -39,9 +39,8 @@ var algolia = { if (Array.isArray(currentData)) { currentData = [currentData]; } - var allParameters = [].concat(currentData).concat(hookArguments); - + return hook.apply(null, allParameters); }, originalData); @@ -143,17 +142,33 @@ document.addEventListener("DOMContentLoaded", function (e) { hit.price = hit.price[0]; } - if (hit['price'] !== undefined && price_key !== '.' + algoliaConfig.currencyCode + '.default' && hit['price'][algoliaConfig.currencyCode][price_key.substr(1) + '_formated'] !== hit['price'][algoliaConfig.currencyCode]['default_formated']) { - hit['price'][algoliaConfig.currencyCode][price_key.substr(1) + '_original_formated'] = hit['price'][algoliaConfig.currencyCode]['default_formated']; + if (Array.isArray(hit.price_with_tax)) { + hit.price_with_tax = hit.price_with_tax[0]; } - - if (hit['price'] !== undefined && hit['price'][algoliaConfig.currencyCode]['default_original_formated'] - && hit['price'][algoliaConfig.currencyCode]['special_to_date']) { + + // price_key is in format .CURRENCY.KEY, fix that for array access + const price_key_as_key = price_key.replace('.' + algoliaConfig.currencyCode + '.', ''); + const formated_original_key = price_key_as_key + '_original_formated'; + + // original_formatted means that there is possibly a special price + if (hit['price'] !== undefined && hit['price'][algoliaConfig.currencyCode][formated_original_key]) { + const formated_key = price_key_as_key + '_formated'; + + // Neither date should be blank, magento sets special_from_date + // Producthelper.php sets to_date to today if it's blank + var priceStart = hit['price'][algoliaConfig.currencyCode]['special_from_date']; var priceExpiration = hit['price'][algoliaConfig.currencyCode]['special_to_date']; - if (algoliaConfig.now > priceExpiration) { - hit['price'][algoliaConfig.currencyCode]['default_formated'] = hit['price'][algoliaConfig.currencyCode]['default_original_formated']; - hit['price'][algoliaConfig.currencyCode]['default_original_formated'] = false; + // if .now is not inside the window between priceStart and priceExpiration + if (!(algoliaConfig.now >= priceStart && algoliaConfig.now <= priceExpiration )) { + // remove original_formatted_price, so client doesn't show special price + hit['price'][algoliaConfig.currencyCode][formated_key] = hit['price'][algoliaConfig.currencyCode][formated_original_key]; + hit['price'][algoliaConfig.currencyCode][formated_original_key] = false; + if (hit.price_with_tax !== undefined) { + hit['price_with_tax'][algoliaConfig.currencyCode][formated_key] = hit['price_with_tax'][algoliaConfig.currencyCode][formated_original_key]; + hit['price_with_tax'][algoliaConfig.currencyCode][formated_original_key] = false; + + } } } @@ -517,4 +532,4 @@ document.addEventListener("DOMContentLoaded", function (e) { window.scrollTo(x, y); }; }); -}); \ No newline at end of file +}); From 05f97b96b1c2ff2d687229ee4f087edcf7b48e30 Mon Sep 17 00:00:00 2001 From: Richard Brown Date: Mon, 8 Apr 2019 21:53:26 +0100 Subject: [PATCH 2/7] Tidy up grouped/bundled/configurable products from my changes --- .../Helper/Entity/Producthelper.php | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php index d4086f2c..f3495a43 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php @@ -612,6 +612,9 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc ); } + // configurable appears to assume that there are no customer_group_prices + // specified on the attached simple products, but needs re-writing anyway + // to correctly calculate the option price, not the simple price if ($type == 'grouped' || $type == 'bundle' || $type == 'configurable') { $min = PHP_INT_MAX; $max = 0; @@ -649,15 +652,16 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $dashed_format = $this->formatPrice($min, false, $currency_code).' - '.$this->formatPrice($max, false, $currency_code); - if (isset($customData[$field][$currency_code]['default_original_formated']) === false || $min <= $customData[$field][$currency_code]['default']) { - $customData[$field][$currency_code]['default_formated'] = $dashed_format; + if (isset($cdfc['default_original_formated']) === false || $min <= $cdfc['default']) { + $cdfc['default_formated'] = $dashed_format; //// Do not keep special price that is already taken into account in min max - unset($customData['price']['special_from_date']); - unset($customData['price']['special_to_date']); - unset($customData['price']['default_original_formated']); + unset($cdfc['special_from_date']); + unset($cdfc['special_to_date']); + unset($cdfc['default_original']); + unset($cdfc['default_original_formated']); - $customData[$field][$currency_code]['default'] = 0; // will be reset just after + $cdfc['default'] = 0; // will be reset just after } if ($customer_groups_enabled) { @@ -665,22 +669,22 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $group_id = (int) $group->getData('customer_group_id'); $group_str = 'group_' . $group_id; - if ($min != $max && $min <= $customData[$field][$currency_code][$group_str]) { - $customData[$field][$currency_code][$group_str] = 0; + if ($min != $max && $min <= $cdfc[$group_str]) { + $cdfc[$group_str] = 0; } else { - $customData[$field][$currency_code][$group_str] = $customData[$field][$currency_code]['default']; + $cdfc[$group_str] = $cdfc['default']; } - $customData[$field][$currency_code][$group_str .'_formated'] = $dashed_format; + $cdfc[$group_str .'_formated'] = $dashed_format; } } } - if ($customData[$field][$currency_code]['default'] == 0) { - $customData[$field][$currency_code]['default'] = $min; + if ($cdfc['default'] == 0) { + $cdfc['default'] = $min; if ($min === $max) { - $customData[$field][$currency_code]['default_formated'] = $this->formatPrice($min, false, + $cdfc['default_formated'] = $this->formatPrice($min, false, $currency_code); } } @@ -690,11 +694,11 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $group_id = (int) $group->getData('customer_group_id'); $group_str = 'group_' . $group_id; - if ($customData[$field][$currency_code][$group_str] == 0) { - $customData[$field][$currency_code][$group_str] = $min; + if ($cdfc[$group_str] == 0) { + $cdfc[$group_str] = $min; if ($min === $max) { - $customData[$field][$currency_code][$group_str .'_formated'] = $customData[$field][$currency_code]['default_formated']; + $cdfc[$group_str .'_formated'] = $cdfc['default_formated']; } } } From 9970df4dfb4c0e504a1581fac57331736330e0ed Mon Sep 17 00:00:00 2001 From: Richard Brown Date: Tue, 26 Mar 2019 22:36:30 +0000 Subject: [PATCH 3/7] Fix pricing when using with&without tax with customer groups When using prices with and without taxes, there are multiple entries in the $fields array. When looping through the groups $product->getPriceModel()->getFinalPrice() is called for each group. This sets the data['final_price'] on the product model each time it is called. This means that on the second loop of the field array, when the call to set $special_price uses $product->getFinalPrice() it is getting value set for the final group in the previous iteration. This patch changes the assignment of special_price to recalculate the final_price everytime, it also moves it out of the currency loop because the result doesn't depend on the currency. (cherry picked from commit 77dad50c58c81b6e95772230bad89e05b60c9b2e) (cherry picked from commit 6731ddb4105bec9263a62a81c5fa5bba9a2ea271) --- .../Algolia/Algoliasearch/Helper/Config.php | 2 + .../Helper/Entity/Producthelper.php | 145 +++++++++--------- .../internals/configuration.phtml | 2 +- js/algoliasearch/internals/frontend/common.js | 37 +++-- 4 files changed, 105 insertions(+), 81 deletions(-) diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Config.php b/app/code/community/Algolia/Algoliasearch/Helper/Config.php index 3e9c0e1f..30858980 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Config.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Config.php @@ -488,6 +488,8 @@ public function getAttributesToRetrieve($groupId, $store) foreach ($currencies as $currency) { $attributes[] = $price.'.'.$currency.'.default'; $attributes[] = $price.'.'.$currency.'.default_formated'; + $attributes[] = $price.'.'.$currency.'.default_original'; + $attributes[] = $price.'.'.$currency.'.default_original_formated'; $attributes[] = $price.'.'.$currency.'.group_'.$groupId; $attributes[] = $price.'.'.$currency.'.group_'.$groupId.'_formated'; $attributes[] = $price.'.'.$currency.'.group_'.$groupId.'_original_formated'; diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php index 02b0c260..d4086f2c 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php @@ -176,6 +176,7 @@ public function getProductCollectionQuery($storeId, $productIds = null, $only_vi } $products = $products + ->addAttributeToSelect('special_price') ->addAttributeToSelect('special_from_date') ->addAttributeToSelect('special_to_date') ->addAttributeToSelect('visibility') @@ -496,14 +497,22 @@ protected function formatPrice($price, $includeContainer, $currency_code) protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_products, &$customData) { + /** @var Mage_Directory_Model_Currency $directoryCurrency */ + $directoryCurrency = Mage::getModel('directory/currency'); + + /** @var Mage_Tax_Helper_Data $taxHelper */ + $taxHelper = Mage::helper('tax'); + + /** @var Mage_Directory_Helper_Data $directoryHelper */ + $directoryHelper = Mage::helper('directory'); + $fields = $this->getFields($product->getStore()); $customer_groups_enabled = $this->config->isCustomerGroupsEnabled($product->getStoreId()); $store = $product->getStore(); $type = $this->config->getMappedProductType($product->getTypeId()); - /** @var Mage_Directory_Model_Currency $directoryCurrency */ - $directoryCurrency = Mage::getModel('directory/currency'); $currencies = $directoryCurrency->getConfigAllowCurrencies(); + $baseCurrencyCode = $store->getBaseCurrencyCode(); if (Mage::helper('core')->isModuleEnabled('Mage_Weee') && Mage::helper('weee')->getPriceDisplayType($product->getStore()) == 0) { @@ -512,96 +521,91 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $weeeTaxAmount = 0; } - $baseCurrencyCode = $store->getBaseCurrencyCode(); - - $groups = array(); - if ($customer_groups_enabled) { $groups = Mage::getModel('customer/group')->getCollection(); + } else { + $groups = array(); + } + $special_price = $product->getSpecialPrice(); + $special_from_date = $product->getSpecialFromDate(); + $special_to_date = $product->getSpecialToDate(); + + // There is a special_price and either no to date or a to date in the future + // start date is irrelevant + if ($special_price && Mage::app()->getLocale()->isStoreDateInInterval($store, null, $special_to_date)) { + $canSpecialBeValid = true; + $special_price += $weeeTaxAmount; } - - /** @var Mage_Tax_Helper_Data $taxHelper */ - $taxHelper = Mage::helper('tax'); - - /** @var Mage_Directory_Helper_Data $directoryHelper */ - $directoryHelper = Mage::helper('directory'); foreach ($fields as $field => $with_tax) { $customData[$field] = array(); + $field_price = (double) $taxHelper->getPrice($product, $product->getPrice() + $weeeTaxAmount, $with_tax, null, null, null, $store, null); + if ($canSpecialBeValid) { + $field_special_price = (double) $taxHelper->getPrice($product, $special_price, $with_tax, null, null, null, $store, null); + } foreach ($currencies as $currency_code) { - $customData[$field][$currency_code] = array(); + $cdfc = array(); - $price = (double) $taxHelper->getPrice($product, $product->getPrice(), $with_tax, null, null, null, $product->getStore(), null); - $price = $directoryHelper->currencyConvert($price, $baseCurrencyCode, $currency_code); - $price += $weeeTaxAmount; + $price = $directoryHelper->currencyConvert($field_price + $weeeTaxAmount, $baseCurrencyCode, $currency_code); - $customData[$field][$currency_code]['default'] = $price; - $customData[$field][$currency_code]['default_formated'] = $this->formatPrice($price, false, $currency_code); + $cdfc['default'] = $price; + $cdfc['default_formated'] = $this->formatPrice($price, false, $currency_code); - $special_price = (double) $taxHelper->getPrice($product, $product->getFinalPrice(), $with_tax, null, null, null, $product->getStore(), null); - $special_price = $directoryHelper->currencyConvert($special_price, $baseCurrencyCode, $currency_code); - $special_price += $weeeTaxAmount; + if ($canSpecialBeValid) { + $special_price = $directoryHelper->currencyConvert($field_special_price + $weeeTaxAmount, $baseCurrencyCode, $currency_code); + // this needs moving up a few levels + $cdfc['special_from_date'] = Mage::app()->getLocale()->storeDate($store, $special_from_date)->getTimestamp(); + //if special_to_date is null this will default to today + $cdfc['special_to_date'] = Mage::app()->getLocale()->storeDate($store, $special_to_date)->getTimestamp(); + } if ($customer_groups_enabled) { // If fetch special price for groups foreach ($groups as $group) { $group_id = (int) $group->getData('customer_group_id'); + $group_str = 'group_' . $group_id; $product->setCustomerGroupId($group_id); - $discounted_price = $product->getPriceModel()->getFinalPrice(1, $product); - $discounted_price = $directoryHelper->currencyConvert($discounted_price, $baseCurrencyCode, $currency_code); - $discounted_price += $weeeTaxAmount; - - if ($discounted_price !== false) { - $customData[$field][$currency_code]['group_'.$group_id] = (double) $taxHelper->getPrice($product, - $discounted_price, - $with_tax, null, - null, null, - $product->getStore(), - null); - $customData[$field][$currency_code]['group_'.$group_id] = $directoryHelper->currencyConvert($customData[$field][$currency_code]['group_'.$group_id], - $baseCurrencyCode, - $currency_code); - $customData[$field][$currency_code]['group_'.$group_id.'_formated'] = $store->formatPrice($customData[$field][$currency_code]['group_'.$group_id], - false, $currency_code); + $group_price = $product->getGroupPrice(); + $group_price += $weeeTaxAmount; + + if ($group_price !== false) { + $cdfc[$group_str] = $directoryHelper->currencyConvert( + (double) $taxHelper->getPrice($product, + $group_price, + $with_tax, null, + null, null, + $store, + null), + $baseCurrencyCode, + $currency_code); } else { - $customData[$field][$currency_code]['group_'.$group_id] = $customData[$field][$currency_code]['default']; - $customData[$field][$currency_code]['group_'.$group_id.'_formated'] = $customData[$field][$currency_code]['default_formated']; + $cdfc[$group_str] = $cdfc['default']; } - } - $product->setCustomerGroupId(null); - } - - $customData[$field][$currency_code]['special_from_date'] = strtotime($product->getSpecialFromDate()); - $customData[$field][$currency_code]['special_to_date'] = strtotime($product->getSpecialToDate()); - - if ($customer_groups_enabled) { - foreach ($groups as $group) { - $group_id = (int) $group->getData('customer_group_id'); - - if ($special_price && $special_price < $customData[$field][$currency_code]['group_'.$group_id]) { - $customData[$field][$currency_code]['group_'.$group_id.'_original_formated'] = - $customData[$field][$currency_code]['default_formated']; - - $customData[$field][$currency_code]['group_'.$group_id] = $special_price; - $customData[$field][$currency_code]['group_'.$group_id.'_formated'] = $this->formatPrice( - $special_price, + if ($canSpecialBeValid && $special_price < $cdfc[$group_str]) { + $cdfc[$group_str .'_original_formated'] = $this->formatPrice( + $cdfc[$group_str], false, $currency_code ); + $cdfc[$group_str .'_original'] = $cdfc[$group_str]; + + $cdfc[$group_str] = $special_price; } + $cdfc[$group_str .'_formated'] = $store->formatPrice($cdfc[$group_str], false, $currency_code); } + $product->setCustomerGroupId(null); } - if ($special_price && $special_price < $customData[$field][$currency_code]['default']) { - $customData[$field][$currency_code]['default_original_formated'] = - $customData[$field][$currency_code]['default_formated']; + if ($canSpecialBeValid && $special_price < $cdfc['default']) { + $cdfc['default_original_formated'] = $cdfc['default_formated']; + $cdfc['default_original'] = $cdfc['default']; - $customData[$field][$currency_code]['default'] = $special_price; - $customData[$field][$currency_code]['default_formated'] = $this->formatPrice( + $cdfc['default'] = $special_price; + $cdfc['default_formated'] = $this->formatPrice( $special_price, false, $currency_code @@ -659,14 +663,15 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc if ($customer_groups_enabled) { foreach ($groups as $group) { $group_id = (int) $group->getData('customer_group_id'); + $group_str = 'group_' . $group_id; - if ($min != $max && $min <= $customData[$field][$currency_code]['group_'.$group_id]) { - $customData[$field][$currency_code]['group_'.$group_id] = 0; + if ($min != $max && $min <= $customData[$field][$currency_code][$group_str]) { + $customData[$field][$currency_code][$group_str] = 0; } else { - $customData[$field][$currency_code]['group_'.$group_id] = $customData[$field][$currency_code]['default']; + $customData[$field][$currency_code][$group_str] = $customData[$field][$currency_code]['default']; } - $customData[$field][$currency_code]['group_'.$group_id.'_formated'] = $dashed_format; + $customData[$field][$currency_code][$group_str .'_formated'] = $dashed_format; } } } @@ -683,17 +688,19 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc if ($customer_groups_enabled) { foreach ($groups as $group) { $group_id = (int) $group->getData('customer_group_id'); + $group_str = 'group_' . $group_id; - if ($customData[$field][$currency_code]['group_'.$group_id] == 0) { - $customData[$field][$currency_code]['group_'.$group_id] = $min; + if ($customData[$field][$currency_code][$group_str] == 0) { + $customData[$field][$currency_code][$group_str] = $min; if ($min === $max) { - $customData[$field][$currency_code]['group_'.$group_id.'_formated'] = $customData[$field][$currency_code]['default_formated']; + $customData[$field][$currency_code][$group_str .'_formated'] = $customData[$field][$currency_code]['default_formated']; } } } } } + $customData[$field][$currency_code] = $cdfc; } } } diff --git a/app/design/frontend/base/default/template/algoliasearch/internals/configuration.phtml b/app/design/frontend/base/default/template/algoliasearch/internals/configuration.phtml index 325906d3..b9a0fc27 100644 --- a/app/design/frontend/base/default/template/algoliasearch/internals/configuration.phtml +++ b/app/design/frontend/base/default/template/algoliasearch/internals/configuration.phtml @@ -35,7 +35,7 @@ $session = Mage::getSingleton('customer/session'); $customerGroupId = $session->getCustomerGroupId(); $priceKey = '.'.$currencyCode.'.default'; -if ($config->isCustomerGroupsEnabled($storeId) && $customerGroupId !== 0) { +if ($config->isCustomerGroupsEnabled($storeId)) { $priceKey = '.'.$currencyCode.'.group_'.$customerGroupId; } diff --git a/js/algoliasearch/internals/frontend/common.js b/js/algoliasearch/internals/frontend/common.js index ef6c2aa0..6b56744f 100644 --- a/js/algoliasearch/internals/frontend/common.js +++ b/js/algoliasearch/internals/frontend/common.js @@ -39,9 +39,8 @@ var algolia = { if (Array.isArray(currentData)) { currentData = [currentData]; } - var allParameters = [].concat(currentData).concat(hookArguments); - + return hook.apply(null, allParameters); }, originalData); @@ -143,17 +142,33 @@ document.addEventListener("DOMContentLoaded", function (e) { hit.price = hit.price[0]; } - if (hit['price'] !== undefined && price_key !== '.' + algoliaConfig.currencyCode + '.default' && hit['price'][algoliaConfig.currencyCode][price_key.substr(1) + '_formated'] !== hit['price'][algoliaConfig.currencyCode]['default_formated']) { - hit['price'][algoliaConfig.currencyCode][price_key.substr(1) + '_original_formated'] = hit['price'][algoliaConfig.currencyCode]['default_formated']; + if (Array.isArray(hit.price_with_tax)) { + hit.price_with_tax = hit.price_with_tax[0]; } - - if (hit['price'] !== undefined && hit['price'][algoliaConfig.currencyCode]['default_original_formated'] - && hit['price'][algoliaConfig.currencyCode]['special_to_date']) { + + // price_key is in format .CURRENCY.KEY, fix that for array access + const price_key_as_key = price_key.replace('.' + algoliaConfig.currencyCode + '.', ''); + const formated_original_key = price_key_as_key + '_original_formated'; + + // original_formatted means that there is possibly a special price + if (hit['price'] !== undefined && hit['price'][algoliaConfig.currencyCode][formated_original_key]) { + const formated_key = price_key_as_key + '_formated'; + + // Neither date should be blank, magento sets special_from_date + // Producthelper.php sets to_date to today if it's blank + var priceStart = hit['price'][algoliaConfig.currencyCode]['special_from_date']; var priceExpiration = hit['price'][algoliaConfig.currencyCode]['special_to_date']; - if (algoliaConfig.now > priceExpiration) { - hit['price'][algoliaConfig.currencyCode]['default_formated'] = hit['price'][algoliaConfig.currencyCode]['default_original_formated']; - hit['price'][algoliaConfig.currencyCode]['default_original_formated'] = false; + // if .now is not inside the window between priceStart and priceExpiration + if (!(algoliaConfig.now >= priceStart && algoliaConfig.now <= priceExpiration )) { + // remove original_formatted_price, so client doesn't show special price + hit['price'][algoliaConfig.currencyCode][formated_key] = hit['price'][algoliaConfig.currencyCode][formated_original_key]; + hit['price'][algoliaConfig.currencyCode][formated_original_key] = false; + if (hit.price_with_tax !== undefined) { + hit['price_with_tax'][algoliaConfig.currencyCode][formated_key] = hit['price_with_tax'][algoliaConfig.currencyCode][formated_original_key]; + hit['price_with_tax'][algoliaConfig.currencyCode][formated_original_key] = false; + + } } } @@ -517,4 +532,4 @@ document.addEventListener("DOMContentLoaded", function (e) { window.scrollTo(x, y); }; }); -}); \ No newline at end of file +}); From e5a0521c9a97cff561c31c978cab514c173d616e Mon Sep 17 00:00:00 2001 From: Richard Brown Date: Mon, 8 Apr 2019 21:53:26 +0100 Subject: [PATCH 4/7] Tidy up grouped/bundled/configurable products from my changes --- .../Helper/Entity/Producthelper.php | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php index d4086f2c..f3495a43 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php @@ -612,6 +612,9 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc ); } + // configurable appears to assume that there are no customer_group_prices + // specified on the attached simple products, but needs re-writing anyway + // to correctly calculate the option price, not the simple price if ($type == 'grouped' || $type == 'bundle' || $type == 'configurable') { $min = PHP_INT_MAX; $max = 0; @@ -649,15 +652,16 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $dashed_format = $this->formatPrice($min, false, $currency_code).' - '.$this->formatPrice($max, false, $currency_code); - if (isset($customData[$field][$currency_code]['default_original_formated']) === false || $min <= $customData[$field][$currency_code]['default']) { - $customData[$field][$currency_code]['default_formated'] = $dashed_format; + if (isset($cdfc['default_original_formated']) === false || $min <= $cdfc['default']) { + $cdfc['default_formated'] = $dashed_format; //// Do not keep special price that is already taken into account in min max - unset($customData['price']['special_from_date']); - unset($customData['price']['special_to_date']); - unset($customData['price']['default_original_formated']); + unset($cdfc['special_from_date']); + unset($cdfc['special_to_date']); + unset($cdfc['default_original']); + unset($cdfc['default_original_formated']); - $customData[$field][$currency_code]['default'] = 0; // will be reset just after + $cdfc['default'] = 0; // will be reset just after } if ($customer_groups_enabled) { @@ -665,22 +669,22 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $group_id = (int) $group->getData('customer_group_id'); $group_str = 'group_' . $group_id; - if ($min != $max && $min <= $customData[$field][$currency_code][$group_str]) { - $customData[$field][$currency_code][$group_str] = 0; + if ($min != $max && $min <= $cdfc[$group_str]) { + $cdfc[$group_str] = 0; } else { - $customData[$field][$currency_code][$group_str] = $customData[$field][$currency_code]['default']; + $cdfc[$group_str] = $cdfc['default']; } - $customData[$field][$currency_code][$group_str .'_formated'] = $dashed_format; + $cdfc[$group_str .'_formated'] = $dashed_format; } } } - if ($customData[$field][$currency_code]['default'] == 0) { - $customData[$field][$currency_code]['default'] = $min; + if ($cdfc['default'] == 0) { + $cdfc['default'] = $min; if ($min === $max) { - $customData[$field][$currency_code]['default_formated'] = $this->formatPrice($min, false, + $cdfc['default_formated'] = $this->formatPrice($min, false, $currency_code); } } @@ -690,11 +694,11 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $group_id = (int) $group->getData('customer_group_id'); $group_str = 'group_' . $group_id; - if ($customData[$field][$currency_code][$group_str] == 0) { - $customData[$field][$currency_code][$group_str] = $min; + if ($cdfc[$group_str] == 0) { + $cdfc[$group_str] = $min; if ($min === $max) { - $customData[$field][$currency_code][$group_str .'_formated'] = $customData[$field][$currency_code]['default_formated']; + $cdfc[$group_str .'_formated'] = $cdfc['default_formated']; } } } From bc6dd618d7b5ebef36e25e16fd8fcd78106eb236 Mon Sep 17 00:00:00 2001 From: Richard Brown Date: Tue, 9 Apr 2019 18:31:54 +0100 Subject: [PATCH 5/7] Fix special prices with no expiry (cherry picked from commit 3324c8edde3fd9599608bf553a81cca977e4d7c4) --- .../Algolia/Algoliasearch/Helper/Entity/Producthelper.php | 6 ++++-- js/algoliasearch/internals/frontend/common.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php index f3495a43..490417ab 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php @@ -557,8 +557,10 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc // this needs moving up a few levels $cdfc['special_from_date'] = Mage::app()->getLocale()->storeDate($store, $special_from_date)->getTimestamp(); - //if special_to_date is null this will default to today - $cdfc['special_to_date'] = Mage::app()->getLocale()->storeDate($store, $special_to_date)->getTimestamp(); + //if special_to_date is null leave this blank or it will end the special_price! + if ($special_to_date) { + $cdfc['special_to_date'] = Mage::app()->getLocale()->storeDate($store, $special_to_date)->getTimestamp(); + } } if ($customer_groups_enabled) { // If fetch special price for groups diff --git a/js/algoliasearch/internals/frontend/common.js b/js/algoliasearch/internals/frontend/common.js index 6b56744f..040b00fe 100644 --- a/js/algoliasearch/internals/frontend/common.js +++ b/js/algoliasearch/internals/frontend/common.js @@ -154,10 +154,12 @@ document.addEventListener("DOMContentLoaded", function (e) { if (hit['price'] !== undefined && hit['price'][algoliaConfig.currencyCode][formated_original_key]) { const formated_key = price_key_as_key + '_formated'; - // Neither date should be blank, magento sets special_from_date - // Producthelper.php sets to_date to today if it's blank + // special_from_date should not be blank Producthelper.php sets it to today if blank var priceStart = hit['price'][algoliaConfig.currencyCode]['special_from_date']; + // special_to_date may be blank, maybe the special price doesn't end + // if it is blank, just set it to the future so the comparison works var priceExpiration = hit['price'][algoliaConfig.currencyCode]['special_to_date']; + if (!priceExpiration) priceExpiration = algoliaConfig.now+1; // if .now is not inside the window between priceStart and priceExpiration if (!(algoliaConfig.now >= priceStart && algoliaConfig.now <= priceExpiration )) { From 454dc46bfe80ed391bdda6ad0b02e2d25f503816 Mon Sep 17 00:00:00 2001 From: Richard Brown Date: Thu, 18 Apr 2019 09:46:10 +0100 Subject: [PATCH 6/7] Make sure $canSpecialBeValid is always defined --- .../Algolia/Algoliasearch/Helper/Entity/Producthelper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php index 490417ab..9602a0f0 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php @@ -535,6 +535,8 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc if ($special_price && Mage::app()->getLocale()->isStoreDateInInterval($store, null, $special_to_date)) { $canSpecialBeValid = true; $special_price += $weeeTaxAmount; + } else { + $canSpecialBeValid = false; } foreach ($fields as $field => $with_tax) { From b71bbd4907b77e3a0bdcdd5cd4c6d6b7bfba83b8 Mon Sep 17 00:00:00 2001 From: Richard Brown Date: Wed, 22 May 2019 18:18:39 +0100 Subject: [PATCH 7/7] Rename $cdfc to $currencyData --- .../Helper/Entity/Producthelper.php | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php index 9602a0f0..fd5fd2fe 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php @@ -547,21 +547,21 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc } foreach ($currencies as $currency_code) { - $cdfc = array(); + $currencyData = array(); $price = $directoryHelper->currencyConvert($field_price + $weeeTaxAmount, $baseCurrencyCode, $currency_code); - $cdfc['default'] = $price; - $cdfc['default_formated'] = $this->formatPrice($price, false, $currency_code); + $currencyData['default'] = $price; + $currencyData['default_formated'] = $this->formatPrice($price, false, $currency_code); if ($canSpecialBeValid) { $special_price = $directoryHelper->currencyConvert($field_special_price + $weeeTaxAmount, $baseCurrencyCode, $currency_code); // this needs moving up a few levels - $cdfc['special_from_date'] = Mage::app()->getLocale()->storeDate($store, $special_from_date)->getTimestamp(); + $currencyData['special_from_date'] = Mage::app()->getLocale()->storeDate($store, $special_from_date)->getTimestamp(); //if special_to_date is null leave this blank or it will end the special_price! if ($special_to_date) { - $cdfc['special_to_date'] = Mage::app()->getLocale()->storeDate($store, $special_to_date)->getTimestamp(); + $currencyData['special_to_date'] = Mage::app()->getLocale()->storeDate($store, $special_to_date)->getTimestamp(); } } if ($customer_groups_enabled) { @@ -576,7 +576,7 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $group_price += $weeeTaxAmount; if ($group_price !== false) { - $cdfc[$group_str] = $directoryHelper->currencyConvert( + $currencyData[$group_str] = $directoryHelper->currencyConvert( (double) $taxHelper->getPrice($product, $group_price, $with_tax, null, @@ -586,30 +586,30 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $baseCurrencyCode, $currency_code); } else { - $cdfc[$group_str] = $cdfc['default']; + $currencyData[$group_str] = $currencyData['default']; } - if ($canSpecialBeValid && $special_price < $cdfc[$group_str]) { - $cdfc[$group_str .'_original_formated'] = $this->formatPrice( - $cdfc[$group_str], + if ($canSpecialBeValid && $special_price < $currencyData[$group_str]) { + $currencyData[$group_str .'_original_formated'] = $this->formatPrice( + $currencyData[$group_str], false, $currency_code ); - $cdfc[$group_str .'_original'] = $cdfc[$group_str]; + $currencyData[$group_str .'_original'] = $currencyData[$group_str]; - $cdfc[$group_str] = $special_price; + $currencyData[$group_str] = $special_price; } - $cdfc[$group_str .'_formated'] = $store->formatPrice($cdfc[$group_str], false, $currency_code); + $currencyData[$group_str .'_formated'] = $store->formatPrice($currencyData[$group_str], false, $currency_code); } $product->setCustomerGroupId(null); } - if ($canSpecialBeValid && $special_price < $cdfc['default']) { - $cdfc['default_original_formated'] = $cdfc['default_formated']; - $cdfc['default_original'] = $cdfc['default']; + if ($canSpecialBeValid && $special_price < $currencyData['default']) { + $currencyData['default_original_formated'] = $currencyData['default_formated']; + $currencyData['default_original'] = $currencyData['default']; - $cdfc['default'] = $special_price; - $cdfc['default_formated'] = $this->formatPrice( + $currencyData['default'] = $special_price; + $currencyData['default_formated'] = $this->formatPrice( $special_price, false, $currency_code @@ -656,16 +656,16 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $dashed_format = $this->formatPrice($min, false, $currency_code).' - '.$this->formatPrice($max, false, $currency_code); - if (isset($cdfc['default_original_formated']) === false || $min <= $cdfc['default']) { - $cdfc['default_formated'] = $dashed_format; + if (isset($currencyData['default_original_formated']) === false || $min <= $currencyData['default']) { + $currencyData['default_formated'] = $dashed_format; //// Do not keep special price that is already taken into account in min max - unset($cdfc['special_from_date']); - unset($cdfc['special_to_date']); - unset($cdfc['default_original']); - unset($cdfc['default_original_formated']); + unset($currencyData['special_from_date']); + unset($currencyData['special_to_date']); + unset($currencyData['default_original']); + unset($currencyData['default_original_formated']); - $cdfc['default'] = 0; // will be reset just after + $currencyData['default'] = 0; // will be reset just after } if ($customer_groups_enabled) { @@ -673,22 +673,22 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $group_id = (int) $group->getData('customer_group_id'); $group_str = 'group_' . $group_id; - if ($min != $max && $min <= $cdfc[$group_str]) { - $cdfc[$group_str] = 0; + if ($min != $max && $min <= $currencyData[$group_str]) { + $currencyData[$group_str] = 0; } else { - $cdfc[$group_str] = $cdfc['default']; + $currencyData[$group_str] = $currencyData['default']; } - $cdfc[$group_str .'_formated'] = $dashed_format; + $currencyData[$group_str .'_formated'] = $dashed_format; } } } - if ($cdfc['default'] == 0) { - $cdfc['default'] = $min; + if ($currencyData['default'] == 0) { + $currencyData['default'] = $min; if ($min === $max) { - $cdfc['default_formated'] = $this->formatPrice($min, false, + $currencyData['default_formated'] = $this->formatPrice($min, false, $currency_code); } } @@ -698,17 +698,17 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc $group_id = (int) $group->getData('customer_group_id'); $group_str = 'group_' . $group_id; - if ($cdfc[$group_str] == 0) { - $cdfc[$group_str] = $min; + if ($currencyData[$group_str] == 0) { + $currencyData[$group_str] = $min; if ($min === $max) { - $cdfc[$group_str .'_formated'] = $cdfc['default_formated']; + $currencyData[$group_str .'_formated'] = $currencyData['default_formated']; } } } } } - $customData[$field][$currency_code] = $cdfc; + $customData[$field][$currency_code] = $currencyData; } } }