4

I want to change my quote currency code to EUR when an order is placed in any other currency.

I tried writing event and observer of event sales_order_place_before. In my observer I have this code

    $quoteId = $observer->getEvent()->getOrder()->getQuoteId();
    $quote = $this->cartRepository->get($quoteId);
    $this->storeManager->getStore()->setCurrentCurrencyCode('EUR');
    $quote->setQuoteCurrencyCode("EUR");
    $quote->collectTotals();
    $this->cartRepository->save($quote);

But after order is placed currency did not change to Euro.

I tried another event sales_quote_save_after, where currency is changed after every save of quote, but in that case, even the customer will see that his cart currency is changed to EUR, which I don't want. I only want to change the currency when order is being placed (the customer should not be shown this anywhere, except on my orders)

2
  • try this $quote->save(); Commented May 27, 2019 at 15:56
  • I tried it, but it did not work.
    – Bharath N
    Commented May 28, 2019 at 7:30

1 Answer 1

0

Instead of sales_order_place_before && sales_quote_save_after use this event sales_model_service_quote_submit_before and write your logic for this but don't call save function in the observer

10
  • let me know if any issues
    – mohith
    Commented May 28, 2019 at 7:44
  • I tried with the sales_model_service_quote_submit_before, it din't work. In my observer if I die and execute again without die, the order is placed in EUR currency. Any suggestions on this?
    – Bharath N
    Commented May 28, 2019 at 9:53
  • what do you mean by " In my observer if I die and execute again without die means" can you please elaborate.
    – mohith
    Commented May 28, 2019 at 10:37
  • At the end of my observer I wrote die, the order was not paced but the quote currency was updated to EUR, next I remove the die, and again place the same order the order is placed in EUR.
    – Bharath N
    Commented May 28, 2019 at 11:26
  • is every thing is fine now?
    – mohith
    Commented May 28, 2019 at 11:42

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.