Back to PhocacartPrice class

Method setCurrency

public
setCurrency
(mixed $id = 0, mixed $orderId = 0)

Method setCurrency - Source code

public function setCurrency($id = 0, $orderId = 0)
{
    // 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)) {
        $app = Factory::getApplication();
        $paramsC = PhocacartUtils::getComponentParameters();
        $exchange_rate_order = $paramsC->get('exchange_rate_order', 0);
        $currencyOrder = false;
        if ((int) $orderId > 0) {
            $currencyOrder = self::getCurrencyAndRateByOrder($orderId);
        }
        // 1) change the currency ID by order
        if (isset($currencyOrder->currency_id)) {
            $id = $currencyOrder->currency_id;
            $key = base64_encode(serialize((int) $id . ':' . (int) $orderId));
        }
        if ((int) $id > 0) {
            self::$currency[$key] = PhocacartCurrency::getCurrency((int) $id, (int) $orderId);
        } else {
            self::$currency[$key] = PhocacartCurrency::getCurrency(0, (int) $orderId);
        }
        // 1) change the currency exchange rate by order
        if (isset($currencyOrder->currency_exchange_rate) && $exchange_rate_order == 0) {
            self::$currency[$key]->exchange_rate = $currencyOrder->currency_exchange_rate;
        }
    }
    if (!empty(self::$currency[$key])) {
        $this->price_decimals = self::$currency[$key]->price_decimals;
        $this->price_dec_symbol = self::$currency[$key]->price_dec_symbol;
        $this->price_thousands_sep = self::$currency[$key]->price_thousands_sep;
        $this->price_format = self::$currency[$key]->price_format;
        $this->price_currency_symbol = self::$currency[$key]->price_currency_symbol;
        $this->price_currency_title = self::$currency[$key]->title;
        $this->price_prefix = self::$currency[$key]->price_prefix;
        $this->price_suffix = self::$currency[$key]->price_suffix;
        $this->exchange_rate = self::$currency[$key]->exchange_rate;
        $this->currency_id = self::$currency[$key]->id;
    }
}