directory

package
v0.0.0-...-02de949 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package directory provides features for currencies, currency rates, conversion of prices to a specified currency format, countries and regions.

@todo think about: https://github.com/mledoze/countries

Index

Constants

This section is empty.

Variables

View Source
var TableCollection csdb.TableManager

TableCollection handles all tables and its columns. init() in generated Go file will set the value.

Functions

func NewConfigStructure

func NewConfigStructure() (config.Sections, error)

NewConfigStructure global configuration structure for this package. Used in frontend (to display the user all the settings) and in backend (scope checks and default values). See the source code of this function for the overall available sections, groups and fields.

Types

type ConfigCurrency

type ConfigCurrency struct {
	cfgmodel.Str
}

ConfigCurrency currency type for the configuration based on text/currency pkg.

func NewConfigCurrency

func NewConfigCurrency(path string, opts ...cfgmodel.Option) ConfigCurrency

NewConfigCurrency creates a new currency configuration type.

func (ConfigCurrency) Get

func (cc ConfigCurrency) Get(sg config.Scoped) (cur Currency, err error)

Get tries to retrieve a currency considering the scope

func (ConfigCurrency) GetDefault

func (cc ConfigCurrency) GetDefault(sg config.Getter) (cur Currency, err error)

GetDefault returns the default currency without considering the scope.

func (ConfigCurrency) Write

func (cc ConfigCurrency) Write(w config.Setter, v Currency, s scope.Type, id int64) error

Writes a currency to the configuration storage.

type Currency

type Currency struct {
	currency.Unit
}

Currency represents a corestore currency type which may add more features.

func MustNewCurrencyISO

func MustNewCurrencyISO(iso string) Currency

MustNewCurrencyISO same as NewCurrencyISO() but panics on error.

func NewCurrencyISO

func NewCurrencyISO(iso string) (c Currency, err error)

NewCurrencyISO creates a new Currency by parsing a 3-letter ISO 4217 currency code. It returns an error if s is not well-formed or not a recognized currency code.

type PkgBackend

