Example #1
0
// BaseCurrencyCode retrieves application base currency code
func BaseCurrencyCode(cr config.Reader) (language.Currency, error) {
	base, err := cr.GetString(config.Path(PathCurrencyBase))
	if config.NotKeyNotFoundError(err) {
		return language.Currency{}, err
	}
	return language.ParseCurrency(base)
}
Example #2
0
// @todo
func (w *Website) BaseCurrencyCode() (language.Currency, error) {
	var c string
	if w.ConfigString(PathPriceScope) == PriceScopeGlobal {
		c = w.cr.GetString(config.Path(directory.PathCurrencyBase))
	} else {
		c = w.ConfigString(directory.PathCurrencyBase)
	}
	return language.ParseCurrency(c)
}
Example #3
0
// SetCurrencyISO parses a 3-letter ISO 4217 code and sets it to the Currency
// struct. If parsing fails errors will be logged and falls back to DefaultCurrencyName.
// Calling this function sets also the CurrencySign() to the at the moment
// 3-letter ISO code. (Missing feature in text/language package)
// This function is called in NewCurrency().
func SetCurrencyISO(cur string) CurrencyOptions {
	return func(c *Currency) CurrencyOptions {
		previous := c.ISO.String()
		lc, err := language.ParseCurrency(cur)
		if err != nil {
			if log.IsTrace() {
				log.Trace("i18n.CurrencyISO.ParseCurrency.error", "err", err, "cur", cur)
			}
			log.Error("i18n.CurrencyISO.ParseCurrency", "err", err, "cur", cur)
			lc = language.MustParseCurrency(DefaultCurrencyName)
		}
		c.ISO = lc
		SetCurrencySign([]byte(lc.String()))(c)
		return SetCurrencyISO(previous)
	}
}
Example #4
0
// BaseCurrencyCode retrieves application base currency code
func BaseCurrencyCode(cr config.Reader) (language.Currency, error) {
	return language.ParseCurrency(cr.GetString(config.Path(PathCurrencyBase)))
}