Skip to content

How to Switch Currency in Magento2

I am creating mobileApp using APIs i used my custom API to return products and used the the function that return price according to the currencycode given below is the code

public function getPriceByCurrency($price)
{

    $rate = $this->_currencyFactory->create()->load($this->apiHelper-
    >getStoreBaseCurrency($this->_storeId))->getAnyRate($this->_currencyCode);

    $itemAmount = number_format(($price * $rate), 2);
    return $itemAmount;
}

However it returns the dedicated price but how can i add to cart using the given currency code i am using the APIs endpoint /V1/carts/mine/items

Please Help Thanks in Advanced…