Because of business logic I need to round all product prices to the nearest thousand.


If i have a price of $18600 i need to change the price to $19000. If i have $18400 i need to change it to $18000.

I've played with setDisplayValue($value) and getDisplayValue() methods from Magento_Framework/Pricing/Render/Amount.php but this does not change the price in all the store.

What file(s) should i modify to affect the behavior in all the store?


A. Martz.


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" 
<type name="Magento\Directory\Model\Currency">
    <plugin name="vendor_module" type="Vendor\Module\Model\Plugin\Currency" />

plugin model, file Vendor/Module/Model/Plugin/Currency.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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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