type PkgBackend struct {
	cfgmodel.PkgBackend

	// CurrencyOptionsBase => Base Currency.
	// Base currency is used for all online payment transactions. If you have more
	// than one store view, the base currency scope is defined by the catalog
	// price scope ("Catalog" > "Price" > "Catalog Price Scope").
	// Path: currency/options/base
	// BackendModel: Magento\Config\Model\Config\Backend\Currency\Base
	// SourceModel: Magento\Config\Model\Config\Source\Locale\Currency
	CurrencyOptionsBase ConfigCurrency

	// CurrencyOptionsDefault => Default Display Currency.
	// Path: currency/options/default
	// BackendModel: Magento\Config\Model\Config\Backend\Currency\DefaultCurrency
	// SourceModel: Magento\Config\Model\Config\Source\Locale\Currency
	CurrencyOptionsDefault ConfigCurrency

	// CurrencyOptionsAllow => Allowed Currencies.
	// Path: currency/options/allow
	// BackendModel: Magento\Config\Model\Config\Backend\Currency\Allow
	// SourceModel: Magento\Config\Model\Config\Source\Locale\Currency
	CurrencyOptionsAllow cfgmodel.StringCSV

	// CurrencyWebservicexTimeout => Connection Timeout in Seconds.
	// Path: currency/webservicex/timeout
	CurrencyWebservicexTimeout cfgmodel.Str

	// CurrencyImportEnabled => Enabled.
	// Path: currency/import/enabled
	// SourceModel: Magento\Config\Model\Config\Source\Yesno
	CurrencyImportEnabled cfgmodel.Bool

	// CurrencyImportErrorEmail => Error Email Recipient.
	// Path: currency/import/error_email
	CurrencyImportErrorEmail cfgmodel.Str

	// CurrencyImportErrorEmailIdentity => Error Email Sender.
	// Path: currency/import/error_email_identity
	// SourceModel: Magento\Config\Model\Config\Source\Email\Identity
	CurrencyImportErrorEmailIdentity cfgmodel.Str

	// CurrencyImportErrorEmailTemplate => Error Email Template.
	// Email template chosen based on theme fallback when "Default" option is
	// selected.
	// Path: currency/import/error_email_template
	// SourceModel: Magento\Config\Model\Config\Source\Email\Template
	CurrencyImportErrorEmailTemplate cfgmodel.Str

	// CurrencyImportFrequency => Frequency.
	// Path: currency/import/frequency
	// SourceModel: Magento\Cron\Model\Config\Source\Frequency
	CurrencyImportFrequency cfgmodel.Str

	// CurrencyImportService => Service.
	// Path: currency/import/service
	// BackendModel: Magento\Config\Model\Config\Backend\Currency\Cron
	// SourceModel: Magento\Directory\Model\Currency\Import\Source\Service
	CurrencyImportService cfgmodel.Str

	// CurrencyImportTime => Start Time.
	// Path: currency/import/time
	CurrencyImportTime cfgmodel.Str

	// SystemCurrencyInstalled => Installed Currencies.
	// Defines all installed and available currencies.
	// Path: system/currency/installed
	// BackendModel: Magento\Config\Model\Config\Backend\Locale
	// SourceModel: Magento\Config\Model\Config\Source\Locale\Currency\All
	//
	// TODO:
	//	// SourceCurrencyAll used in Path: `system/currency/installed`,
	//func (sca *SourceCurrencyAll) Options() source.Slice {
	//	// Magento\Framework\Locale\Resolver
	//	// 1. get all allowed currencies from the config
	//	// 2. get slice of currency code and currency name and filter out all not-allowed currencies
	//	// grep locale from general/locale/code scope::store for the current store ID
	//	// the store locale greps the currencies from http://php.net/manual/en/class.resourcebundle.php
	//	// in the correct language
	//	storeLocale, err := sca.mc.Config.String(config.Path(PathDefaultLocale), config.ScopeStore(sca.mc.ScopeStore.StoreID()))
	//	return nil
	//}
	SystemCurrencyInstalled cfgmodel.StringCSV

	// GeneralCountryOptionalZipCountries => Zip/Postal Code is Optional for.
	// Path: general/country/optional_zip_countries
	// SourceModel: Magento\Directory\Model\Config\Source\Country
	GeneralCountryOptionalZipCountries cfgmodel.StringCSV

	// PathGeneralCountryAllow per store view allowed list of countries
	// SourceModel: Magento\Directory\Model\Config\Source\Country
	GeneralCountryAllow cfgmodel.StringCSV

	// PathGeneralCountryDefault returns the store view default configured country code.
	// SourceModel: Magento\Directory\Model\Config\Source\Country
	GeneralCountryDefault cfgmodel.Str

	// PathGeneralCountryEuCountries => European Union Countries.
	// SourceModel: Magento\Directory\Model\Config\Source\Country
	GeneralCountryEuCountries cfgmodel.StringCSV

	// PathGeneralCountryDestinations contains codes of the most used countries.
	// Such countries can be shown on the top of the country list.
	// SourceModel: Magento\Directory\Model\Config\Source\Country
	GeneralCountryDestinations cfgmodel.StringCSV

	// PathGeneralLocaleTimezone => Timezone.
	// BackendModel: Magento\Config\Model\Config\Backend\Locale\Timezone
	// SourceModel: Magento\Config\Model\Config\Source\Locale\Timezone
	GeneralLocaleTimezone cfgmodel.Str

	// PathGeneralLocaleCode => Locale.
	// SourceModel: Magento\Config\Model\Config\Source\Locale
	GeneralLocaleCode cfgmodel.Str

	// PathGeneralLocaleFirstday => First Day of Week.
	// SourceModel: Magento\Config\Model\Config\Source\Locale\Weekdays
	GeneralLocaleFirstday cfgmodel.Str

	// PathGeneralLocaleWeekend => Weekend Days.
	// SourceModel: Magento\Config\Model\Config\Source\Locale\Weekdays
	GeneralLocaleWeekend cfgmodel.StringCSV

	// GeneralRegionStateRequired => State is Required for.
	// Path: general/region/state_required
	// SourceModel: Magento\Directory\Model\Config\Source\Country
	GeneralRegionStateRequired cfgmodel.StringCSV

	// GeneralRegionDisplayAll => Allow to Choose State if It is Optional for Country.
	// Path: general/region/display_all
	// SourceModel: Magento\Config\Model\Config\Source\Yesno
	GeneralRegionDisplayAll cfgmodel.Bool

	// GeneralLocaleWeightUnit => Weight Unit.
	// Path: general/locale/weight_unit
	// SourceModel: Magento\Directory\Model\Config\Source\WeightUnit
	GeneralLocaleWeightUnit cfgmodel.Str
}

PkgBackend just exported for the sake of documentation. See fields for more information. The PkgBackend handles the reading and writing of configuration values within this package.

func NewBackend

func NewBackend(cfgStruct element.Sections) *PkgBackend

NewBackend initializes the global configuration models containing the cfgpath.Route variable to the appropriate entry. The function Load() will be executed to apply the Sections to all models. See Load() for more details.

func (*PkgBackend) InitCountry

func (be *PkgBackend) InitCountry(dbrsess dbr.SessionRunner, o *PkgSource) error

InitCountry should run every time your service initializes or a value in the database changes.

func (*PkgBackend) InitCurrency

func (be *PkgBackend) InitCurrency(dbrSess dbr.SessionRunner, o *PkgSource) error

InitCurrency sets the Options() on all PathCurrency* configuration global variables.

func (*PkgBackend) InitSources

func (be *PkgBackend) InitSources(dbrSess dbr.SessionRunner) (*PkgSource, error)

InitSources initializes the global variable Sources in all models. Changing a cfgsource.Slice here affects all other models.

func (*PkgBackend) Load

func (pp *PkgBackend) Load(cfgStruct element.Sections) *PkgBackend

Load creates the configuration models for each PkgBackend field. Internal mutex will protect the fields during loading. The argument Sections will be applied to all models.

type PkgSource

type PkgSource struct {
	sync.Mutex
	// Currency contains all possible currencies on this planet.
	Currency _cfgsource.Slice
	// Country should contain all countries
	Country _cfgsource.Slice
}

PkgSource a container for all available cfgsource.Slice within this package. These sources will be applied to the models See fields for more information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL