OpenCart

Класс Currency { ... }

Класс для работы с валютами

Название свойства Описание
Currency::$code private mixed $code
Currency::$currencies private mixed $currencies = array();
Тип Возвр. Описание
public mixed __construct ( $registry )
Исходный код метода:
$this->config = $registry->get('config');
$this->db = $registry->get('db');
$this->language = $registry->get('language');
$this->request = $registry->get('request');
$this->session = $registry->get('session');

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency");

foreach ($query->rows as $result) {
	$this->currencies[$result['code']] = array(
		'currency_id'   => $result['currency_id'],
		'title'         => $result['title'],
		'symbol_left'   => $result['symbol_left'],
		'symbol_right'  => $result['symbol_right'],
		'decimal_place' => $result['decimal_place'],
		'value'         => $result['value']
	);
}

if (isset($this->request->get['currency']) && (array_key_exists($this->request->get['currency'], $this->currencies))) {
	$this->set($this->request->get['currency']);
} elseif ((isset($this->session->data['currency'])) && (array_key_exists($this->session->data['currency'], $this->currencies))) {
	$this->set($this->session->data['currency']);
} elseif ((isset($this->request->cookie['currency'])) && (array_key_exists($this->request->cookie['currency'], $this->currencies))) {
	$this->set($this->request->cookie['currency']);
} else {
	$this->set($this->config->get('config_currency'));
}
public void set ( string $currency )
Исходный код метода:
$this->code = $currency;

if (!isset($this->session->data['currency']) || ($this->session->data['currency'] != $currency)) {
	$this->session->data['currency'] = $currency;
}

if (!isset($this->request->cookie['currency']) || ($this->request->cookie['currency'] != $currency)) {
	setcookie('currency', $currency, time() + 60 * 60 * 24 * 30, '/', $this->request->server['HTTP_HOST']);
}
public mixed format ( $number, $currency = '', $value = '', $format = true )
Исходный код метода:
if ($currency && $this->has($currency)) {
	$symbol_left   = $this->currencies[$currency]['symbol_left'];
	$symbol_right  = $this->currencies[$currency]['symbol_right'];
	$decimal_place = $this->currencies[$currency]['decimal_place'];
} else {
	$symbol_left   = $this->currencies[$this->code]['symbol_left'];
	$symbol_right  = $this->currencies[$this->code]['symbol_right'];
	$decimal_place = $this->currencies[$this->code]['decimal_place'];

	$currency = $this->code;
}

if ($value) {
	$value = $value;
} else {
	$value = $this->currencies[$currency]['value'];
}

if ($value) {
	$value = (float)$number * $value;
} else {
	$value = $number;
}

$string = '';

if (($symbol_left) && ($format)) {
	$string .= $symbol_left;
}

if ($format) {
	$decimal_point = $this->language->get('decimal_point');
} else {
	$decimal_point = '.';
}

if ($format) {
	$thousand_point = $this->language->get('thousand_point');
} else {
	$thousand_point = '';
}

$string .= number_format(round($value, (int)$decimal_place), (int)$decimal_place, $decimal_point, $thousand_point);

if (($symbol_right) && ($format)) {
	$string .= $symbol_right;
}

return $string;
public float convert ( float $value, string $from, string $to )
Исходный код метода:
if (isset($this->currencies[$from])) {
	$from = $this->currencies[$from]['value'];
} else {
	$from = 0;
}

if (isset($this->currencies[$to])) {
	$to = $this->currencies[$to]['value'];
} else {
	$to = 0;
}		

return $value * ($to / $from);
public int getId ( string $currency = )
Исходный код метода:
if (!$currency) {
	return $this->currencies[$this->code]['currency_id'];
} elseif ($currency && isset($this->currencies[$currency])) {
	return $this->currencies[$currency]['currency_id'];
} else {
	return 0;
}
public mixed getSymbolLeft ( $currency = '' )
Исходный код метода:
if (!$currency) {
	return $this->currencies[$this->code]['symbol_left'];
} elseif ($currency && isset($this->currencies[$currency])) {
	return $this->currencies[$currency]['symbol_left'];
} else {
	return '';
}
public mixed getSymbolRight ( $currency = '' )
Исходный код метода:
if (!$currency) {
	return $this->currencies[$this->code]['symbol_right'];
} elseif ($currency && isset($this->currencies[$currency])) {
	return $this->currencies[$currency]['symbol_right'];
} else {
	return '';
}
public mixed getDecimalPlace ( $currency = '' )
Исходный код метода:
if (!$currency) {
	return $this->currencies[$this->code]['decimal_place'];
} elseif ($currency && isset($this->currencies[$currency])) {
	return $this->currencies[$currency]['decimal_place'];
} else {
	return 0;
}
public mixed getCode ( )
Исходный код метода:
return $this->code;
public mixed getValue ( $currency = '' )
Исходный код метода:
if (!$currency) {
	return $this->currencies[$this->code]['value'];
} elseif ($currency && isset($this->currencies[$currency])) {
	return $this->currencies[$currency]['value'];
} else {
	return 0;
}
public mixed has ( $currency )
Исходный код метода:
return isset($this->currencies[$currency]);

Связанные классы:

Название класса Роль
class Config { ... } Компонент Config используется в данном классе
class DB { ... } Компонент Db используется в данном классе
class Language { ... } Компонент Language используется в данном классе
class Request { ... } Компонент Request используется в данном классе
class Session { ... } Компонент Session используется в данном классе

Комментарии