/*public static function getCurrency() {
if(self::$currency === false){
$session = Factory::getSession();
$currencyId = $session->get('currency', 0, 'phocaCart');
if ((int)$currencyId < 1) {
$currencyId = self::getDefaultCurrency();
}
$db = Factory::getDBO();
$query = ' SELECT a.* FROM #__phocacart_currencies AS a'
.' WHERE a.id = '.(int)$currencyId;
$db->setQuery($query);
$c = $db->loadObject();
if (!empty($c)) {
self::$currency = $c;
} else {
self::$currency = false;
}
}
return self::$currency;
}*/
public static function getCurrency($id = 0, $orderId = 0)
{
// Order currency is never stored in session
// so we use id instead of key
$session = Factory::getSession();
if ($id == 0) {
$id = $session->get('currency', 0, 'phocaCart');
// check only session currencies, not database - as they can be order currencies
$isValid = self::isCurrencyValid($id);
if (!$isValid) {
$id = 0;
}
}
if ((int) $id < 1) {
$id = self::getDefaultCurrency();
$session->set('currency', (int) $id, 'phocaCart');
}
$id = (int) $id;
// Price can be different for each currency and order
// So there is a key which identifies default currency, other currency, default currency in order, other currency in order
// one currency can have different exchange rates in order history, so two orders can have same currency but different exchange rate
$key = base64_encode(serialize((int) $id . ':' . (int) $orderId));
if (!array_key_exists((string) $key, self::$currency)) {
$db = Factory::getDBO();
$query = ' SELECT a.* FROM #__phocacart_currencies AS a' . ' WHERE a.id = ' . (int) $id . ' ORDER BY a.id';
$db->setQuery($query);
$c = $db->loadObject();
if (!empty($c)) {
self::$currency[$key] = $c;
} else {
self::$currency[$key] = false;
}
}
return self::$currency[$key];
}