I did a lot of trial and error and was able to override the base_currency
.
/** @var \Magento\Quote\Model\Cart\Currency $quoteCurrency */
$quoteCurrency = $this->quoteCurrencyFactory->create()
->setGlobalCurrencyCode("GBP")
->setBaseCurrencyCode("GBP")
->setStoreCurrencyCode("GBP")
->setQuoteCurrencyCode("GBP")
->setStoreToBaseRate(1.00)
->setStoreToQuoteRate(1.00)
->setBaseToGlobalRate(1.00)
->setBaseToQuoteRate(1.00);
/** @var \Magento\Directory\Model\Currency $directoryCurrency */
$directoryCurrency = $this->directoryCurrencyFactory->create()
->setGlobalCurrencyCode("GBP")
->setBaseCurrencyCode("GBP")
->setStoreCurrencyCode("GBP")
->setQuoteCurrencyCode("GBP")
->setStoreToBaseRate(1.00)
->setStoreToQuoteRate(1.00)
->setBaseToGlobalRate(1.00)
->setBaseToQuoteRate(1.00);
// Overrriding base currency on Store
/** @var \Magento\Store\Model\Store $store */
$store->setBaseCurrency($directoryCurrency);
// Creating an Empty Cart
$cartId = $this->cartManagementInterface->createEmptyCart();
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->cartRepositoryInterface->get($cartId);
$quote->setStore($store);
// forcefully changing the currency for quote
$quote->setForcedCurrency($directoryCurrency);
$quote->setBaseCurrencyCode("GBP");
$quote->setGlobalCurrencyCode("GBP");
$quote->setStoreCurrencyCode("GBP");
$quote->setQuoteCurrencyCode("GBP");
$quote->setCurrency($quoteCurrency);
// Add Products
// TODO: Add Products
// Collect total and Save the qoute
$quote->collectTotals()->save();
// forcefully changing the currency for quote again as collect total made it "null"
$quote->setForcedCurrency($directoryCurrency);
$quote->setBaseCurrencyCode("GBP");
$quote->setGlobalCurrencyCode("GBP");
$quote->setStoreCurrencyCode("GBP");
$quote->setQuoteCurrencyCode("GBP");
$quote->setCurrency($quoteCurrency);
// Submi the order, and done.
/** @var \Magento\Sales\Model\Order $magentoOrder */
$magentoOrder = $this->cartManagementInterface->submit($quote)
The above code did the job but If anyone can suggest a better way to do the job, it will be highly appreciated.
Also, this may not be the standard way.