Posted on

Magento 2: Change quote currency code before place order with Observer

I am trying to change the quote currency before placing any order.

I have used below event for that.

VendorModuleetcfrontendevents.xml

<event name=”sales_model_service_quote_submit_before”>
<observer name=”change_currency_before_place_order” instance=”VendorModuleObserverBeforePlaceOrder” />
</event>

VendorModuleObserverBeforePlaceOrder.php

<?php

namespace VendorModuleObserver;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
class BeforePlaceOrder implements ObserverInterface
{

protected $_checkoutSession;
private $logger;
/**
* @var MagentoCatalogModelSession
*/
protected $catalogSession;

public function __construct(
MagentoCheckoutModelSession $checkoutSession,
MagentoCatalogModelSession $catalogSession,
PsrLogLoggerInterface $logger
)
{
$this->_checkoutSession = $checkoutSession;
$this->catalogSession = $catalogSession;
$this->logger = $logger;
}

public function execute(MagentoFrameworkEventObserver $observer)
{
$quote = $observer->getEvent()->getQuote();
$this->logger->info(‘inside place order observer’);
//$this->storeManager->getStore()->setCurrentCurrencyCode(‘EUR’);
$quote->setQuoteCurrencyCode(“EUR”);
$quote->collectTotals();
}
}

The above event is not firing for me, Is there any other way to implement this functionality?

Note: The accepted answer working well but once the invoice is created, its changing to default currency again.

Can anyone advise me please why that event is not firing even after placing globally?.

Leave a Reply

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