Wednesday, 2 December 2015

Magento Remove Decimals from product price

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)


return $this->formatPrecision($price, 2, $options, $includeContainer, $addBrackets);
and change with new line :
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)

$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 :
   
    $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)


return round($price, 2);
and change with new line :

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):


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 :


var precision = 0;
var requiredPrecision = 0;


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

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 :

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'
    );



Related link:-
http://magento.stackexchange.com/questions/36600/remove-precision-from-price-of-a-product

No comments:

Post a Comment