We are doing custom Magento themes, Magento design, custom Magento extensions and creative services through Magento designers & developers for worldwide shop owners.

Last News
Magento Remove Decimals from product price without touching the core

Magento Remove Decimals from product price without touching the core

Many customers ask us to Remove Decimals from product price, so that does not happen for buyers confusion or mistakes in the price of the basket, so we decided to give a lesson in this easy way of how Remove Decimals from product price without touching the core .
1 – Remove Decimals from product price in product and category page :

A – create currency class in path /app/code/local/Mage/Directory/Model/Currency.php
copy the content from file in core /app/code/core/Mage/Directory/Model/Currency.php and paste in your new file /app/code/local/Mage/Directory/Model/Currency.php

B – find this code in your new file (line 222)

1
return $this->formatPrecision($price, 2, $options, $includeContainer, $addBrackets);

and change with new line :

1
return $this->formatPrecision($price, 0, $options, $includeContainer, $addBrackets);

2 – For Remove Decimals from product price in product view page with custom options

A – create view class in path /app/code/local/Mage/Catalog/Block/Product/View.php
copy the content from file in core /app/code/core/Mage/Catalog/Block/Product/View.php and paste in your new file /app/code/local/Mage/Catalog/Block/Product/View.php

B – find this code in your new file (line 175)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$config = array(
            'productId'           => $product->getId(),
            'priceFormat'         => Mage::app()->getLocale()->getJsPriceFormat(),
            'includeTax'          => Mage::helper('tax')->priceIncludesTax() ? 'true' : 'false',
            'showIncludeTax'      => Mage::helper('tax')->displayPriceIncludingTax(),
            'showBothPrices'      => Mage::helper('tax')->displayBothPrices(),
            'productPrice'        => Mage::helper('core')->currency($_finalPrice, false, false),
            'productOldPrice'     => Mage::helper('core')->currency($_regularPrice, false, false),
            'priceInclTax'        => Mage::helper('core')->currency($_priceInclTax, false, false),
            'priceExclTax'        => Mage::helper('core')->currency($_priceExclTax, false, false),
            /**
             * @var skipCalculate
             * @deprecated after 1.5.1.0
             */
            'skipCalculate'       => ($_priceExclTax != $_priceInclTax ? 0 : 1),
            'defaultTax'          => $defaultTax,
            'currentTax'          => $currentTax,
            'idSuffix'            => '_clone',
            'oldPlusDisposition'  => 0,
            'plusDisposition'     => 0,
            'plusDispositionTax'  => 0,
            'oldMinusDisposition' => 0,
            'minusDisposition'    => 0,
            'tierPrices'          => $_tierPrices,
            'tierPricesInclTax'   => $_tierPricesInclTax,
        );

and change with new line :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$pf=Mage::app()->getLocale()->getJsPriceFormat();
        $pf['precision']=0;
        $pf['requiredPrecision']=0;
        $config = array(
            'productId'           => $product->getId(),
            'priceFormat'         => $pf,
            'includeTax'          => Mage::helper('tax')->priceIncludesTax() ? 'true' : 'false',
            'showIncludeTax'      => Mage::helper('tax')->displayPriceIncludingTax(),
            'showBothPrices'      => Mage::helper('tax')->displayBothPrices(),
            'productPrice'        => Mage::helper('core')->currency($_finalPrice, false, false),
            'productOldPrice'     => Mage::helper('core')->currency($_regularPrice, false, false),
            'priceInclTax'        => Mage::helper('core')->currency($_priceInclTax, false, false),
            'priceExclTax'        => Mage::helper('core')->currency($_priceExclTax, false, false),
            /**
             * @var skipCalculate
             * @deprecated after 1.5.1.0
             */
            'skipCalculate'       => ($_priceExclTax != $_priceInclTax ? 0 : 1),
            'defaultTax'          => $defaultTax,
            'currentTax'          => $currentTax,
            'idSuffix'            => '_clone',
            'oldPlusDisposition'  => 0,
            'plusDisposition'     => 0,
            'plusDispositionTax'  => 0,
            'oldMinusDisposition' => 0,
            'minusDisposition'    => 0,
            'tierPrices'          => $_tierPrices,
            'tierPricesInclTax'   => $_tierPricesInclTax,
        );

3 – For Remove Decimals between store

A – create currency class in path /app/code/local/Mage/Core/Model/Store.php
copy the content from file in core /app/code/core/Mage/Core/Model/Store.php and paste in your new file /app/code/app/code/local/Mage/Core/Model/Store.php

B – find this code in your new file (line 991)

1
return round($price, 2);

and change with new line :

1
return round($price, 0);

4 -try the preview methode if you don’t have result ,
you can play too inside :

A – js/varien/js.js in code (line 222):

1
2
var precision = isNaN(format.precision = Math.abs(format.precision)) ? 2 : format.precision;
var requiredPrecision = isNaN(format.requiredPrecision = Math.abs(format.requiredPrecision)) ? 2 : format.requiredPrecision;

change to :

1
2
var precision = 0;
var requiredPrecision = 0;

B – lib/Zend/Currency.php (line 69) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
protected $_options = array(
        'position'  => self::STANDARD,
        'script'    => null,
        'format'    => null,
        'display'   => self::NO_SYMBOL,
        'precision' => 2,
        'name'      => null,
        'currency'  => null,
        'symbol'    => null,
        'locale'    => null,
        'value'     => 0,
        'service'   => null,
        'tag'       => 'Zend_Locale'
    );

change to :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
protected $_options = array(
        'position'  => self::STANDARD,
        'script'    => null,
        'format'    => null,
        'display'   => self::NO_SYMBOL,
        'precision' => 0,
        'name'      => null,
        'currency'  => null,
        'symbol'    => null,
        'locale'    => null,
        'value'     => 0,
        'service'   => null,
        'tag'       => 'Zend_Locale'
    );

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*