3

Currently the price is Rs 1,599.00 After 45% discount the price will be Rs 879.45.

I want that the price will be round off i.e Rs 879 and then when we choose the quantity to be 18 then the subtotal price will be 15822

Check Below screens for reference.

  1. https://prnt.sc/jsdn9b
  2. https://prnt.sc/jsdnh1

I dont want that price will be displayed in the decimal form like subtotal,shipping,discount,tax etc etc.

I'm using Magento 2.2.2

4 Answers 4

0

I have modified a method convert of file Magento\Directory\Model\Currency.

declaring a plugin, file Vendor/Module/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> 
<type name="Magento\Directory\Model\Currency">
    <plugin name="vendor_module" type="Vendor\Module\Model\Plugin\Currency" />
</type> 

plugin model, file Vendor/Module/Model/Plugin/Currency.php

<?php
namespace Vendor\Module\Model\Plugin;
use Magento\Framework\Exception\InputException;

class Currency
{
    public function aroundConvert($subject, $proceed, $price, $toCurrency = null)
    {
        $price = $proceed($price, $toCurrency);     
        // you logic
        // warning ... logic affects the price of shipping  
        return $price;
    }
}

Also see Complete code on GitHub

8
0

Create file and use this code :

=> From :

vendor/magento/module-catalog/view/base/templates/product/price/amount/default.phtml

=> To :

app/design/frontend/VendorName/ModuleName/Magento_Catalog/templates/product/price/amount/default.phtml

this file is defined from \Magento\Framework\Pricing\Render\Amount

The price itself is coming from this call:

<?php /* @escapeNotVerified */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?>

If we take a look at the file that this method is created based on the class it's inheriting (/vendor/magento/framework/Pricing/Render/Amount.php)

Update line no 24

<?php /* @escapeNotVerified */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?>

To

<?php /* @escapeNotVerified */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer() , 0) ?>

You need to override

vendor/magento/module-catalog/view/base/web/js/price-utils.js

To

app/design/frontend/VendorName/ModuelName/Magento_Catalog/web/js/price-utils.js

and change the value of precision on line 38:

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

To

var precision = 0,
3
  • This solution did not work for me. Commented Jun 8, 2018 at 9:32
  • can you tell me where issue generated ? Commented Jun 8, 2018 at 11:35
  • I already check that and it's working for me. There are something going wrong. Please check it. Commented Jun 8, 2018 at 11:55
0

We need to override Magento\Catalog\Model\Product file like below :

Create /Vendor/Module/etc/di.xml and copy below code:

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <type name="Magento\Catalog\Model\Product">
    <plugin name="change_product" type=" Vendor\Module\Plugin\Product" sortOrder="1" />
  </type>
</config>

Create file /Vendor/Module/Plugin/Product.php and copy below code:

<?php

namespace Vendor\Module\Plugin;


    class Product
    {
        public function afterGetPrice(\Magento\Catalog\Model\Product $subject, $result)
        {
            return round($result);
        }
    }
0

please use this plugin. This is Best solution and tested in 2.3 and working fine.

https://github.com/lillik/magento2-price-decimal

Gopal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.