Magento Forum

Format price in layered navigation (1.7.0.0)
 
marcfalk
Sr. Member
 
Total Posts:  87
Joined:  2008-11-22
 

Hi there,

I have happily upgraded to Magento CE 1.7.0.0, and appreciate all the new features. However, there are a couple of “theme” fixes that I need to upgrade as well, one of them being the way price is formatted in the layered navigation.

1.6.2.0

Before I was running 1.6.2.0, and I had modified the way prices were rendered in the layered navigation in the following way.

File:

app/code/local/Mage/Catalog/Model/Layer/Filter/Price.php

Function (around line 185):

/**
     * Prepare text of item label
     *
     * @deprecated since 1.7.0.0
     * @param   int $range
     * @param   float $value
     * @return  string
     */
    protected function _renderItemLabel($range$value)
    
{
        
// Commented out and replaced with code below to remove decimals from layered navigation
        //$store      = Mage::app()->getStore();
        //$fromPrice  = $store->formatPrice(($value-1)*$range);
        //$toPrice    = $store->formatPrice($value*$range);
        
        
$currency    Mage::app()->getStore()-> getCurrentCurrencyCode();
        
$fromPrice  round(($value-1)*$range,0);
        
$toPrice    round($value*$range,0);

        return 
Mage::helper('catalog')->__('%s - %s'$fromPrice$toPrice);
    
}

Output:

0-200
200
-400
400
-600
600
-800
etc
.

1.7.0.0

As that function has now been deprecated, a new function has taken its place. Now, however, I cannot really figure out how to show no decimals, and no currency symbol.

File:

app/code/local/Mage/Catalog/Model/Layer/Filter/Price.php

Function (around line 210):

/**
     * Prepare text of range label
     *
     * @param float|string $fromPrice
     * @param float|string $toPrice
     * @return string
     */
    protected function _renderRangeLabel($fromPrice$toPrice)
    
{
        
        $store 
Mage::app()->getStore();
        
$formattedFromPrice $store->formatPrice($fromPrice);
        
        if (
$toPrice === ''{
            
return Mage::helper('catalog')->__('%s and above'$formattedFromPrice);
        
elseif ($fromPrice == $toPrice && Mage::app()->getStore()->getConfig(self::XML_PATH_ONE_PRICE_INTERVAL)) {
            
return $formattedFromPrice;
        
else {
            
if ($fromPrice != $toPrice{
                $toPrice 
-= 0// Changed 0.01 to 0
            
}
            
return Mage::helper('catalog')->__('%s - %s'$formattedFromPrice$store->formatPrice($toPrice));
        
}
    }

Current output:

0,00 DKK 200,00 DKK
200
,00 DKK 400,00 DKK
400
,00 DKK 600,00 DKK
600
,00 DKK 800,00 DKK
etc
.

So, I guess my question is: How do I format price in the layered navigation (only) so that it displays without decimals or currency symbols?

I appreciate any hint in the right direction. Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
kiatng
Enthusiast
 
Total Posts:  875
Joined:  2008-09-03
Kuala Lumpur, Malaysia
 

Try

protected function _renderRangeLabel($fromPrice$toPrice)
{
        
        
//$store = Mage::app()->getStore();
        
$formattedFromPrice =$fromPrice;
        
        if (
$toPrice === ''{
            
return Mage::helper('catalog')->__('%s and above'$formattedFromPrice);
        
elseif ($fromPrice == $toPrice && Mage::app()->getStore()->getConfig(self::XML_PATH_ONE_PRICE_INTERVAL)) {
            
return $formattedFromPrice;
        
else {
            
if ($fromPrice != $toPrice{
                $toPrice 
-= 0// Changed 0.01 to 0
            
}
            
return Mage::helper('catalog')->__('%s - %s'$formattedFromPrice$toPrice);
        
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
HASSAN SHAHZAD
Jr. Member
 
Avatar
Total Posts:  26
Joined:  2012-02-08
 

For Mage 1.7.0.0:-
follow the path:

app\code\core\Mage\Catalog\Model\Layer\Filter
in price.phtml changes made no result, what was the issue I also had changed in 1.6.2.0 successfully.
 
Magento Community Magento Community
Magento Community
Magento Community
 
Stevan1978
Sr. Member
 
Avatar
Total Posts:  78
Joined:  2009-04-22
Etten-leur
 

Hi There,

I followed these steps from another site:

1) Add the attribute and choose “Text Input” as the “Catalog Input Type”

2) Open up PHPMyAdmin and search for your new attribute in “eav_attribute”
Change the backend_type from “varchar” to “decimal”
Change the value for “is_filterable” in “catalog_eav_attribute” from 0 to 1

3) Change Mage_Catalog_Model_Layer_Filter_Decimal _renderItemLabel to remove the price-formatting

The last item is refering to app\code\Mage\Catalog\Model\Layer\Filter\Decimal.php

But I don’t know what to change.
If I follow the answers in this post only the price, which is in the layered navigation gets stripped from it’s currency symbol and not my attribute.

How can I solve this so it also removes the currency symbol from my text attribute?

Br,

Steve

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top