About the currency function on the opencart





currency:
set($currency):
Set the currency to be used in overall site.
public function set($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']);
}
}
format($number, $currency = '', $value = '', $format = TRUE):

public function 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 = $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;
}
convert($value, $from, $to):
Convert the given value from once currency to other. The parameters are $value means of what amount and $from means of which currency and $to mean to which currency is the value to be converted.
public function convert($value, $from, $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);
}
getId():
Returns the currency ID.
public function getId() {
return $this->currencies[$this->code]['currency_id'];
}
getCode():
Returns the currency code.
public function getCode() {
return $this->code;
}
getValue($currency):
If the currency is set then returns the value nor it will return zero.
public function getValue($currency) {
if (isset($this->currencies[$currency])) {
return $this->currencies[$currency]['value'];
} else {
return 0;
}
}
has($currency):
Whether the request currency is available or not.
public function has($currency) {
return isset($this->currencies[$currency]);
}

currency converting function, currency library function, converting currency function in class of opencart

Comments

Popular posts from this blog

Cloudflare Settings for Marketing Websites

Collection of customer function and its description in Opencart