Documentation ¶
Overview ¶
Package store implements the handling of websites, groups and stores.
The following shows a hierarchical diagram of the structure:
+---------------------+ | Website | | ID <-----------------+---+ | Code | | | +----+ Default Group ID | | | | | Is Default | | | | +---------------------+ | | | | | | +----------------------+ | | | | Group | | | +------> ID | | | | Website ID +-----------+ | | Root Category ID | | +------+ Default Store ID | | | +----------------------+ | | | | +---------------+ | | | Store | | | | ID | | | | Code | | +--------> Group ID | | | Website ID +-------------+ | Is Active | +---------------+ http://asciiflow.com
Those three objects also represents the tables in the database.
Sub package Scope ¶
The subpackage scope depends on these structure except that the group has been removed and a default scope has been introduced.
More explanation @todo Read more: http://magento-quickies.alanstorm.com/post/146610004255/taming-magento-2s-scope https://cyrillschumacher.com/2015/04/20/magento2-stores-and-scopes/
Index ¶
- Constants
- Variables
- func CodeIsValid(c string) error
- type CodeProcessor
- type ExtractGroup
- type ExtractStore
- type ExtractWebsite
- type Finder
- type Group
- func (g Group) DefaultStore() (Store, error)
- func (g Group) DefaultStoreID() int64
- func (g Group) ID() int64
- func (g Group) MarshalJSON() ([]byte, error)
- func (g Group) Name() string
- func (g *Group) SetWebsiteStores(cfg config.Getter, w *TableWebsite, tss TableStoreSlice) error
- func (g Group) Validate() error
- func (g Group) WebsiteID() int64
- type GroupSlice
- func (gs GroupSlice) Each(f func(Group)) GroupSlice
- func (gs GroupSlice) Filter(f func(Group) bool) GroupSlice
- func (gs GroupSlice) FindByID(id int64) (Group, bool)
- func (gs GroupSlice) IDs() []int64
- func (gs GroupSlice) Len() int
- func (gs *GroupSlice) Less(i, j int) bool
- func (gs GroupSlice) Map(f func(*Group)) GroupSlice
- func (gs *GroupSlice) Sort() *GroupSlice
- func (gs *GroupSlice) Swap(i, j int)
- type Option
- type Service
- func (s *Service) AllowedStores(runMode scope.TypeID) (StoreSlice, error)
- func (s *Service) ClearCache()
- func (s *Service) DefaultStoreID(runMode scope.TypeID) (storeID, websiteID int64, _ error)
- func (s *Service) DefaultStoreView() (Store, error)
- func (s *Service) Group(id int64) (Group, error)
- func (s *Service) Groups() GroupSlice
- func (s *Service) HasSingleStore() bool
- func (s *Service) IsAllowedStoreID(runMode scope.TypeID, storeID int64) (isAllowed bool, storeCode string, _ error)
- func (s *Service) IsCacheEmpty() bool
- func (s *Service) IsSingleStoreMode(cfg config.Scoped) (bool, error)
- func (s *Service) LoadFromDB(dbrSess dbr.SessionRunner, cbs ...dbr.SelectCb) error
- func (s *Service) Store(id int64) (Store, error)
- func (s *Service) StoreIDbyCode(runMode scope.TypeID, storeCode string) (storeID, websiteID int64, err error)
- func (s *Service) Stores() StoreSlice
- func (s *Service) Website(id int64) (Website, error)
- func (s *Service) Websites() WebsiteSlice
- type Store
- func (s Store) Code() string
- func (s Store) GroupID() int64
- func (s Store) ID() int64
- func (s Store) IsActive() bool
- func (s Store) MarshalJSON() ([]byte, error)
- func (s Store) MarshalLog(kv log.KeyValuer) error
- func (s Store) Name() string
- func (s Store) RootCategoryID() int64
- func (s *Store) SetWebsiteGroup(cfg config.Getter, tw *TableWebsite, tg *TableGroup) error
- func (s Store) String() string
- func (s Store) Validate() (err error)
- func (s Store) WebsiteID() int64
- type StoreSlice
- func (ss StoreSlice) ActiveCodes() []string
- func (ss StoreSlice) ActiveIDs() []int64
- func (ss StoreSlice) Codes() []string
- func (ss StoreSlice) Each(f func(Store)) StoreSlice
- func (ss StoreSlice) Filter(f func(Store) bool) StoreSlice
- func (ss StoreSlice) FindByID(id int64) (Store, bool)
- func (ss StoreSlice) FindOne(f func(Store) bool) (Store, bool)
- func (ss StoreSlice) IDs() []int64
- func (ss StoreSlice) Len() int
- func (ss *StoreSlice) Less(i, j int) bool
- func (ss StoreSlice) Map(f func(*Store)) StoreSlice
- func (ss *StoreSlice) Sort() *StoreSlice
- func (ss *StoreSlice) Swap(i, j int)
- type TableGroup
- type TableGroupSlice
- func (s *TableGroupSlice) Append(n ...*TableGroup)
- func (s *TableGroupSlice) Cut(i, j int)
- func (s *TableGroupSlice) Delete(i int)
- func (s TableGroupSlice) Each(f func(*TableGroup)) TableGroupSlice
- func (s TableGroupSlice) Extract() ExtractGroup
- func (s TableGroupSlice) Filter(f func(*TableGroup) bool) TableGroupSlice
- func (s TableGroupSlice) FilterNot(f func(*TableGroup) bool) TableGroupSlice
- func (s TableGroupSlice) FilterThis(f func(*TableGroup) bool) TableGroupSlice
- func (s TableGroupSlice) FindByGroupID(group_id int64) (match *TableGroup, found bool)
- func (s *TableGroupSlice) Insert(n *TableGroup, i int)
- func (s TableGroupSlice) Len() int
- func (s TableGroupSlice) LessPK(i, j *TableGroup) bool
- func (s *TableGroupSlice) Prepend(n *TableGroup)
- func (s *TableGroupSlice) SQLDelete(dbrSess dbr.SessionRunner, cbs ...dbr.DeleteCb) (int, error)
- func (s *TableGroupSlice) SQLInsert(dbrSess dbr.SessionRunner, cbs ...dbr.InsertCb) (int, error)
- func (s *TableGroupSlice) SQLSelect(dbrSess dbr.SessionRunner, cbs ...dbr.SelectCb) (int, error)
- func (s *TableGroupSlice) SQLUpdate(dbrSess dbr.SessionRunner, cbs ...dbr.UpdateCb) (int, error)
- func (s TableGroupSlice) Sort(less func(*TableGroup, *TableGroup) bool)
- func (s TableGroupSlice) Swap(i, j int)
- type TableStore
- type TableStoreSlice
- func (s *TableStoreSlice) Append(n ...*TableStore)
- func (s *TableStoreSlice) Cut(i, j int)
- func (s *TableStoreSlice) Delete(i int)
- func (s TableStoreSlice) Each(f func(*TableStore)) TableStoreSlice
- func (s TableStoreSlice) Extract() ExtractStore
- func (s TableStoreSlice) Filter(f func(*TableStore) bool) TableStoreSlice
- func (s TableStoreSlice) FilterByGroupID(id int64) TableStoreSlice
- func (s TableStoreSlice) FilterByWebsiteID(id int64) TableStoreSlice
- func (s TableStoreSlice) FilterNot(f func(*TableStore) bool) TableStoreSlice
- func (s TableStoreSlice) FilterThis(f func(*TableStore) bool) TableStoreSlice
- func (s TableStoreSlice) FindByCode(code string) (match *TableStore, found bool)
- func (s TableStoreSlice) FindByStoreID(store_id int64) (match *TableStore, found bool)
- func (s *TableStoreSlice) Insert(n *TableStore, i int)
- func (s TableStoreSlice) Len() int
- func (s TableStoreSlice) LessPK(i, j *TableStore) bool
- func (s *TableStoreSlice) Prepend(n *TableStore)
- func (s *TableStoreSlice) SQLDelete(dbrSess dbr.SessionRunner, cbs ...dbr.DeleteCb) (int, error)
- func (s *TableStoreSlice) SQLInsert(dbrSess dbr.SessionRunner, cbs ...dbr.InsertCb) (int, error)
- func (s *TableStoreSlice) SQLSelect(dbrSess dbr.SessionRunner, cbs ...dbr.SelectCb) (int, error)
- func (s *TableStoreSlice) SQLUpdate(dbrSess dbr.SessionRunner, cbs ...dbr.UpdateCb) (int, error)
- func (s TableStoreSlice) Sort(less func(*TableStore, *TableStore) bool)
- func (s TableStoreSlice) Swap(i, j int)
- type TableWebsite
- type TableWebsiteSlice
- func (s *TableWebsiteSlice) Append(n ...*TableWebsite)
- func (s *TableWebsiteSlice) Cut(i, j int)
- func (s *TableWebsiteSlice) Delete(i int)
- func (s TableWebsiteSlice) Each(f func(*TableWebsite)) TableWebsiteSlice
- func (s TableWebsiteSlice) Extract() ExtractWebsite
- func (s TableWebsiteSlice) Filter(f func(*TableWebsite) bool) TableWebsiteSlice
- func (s TableWebsiteSlice) FilterNot(f func(*TableWebsite) bool) TableWebsiteSlice
- func (s TableWebsiteSlice) FilterThis(f func(*TableWebsite) bool) TableWebsiteSlice
- func (s TableWebsiteSlice) FindByCode(code string) (match *TableWebsite, found bool)
- func (s TableWebsiteSlice) FindByWebsiteID(website_id int64) (match *TableWebsite, found bool)
- func (s *TableWebsiteSlice) Insert(n *TableWebsite, i int)
- func (s TableWebsiteSlice) Len() int
- func (s TableWebsiteSlice) LessPK(i, j *TableWebsite) bool
- func (s *TableWebsiteSlice) Prepend(n *TableWebsite)
- func (s *TableWebsiteSlice) SQLDelete(dbrSess dbr.SessionRunner, cbs ...dbr.DeleteCb) (int, error)
- func (s *TableWebsiteSlice) SQLInsert(dbrSess dbr.SessionRunner, cbs ...dbr.InsertCb) (int, error)
- func (s *TableWebsiteSlice) SQLSelect(dbrSess dbr.SessionRunner, cbs ...dbr.SelectCb) (int, error)
- func (s *TableWebsiteSlice) SQLUpdate(dbrSess dbr.SessionRunner, cbs ...dbr.UpdateCb) (int, error)
- func (s TableWebsiteSlice) Sort(less func(*TableWebsite, *TableWebsite) bool)
- func (s TableWebsiteSlice) Swap(i, j int)
- type Tree
- type Website
- func (w Website) Code() string
- func (w Website) DefaultGroup() (Group, error)
- func (w Website) DefaultGroupID() int64
- func (w Website) DefaultStore() (Store, error)
- func (w Website) DefaultStoreID() (int64, error)
- func (w Website) ID() int64
- func (w Website) MarshalJSON() ([]byte, error)
- func (w Website) Name() string
- func (w *Website) SetGroupsStores(tgs TableGroupSlice, tss TableStoreSlice) error
- func (w Website) Validate() error
- type WebsiteSlice
- func (ws WebsiteSlice) Codes() []string
- func (ws WebsiteSlice) Default() (Website, error)
- func (ws WebsiteSlice) Each(f func(Website)) WebsiteSlice
- func (ws WebsiteSlice) Filter(f func(Website) bool) WebsiteSlice
- func (ws WebsiteSlice) FindByID(id int64) (Website, bool)
- func (ws WebsiteSlice) IDs() []int64
- func (ws WebsiteSlice) Len() int
- func (ws WebsiteSlice) Less(i, j int) bool
- func (ws WebsiteSlice) Map(f func(*Website)) WebsiteSlice
- func (ws *WebsiteSlice) Sort() *WebsiteSlice
- func (ws *WebsiteSlice) Swap(i, j int)
- func (ws WebsiteSlice) Tree() Tree
Constants ¶
const ( TableIndexStore = iota // Table: store TableIndexGroup // Table: store_group TableIndexWebsite // Table: store_website TableIndexZZZ // the maximum index, which is not available. )
TableIndex... is the index to a table. These constants are guaranteed to stay the same for all Magento versions. Please access a table via this constant instead of the raw table name. TableIndex iotas must start with 0.
const CodeFieldName = `store`
CodeFieldName defines the filed name where store code has been saved. Used in Cookies and JSON Web Tokens (JWT) to identify an active store besides from the default loaded store.
const CodeMaxLen = 32
CodeMaxLen defines the overall maximum length a store code can have.
const CodeURLFieldName = `___store`
CodeURLFieldName name of the GET parameter to set a new store in a current website/group context/request.
const DefaultStoreID int64 = 0
DefaultStoreID is always 0.
Variables ¶
var TableCollection *csdb.Tables
TableCollection handles all tables and its columns. init() in generated Go file will set the value.
Functions ¶
func CodeIsValid ¶
CodeIsValid checks if a store code is valid. Returns an ErrStoreCodeEmpty or an ErrStoreCodeInvalid if the first letter is not a-zA-Z and followed by a-zA-Z0-9_ or store code length is greater than 32 characters. Error behaviour: NotValid
Types ¶
type CodeProcessor ¶
type CodeProcessor interface { // FromRequest returns the valid non-empty store code. Returns an empty // store code on all other cases. FromRequest(runMode scope.TypeID, req *http.Request) (code string) // ProcessDenied gets called in the middleware WithRunMode whenever a store // ID isn't allowed to proceed. The variable newStoreID reflects the denied // store ID. The ResponseWriter and Request variables can be used for // additional information writing and extracting. The error Handler will // always be called. ProcessDenied(runMode scope.TypeID, oldStoreID, newStoreID int64, w http.ResponseWriter, r *http.Request) // ProcessAllowed enables to adjust the ResponseWriter based on the new // store ID. The variable newStoreID contains the new ID, which can also be // 0. The code is guaranteed to be not empty, a valid store code, and always // points to an existing active store. The ResponseWriter and Request // variables can be used for additional information writing and extracting. // The next Handler in the chain will after this function be called. ProcessAllowed(runMode scope.TypeID, oldStoreID, newStoreID int64, newStoreCode string, w http.ResponseWriter, r *http.Request) }
CodeProcessor gets used in the middleware WithRunMode() to extract a store code from a Request and modify the response; for example setting cookies to persists the selected store.
type ExtractGroup ¶
type ExtractGroup struct { GroupID func() []int64 WebsiteID func() []int64 Name func() []string RootCategoryID func() []int64 DefaultStoreID func() []int64 }
ExtractGroup functions for extracting fields from Group slice. Generated via tableToStruct.
type ExtractStore ¶
type ExtractStore struct { StoreID func() []int64 Code func() []string WebsiteID func() []int64 GroupID func() []int64 Name func() []string SortOrder func() []int64 IsActive func() []bool }
ExtractStore functions for extracting fields from Store slice. Generated via tableToStruct.
type ExtractWebsite ¶
type ExtractWebsite struct { WebsiteID func() []int64 Code func() []string Name func() []string SortOrder func() []int64 DefaultGroupID func() []int64 IsDefault func() []bool }
ExtractWebsite functions for extracting fields from Website slice. Generated via tableToStruct.
type Finder ¶
type Finder interface { // DefaultStoreID returns the default active store ID and its website ID // depending on the run mode. Error behaviour is mostly of type NotValid. DefaultStoreID(runMode scope.TypeID) (storeID, websiteID int64, err error) // StoreIDbyCode returns, depending on the runMode, for a storeCode its // active store ID and its website ID. An empty runMode hash falls back to // select the default website, with its default group, and the slice of // default stores. A not-found error behaviour gets returned if the code // cannot be found. If the runMode equals to scope.DefaultTypeID, the // returned ID is always 0 and error is nil. StoreIDbyCode(runMode scope.TypeID, storeCode string) (storeID, websiteID int64, err error) }
Finder depends on the runMode from package scope and finds the active store depending on the run mode. The Hash argument will be provided via scope.RunMode type or the scope.FromContextRunMode(ctx) function. runMode is named in Mage world: MAGE_RUN_CODE and MAGE_RUN_TYPE. The MAGE_RUN_TYPE can be either website or store scope and MAGE_RUN_CODE any defined website or store code from the database. In our case we must pass an ID and not a code string.
type Group ¶
type Group struct { // Data contains the raw group data. Cannot be nil Data *TableGroup // Stores contains a slice to all stores associated to this group. Can be nil. Stores StoreSlice // Website contains the Website which belongs to this group. Website Website }
Group defines the root category id and default store id for a set of stores. A group is assigned to one website and a group can have multiple stores. A group does not have any kind of configuration setting but hands down the BaseConfig to the stores and the Website.
func MustNewGroup ¶
func MustNewGroup(cfg config.Getter, tg *TableGroup, tw *TableWebsite, tss TableStoreSlice) Group
MustNewGroup creates a NewGroup but panics on error.
func NewGroup ¶
func NewGroup(cfg config.Getter, tg *TableGroup, tw *TableWebsite, tss TableStoreSlice) (Group, error)
NewGroup creates a new Group with its depended Website and Stores.
func (Group) DefaultStore ¶
DefaultStore returns the default Store or an error of behaviour NotFound.
func (Group) DefaultStoreID ¶
DefaultStoreID returns the default store ID. If Data is nil returns -1.
func (Group) MarshalJSON ¶
MarshalJSON satisfies interface for JSON marshalling. The TableWebsite struct will be encoded to JSON.
func (*Group) SetWebsiteStores ¶
func (g *Group) SetWebsiteStores(cfg config.Getter, w *TableWebsite, tss TableStoreSlice) error
SetWebsiteStores applies a raw website and multiple stores belonging to the group. Validates the internal integrity afterwards.
type GroupSlice ¶
type GroupSlice []Group
GroupSlice collection of Group. GroupSlice has some nice method receivers.
func (GroupSlice) Each ¶
func (gs GroupSlice) Each(f func(Group)) GroupSlice
Each applies predicate f on each item within the slice without changing it.
func (GroupSlice) Filter ¶
func (gs GroupSlice) Filter(f func(Group) bool) GroupSlice
Filter returns a new slice filtered by predicate f
func (GroupSlice) FindByID ¶
func (gs GroupSlice) FindByID(id int64) (Group, bool)
FindByID filters by Id, returns the website and true if found.
func (*GroupSlice) Less ¶
func (gs *GroupSlice) Less(i, j int) bool
Less checks the Data field GroupID if index i < index j.
func (GroupSlice) Map ¶
func (gs GroupSlice) Map(f func(*Group)) GroupSlice
Map applies predicate f on each item within the slice and allows changing it.
func (*GroupSlice) Swap ¶
func (gs *GroupSlice) Swap(i, j int)
Swap swaps positions within the slice
type Option ¶
type Option func(*factory) error
Option type to pass options to the service type.
func WithTableGroups ¶
func WithTableGroups(tgs ...*TableGroup) Option
WithTableGroups appends the data from the DB table groups to the service.
func WithTableStores ¶
func WithTableStores(tss ...*TableStore) Option
WithTableStores appends the data from the DB table store to the service.
func WithTableWebsites ¶
func WithTableWebsites(tws ...*TableWebsite) Option
WithTableWebsites appends the data from the DB table website to the service.
type Service ¶
type Service struct { // SingleStoreModeEnabled default value true to enable globally single store // mode but might get overwritten via a store scope configuration flag. If // this flag is false, single store mode cannot be enabled at all. SingleStoreModeEnabled bool // BackendSingleStore contains the path to the configuration flag which // limits the Service to a single store Default value: false. Setting this // value is optional. BackendSingleStore cfgmodel.Bool // contains filtered or unexported fields }
Service represents type which handles the underlying storage and takes care of the default stores. A Service is bound a specific scope.Scope. Depending on the scope it is possible or not to switch stores. A Service contains also a config.Getter which gets passed to the scope of a Store(), Group() or Website() so that you always have the possibility to access a scoped based configuration value. This Service uses three internal maps to cache Websites, Groups and Stores.
func MustNewService ¶
MustNewService same as NewService, but panics on error.
func NewService ¶
NewService creates a new store Service which handles websites, groups and stores. You must either provide the functional options or call LoadFromDB() to setup the internal cache.
func (*Service) AllowedStores ¶
func (s *Service) AllowedStores(runMode scope.TypeID) (StoreSlice, error)
AllowedStores creates a new slice containing all active stores depending on the current runMode. The returned slice and its pointers are owned by the callee.
func (*Service) ClearCache ¶
func (s *Service) ClearCache()
ClearCache resets the internal caches which stores the pointers to Websites, Groups or Stores. The ReInit() also uses this method to clear caches before the Storage gets reloaded.
func (*Service) DefaultStoreID ¶
DefaultStoreID returns the default active store ID depending on the run mode. Error behaviour is mostly of type NotValid.
func (*Service) DefaultStoreView ¶
DefaultStoreView returns the overall default store view.
func (*Service) Group ¶
Group returns a cached Group which contains all related stores and its website.
func (*Service) Groups ¶
func (s *Service) Groups() GroupSlice
Groups returns a cached slice containing all Groups with its associated stores and websites. You shall not modify the returned slice.
func (*Service) HasSingleStore ¶
HasSingleStore checks if we only have one store view besides the admin store view. Mostly used in models to the set store id and in blocks to not display the e.g. store switch. Global flag.
func (*Service) IsAllowedStoreID ¶
func (s *Service) IsAllowedStoreID(runMode scope.TypeID, storeID int64) (isAllowed bool, storeCode string, _ error)
IsAllowedStoreID checks if the store ID is allowed within the runMode. Returns true on success. An error may occur when the default website and store can't be selected. An empty scope.Hash checks the default website with its default group and its default stores.
func (*Service) IsCacheEmpty ¶
IsCacheEmpty returns true if the internal cache is empty.
func (*Service) IsSingleStoreMode ¶
IsSingleStoreMode check if Single-Store mode is enabled in the backend configuration and there are less than three Stores. This flag only shows that admin does not want to show certain UI components at backend (like store switchers etc). Store scope specific flag.
func (*Service) LoadFromDB ¶
LoadFromDB reloads the website, store group and store view data from the database. After reloading internal cache will be cleared if there are no errors.
func (*Service) StoreIDbyCode ¶
func (s *Service) StoreIDbyCode(runMode scope.TypeID, storeCode string) (storeID, websiteID int64, err error)
StoreIDbyCode returns, depending on the runMode, for a storeCode its active store ID and its website ID. An empty runMode hash falls back to select the default website, with its default group, and the slice of default stores. A not-found error behaviour gets returned if the code cannot be found. If the runMode equals to scope.DefaultTypeID, the returned ID is always 0 and error is nil. Implements interface Finder.
func (*Service) Stores ¶
func (s *Service) Stores() StoreSlice
Stores returns a cached Store slice containing all related websites and groups. You shall not modify the returned slice.
func (*Service) Website ¶
Website returns the cached Website from an ID including all of its groups and all related stores.
func (*Service) Websites ¶
func (s *Service) Websites() WebsiteSlice
Websites returns a cached slice containing all Websites with its associated groups and stores. You shall not modify the returned slice.
type Store ¶
type Store struct { // Config contains the scoped configuration which cannot be changed once the // object has been created. Config config.Scoped // Data underlying raw data Data *TableStore // Website points to the current website for this store. No integrity checks. // Can be nil. Website Website // Group points to the current store group for this store. No integrity // checks. Can be nil. Group Group }
Store represents the scope in which a shop runs. Everything is bound to a Store. A store knows its website ID, group ID and if its active. A store can have its own configuration settings which overrides the default scope and website scope.
func MustNewStore ¶
func MustNewStore(cfg config.Getter, ts *TableStore, tw *TableWebsite, tg *TableGroup) Store
MustNewStore same as NewStore except that it panics on an error.
func NewStore ¶
func NewStore(cfg config.Getter, ts *TableStore, tw *TableWebsite, tg *TableGroup) (Store, error)
NewStore creates a new Store. Returns an error if the first three arguments are nil. Returns an error if integrity checks fail. config.Getter will be also set to Group and Website.
func (Store) MarshalJSON ¶
MarshalJSON satisfies interface for JSON marshalling. The TableStore struct will be encoded to JSON using Go's standard library.
func (Store) MarshalLog ¶
MarshalLog implements the log.Marshaler interface
func (Store) RootCategoryID ¶
RootCategoryID returns the root category ID assigned to this store view.
func (*Store) SetWebsiteGroup ¶
func (s *Store) SetWebsiteGroup(cfg config.Getter, tw *TableWebsite, tg *TableGroup) error
SetWebsiteGroup uses a raw website and a table store slice to set the groups associated to this website and the stores associated to this website. It returns an error if the data integrity is incorrect.
func (Store) String ¶
String returns human readable information about a Store. The returned string may change in the future to provide better informations.
type StoreSlice ¶
type StoreSlice []Store
StoreSlice a collection of pointers to the Store structs. StoreSlice has some nifty method receivers.
func (StoreSlice) ActiveCodes ¶
func (ss StoreSlice) ActiveCodes() []string
ActiveCodes returns all active store codes
func (StoreSlice) ActiveIDs ¶
func (ss StoreSlice) ActiveIDs() []int64
ActiveIDs returns all active store IDs
func (StoreSlice) Each ¶
func (ss StoreSlice) Each(f func(Store)) StoreSlice
Each applies predicate f on each item within the slice.
func (StoreSlice) Filter ¶
func (ss StoreSlice) Filter(f func(Store) bool) StoreSlice
Filter returns a new slice filtered by predicate f
func (StoreSlice) FindByID ¶
func (ss StoreSlice) FindByID(id int64) (Store, bool)
FindByID filters by Id, returns the website and true if found.
func (StoreSlice) FindOne ¶
func (ss StoreSlice) FindOne(f func(Store) bool) (Store, bool)
FindOne filters by predicate f and returns the first hit.
func (StoreSlice) Len ¶
func (ss StoreSlice) Len() int
func (StoreSlice) Map ¶
func (ss StoreSlice) Map(f func(*Store)) StoreSlice
Map applies predicate f on each item within the slice and allows changing it.
func (*StoreSlice) Swap ¶
func (ss *StoreSlice) Swap(i, j int)
type TableGroup ¶
type TableGroup struct { GroupID int64 `db:"group_id" json:",omitempty"` // group_id smallint(5) unsigned NOT NULL PRI auto_increment WebsiteID int64 `db:"website_id" json:",omitempty"` // website_id smallint(5) unsigned NOT NULL MUL DEFAULT '0' Name string `db:"name" json:",omitempty"` // name varchar(255) NOT NULL RootCategoryID int64 `db:"root_category_id" json:",omitempty"` // root_category_id int(10) unsigned NOT NULL DEFAULT '0' DefaultStoreID int64 `db:"default_store_id" json:",omitempty"` // default_store_id smallint(5) unsigned NOT NULL MUL DEFAULT '0' }
TableGroup represents a type for DB table store_group Generated via tableToStruct.
type TableGroupSlice ¶
type TableGroupSlice []*TableGroup
TableGroupSlice represents a collection type for DB table store_group Generated via tableToStruct.
func (*TableGroupSlice) Append ¶
func (s *TableGroupSlice) Append(n ...*TableGroup)
Append will add a new item at the end of TableGroupSlice. Generated via tableToStruct.
func (*TableGroupSlice) Cut ¶
func (s *TableGroupSlice) Cut(i, j int)
Cut will remove items i through j-1. Generated via tableToStruct.
func (*TableGroupSlice) Delete ¶
func (s *TableGroupSlice) Delete(i int)
Delete will remove an item from the slice. Generated via tableToStruct.
func (TableGroupSlice) Each ¶
func (s TableGroupSlice) Each(f func(*TableGroup)) TableGroupSlice
Each will run function f on all items in TableGroupSlice. Generated via tableToStruct.
func (TableGroupSlice) Extract ¶
func (s TableGroupSlice) Extract() ExtractGroup
Extract extracts from a specified field all values into a slice. Generated via tableToStruct.
func (TableGroupSlice) Filter ¶
func (s TableGroupSlice) Filter(f func(*TableGroup) bool) TableGroupSlice
Filter returns a new slice filtered by predicate f. Generated via tableToStruct.
func (TableGroupSlice) FilterNot ¶
func (s TableGroupSlice) FilterNot(f func(*TableGroup) bool) TableGroupSlice
FilterNot will return a new TableGroupSlice that does not match by calling the function f Generated via tableToStruct.
func (TableGroupSlice) FilterThis ¶
func (s TableGroupSlice) FilterThis(f func(*TableGroup) bool) TableGroupSlice
FilterThis filters the current slice by predicate f without memory allocation. Generated via tableToStruct.
func (TableGroupSlice) FindByGroupID ¶
func (s TableGroupSlice) FindByGroupID( group_id int64, ) (match *TableGroup, found bool)
FindByGroupID searches the primary keys and returns a *TableGroup if found or nil and false. Generated via tableToStruct.
func (*TableGroupSlice) Insert ¶
func (s *TableGroupSlice) Insert(n *TableGroup, i int)
Insert will place a new item at position i. Generated via tableToStruct.
func (TableGroupSlice) Len ¶
func (s TableGroupSlice) Len() int
Len returns the length and will satisfy the sort.Interface. Generated via tableToStruct.
func (TableGroupSlice) LessPK ¶
func (s TableGroupSlice) LessPK(i, j *TableGroup) bool
LessPK helper functions for sorting by ascending primary key. Can be used as an argument in Sort(). Generated via tableToStruct.
func (*TableGroupSlice) Prepend ¶
func (s *TableGroupSlice) Prepend(n *TableGroup)
Prepend will add a new item at the beginning of TableGroupSlice. Generated via tableToStruct.
func (*TableGroupSlice) SQLDelete ¶
func (s *TableGroupSlice) SQLDelete(dbrSess dbr.SessionRunner, cbs ...dbr.DeleteCb) (int, error)
SQLDelete deletes all record from the database @todo. Generated via tableToStruct.
func (*TableGroupSlice) SQLInsert ¶
func (s *TableGroupSlice) SQLInsert(dbrSess dbr.SessionRunner, cbs ...dbr.InsertCb) (int, error)
SQLInsert inserts all records into the database @todo. Generated via tableToStruct.
func (*TableGroupSlice) SQLSelect ¶
func (s *TableGroupSlice) SQLSelect(dbrSess dbr.SessionRunner, cbs ...dbr.SelectCb) (int, error)
SQLSelect uses a dbr session to load all data from the core_store_group table into the current slice. The variadic 2nd argument can be a call back function to manipulate the select. Additional columns or joins cannot be added. This method receiver should only be used in development. @see app/code/Magento/Store/Model/Resource/Group/Collection.php::_beforeLoad()
func (*TableGroupSlice) SQLUpdate ¶
func (s *TableGroupSlice) SQLUpdate(dbrSess dbr.SessionRunner, cbs ...dbr.UpdateCb) (int, error)
SQLUpdate updates all record in the database @todo. Generated via tableToStruct.
func (TableGroupSlice) Sort ¶
func (s TableGroupSlice) Sort(less func(*TableGroup, *TableGroup) bool)
Sort will sort TableGroupSlice. Generated via tableToStruct.
func (TableGroupSlice) Swap ¶
func (s TableGroupSlice) Swap(i, j int)
Swap will satisfy the sort.Interface. Generated via tableToStruct.
type TableStore ¶
type TableStore struct { StoreID int64 `db:"store_id" json:",omitempty"` // store_id smallint(5) unsigned NOT NULL PRI auto_increment Code null.String `db:"code" json:",omitempty"` // code varchar(32) NULL UNI WebsiteID int64 `db:"website_id" json:",omitempty"` // website_id smallint(5) unsigned NOT NULL MUL DEFAULT '0' GroupID int64 `db:"group_id" json:",omitempty"` // group_id smallint(5) unsigned NOT NULL MUL DEFAULT '0' Name string `db:"name" json:",omitempty"` // name varchar(255) NOT NULL SortOrder int64 `db:"sort_order" json:",omitempty"` // sort_order smallint(5) unsigned NOT NULL DEFAULT '0' IsActive bool `db:"is_active" json:",omitempty"` // is_active smallint(5) unsigned NOT NULL MUL DEFAULT '0' }
TableStore represents a type for DB table store Generated via tableToStruct.
func (TableStore) IsDefault ¶
func (s TableStore) IsDefault() bool
IsDefault returns true if the current store is the default store.
type TableStoreSlice ¶
type TableStoreSlice []*TableStore
TableStoreSlice represents a collection type for DB table store Generated via tableToStruct.
func (*TableStoreSlice) Append ¶
func (s *TableStoreSlice) Append(n ...*TableStore)
Append will add a new item at the end of TableStoreSlice. Generated via tableToStruct.
func (*TableStoreSlice) Cut ¶
func (s *TableStoreSlice) Cut(i, j int)
Cut will remove items i through j-1. Generated via tableToStruct.
func (*TableStoreSlice) Delete ¶
func (s *TableStoreSlice) Delete(i int)
Delete will remove an item from the slice. Generated via tableToStruct.
func (TableStoreSlice) Each ¶
func (s TableStoreSlice) Each(f func(*TableStore)) TableStoreSlice
Each will run function f on all items in TableStoreSlice. Generated via tableToStruct.
func (TableStoreSlice) Extract ¶
func (s TableStoreSlice) Extract() ExtractStore
Extract extracts from a specified field all values into a slice. Generated via tableToStruct.
func (TableStoreSlice) Filter ¶
func (s TableStoreSlice) Filter(f func(*TableStore) bool) TableStoreSlice
Filter returns a new slice filtered by predicate f. Generated via tableToStruct.
func (TableStoreSlice) FilterByGroupID ¶
func (s TableStoreSlice) FilterByGroupID(id int64) TableStoreSlice
FilterByGroupID returns a new slice with all TableStores belonging to a group id
func (TableStoreSlice) FilterByWebsiteID ¶
func (s TableStoreSlice) FilterByWebsiteID(id int64) TableStoreSlice
FilterByWebsiteID returns a new slice with all TableStores belonging to a website id
func (TableStoreSlice) FilterNot ¶
func (s TableStoreSlice) FilterNot(f func(*TableStore) bool) TableStoreSlice
FilterNot will return a new TableStoreSlice that does not match by calling the function f Generated via tableToStruct.
func (TableStoreSlice) FilterThis ¶
func (s TableStoreSlice) FilterThis(f func(*TableStore) bool) TableStoreSlice
FilterThis filters the current slice by predicate f without memory allocation. Generated via tableToStruct.
func (TableStoreSlice) FindByCode ¶
func (s TableStoreSlice) FindByCode(code string) (match *TableStore, found bool)
FindByCode searches through this unique key and returns a *TableStore if found or nil and false. Generated via tableToStruct.
func (TableStoreSlice) FindByStoreID ¶
func (s TableStoreSlice) FindByStoreID( store_id int64, ) (match *TableStore, found bool)
FindByStoreID searches the primary keys and returns a *TableStore if found or nil and false. Generated via tableToStruct.
func (*TableStoreSlice) Insert ¶
func (s *TableStoreSlice) Insert(n *TableStore, i int)
Insert will place a new item at position i. Generated via tableToStruct.
func (TableStoreSlice) Len ¶
func (s TableStoreSlice) Len() int
Len returns the length and will satisfy the sort.Interface. Generated via tableToStruct.
func (TableStoreSlice) LessPK ¶
func (s TableStoreSlice) LessPK(i, j *TableStore) bool
LessPK helper functions for sorting by ascending primary key. Can be used as an argument in Sort(). Generated via tableToStruct.
func (*TableStoreSlice) Prepend ¶
func (s *TableStoreSlice) Prepend(n *TableStore)
Prepend will add a new item at the beginning of TableStoreSlice. Generated via tableToStruct.
func (*TableStoreSlice) SQLDelete ¶
func (s *TableStoreSlice) SQLDelete(dbrSess dbr.SessionRunner, cbs ...dbr.DeleteCb) (int, error)
SQLDelete deletes all record from the database @todo. Generated via tableToStruct.
func (*TableStoreSlice) SQLInsert ¶
func (s *TableStoreSlice) SQLInsert(dbrSess dbr.SessionRunner, cbs ...dbr.InsertCb) (int, error)
SQLInsert inserts all records into the database @todo. Generated via tableToStruct.
func (*TableStoreSlice) SQLSelect ¶
func (s *TableStoreSlice) SQLSelect(dbrSess dbr.SessionRunner, cbs ...dbr.SelectCb) (int, error)
SQLSelect uses a dbr session to load all data from the core_store table into the current slice. The variadic 2nd argument can be a call back function to manipulate the select. Additional columns or joins cannot be added. This method receiver should only be used in development. @see https://github.com/magento/magento2/blob/0.74.0-beta7/app%2Fcode%2FMagento%2FStore%2FModel%2FResource%2FStore%2FCollection.php#L147 regarding the sort order.
func (*TableStoreSlice) SQLUpdate ¶
func (s *TableStoreSlice) SQLUpdate(dbrSess dbr.SessionRunner, cbs ...dbr.UpdateCb) (int, error)
SQLUpdate updates all record in the database @todo. Generated via tableToStruct.
func (TableStoreSlice) Sort ¶
func (s TableStoreSlice) Sort(less func(*TableStore, *TableStore) bool)
Sort will sort TableStoreSlice. Generated via tableToStruct.
func (TableStoreSlice) Swap ¶
func (s TableStoreSlice) Swap(i, j int)
Swap will satisfy the sort.Interface. Generated via tableToStruct.
type TableWebsite ¶
type TableWebsite struct { WebsiteID int64 `db:"website_id" json:",omitempty"` // website_id smallint(5) unsigned NOT NULL PRI auto_increment Code null.String `db:"code" json:",omitempty"` // code varchar(32) NULL UNI Name null.String `db:"name" json:",omitempty"` // name varchar(64) NULL SortOrder int64 `db:"sort_order" json:",omitempty"` // sort_order smallint(5) unsigned NOT NULL MUL DEFAULT '0' DefaultGroupID int64 `db:"default_group_id" json:",omitempty"` // default_group_id smallint(5) unsigned NOT NULL MUL DEFAULT '0' IsDefault null.Bool `db:"is_default" json:",omitempty"` // is_default smallint(5) unsigned NULL DEFAULT '0' }
TableWebsite represents a type for DB table store_website Generated via tableToStruct.
type TableWebsiteSlice ¶
type TableWebsiteSlice []*TableWebsite
TableWebsiteSlice represents a collection type for DB table store_website Generated via tableToStruct.
func (*TableWebsiteSlice) Append ¶
func (s *TableWebsiteSlice) Append(n ...*TableWebsite)
Append will add a new item at the end of TableWebsiteSlice. Generated via tableToStruct.
func (*TableWebsiteSlice) Cut ¶
func (s *TableWebsiteSlice) Cut(i, j int)
Cut will remove items i through j-1. Generated via tableToStruct.
func (*TableWebsiteSlice) Delete ¶
func (s *TableWebsiteSlice) Delete(i int)
Delete will remove an item from the slice. Generated via tableToStruct.
func (TableWebsiteSlice) Each ¶
func (s TableWebsiteSlice) Each(f func(*TableWebsite)) TableWebsiteSlice
Each will run function f on all items in TableWebsiteSlice. Generated via tableToStruct.
func (TableWebsiteSlice) Extract ¶
func (s TableWebsiteSlice) Extract() ExtractWebsite
Extract extracts from a specified field all values into a slice. Generated via tableToStruct.
func (TableWebsiteSlice) Filter ¶
func (s TableWebsiteSlice) Filter(f func(*TableWebsite) bool) TableWebsiteSlice
Filter returns a new slice filtered by predicate f. Generated via tableToStruct.
func (TableWebsiteSlice) FilterNot ¶
func (s TableWebsiteSlice) FilterNot(f func(*TableWebsite) bool) TableWebsiteSlice
FilterNot will return a new TableWebsiteSlice that does not match by calling the function f Generated via tableToStruct.
func (TableWebsiteSlice) FilterThis ¶
func (s TableWebsiteSlice) FilterThis(f func(*TableWebsite) bool) TableWebsiteSlice
FilterThis filters the current slice by predicate f without memory allocation. Generated via tableToStruct.
func (TableWebsiteSlice) FindByCode ¶
func (s TableWebsiteSlice) FindByCode(code string) (match *TableWebsite, found bool)
FindByCode searches through this unique key and returns a *TableWebsite if found or nil and false. Generated via tableToStruct.
func (TableWebsiteSlice) FindByWebsiteID ¶
func (s TableWebsiteSlice) FindByWebsiteID( website_id int64, ) (match *TableWebsite, found bool)
FindByWebsiteID searches the primary keys and returns a *TableWebsite if found or nil and false. Generated via tableToStruct.
func (*TableWebsiteSlice) Insert ¶
func (s *TableWebsiteSlice) Insert(n *TableWebsite, i int)
Insert will place a new item at position i. Generated via tableToStruct.
func (TableWebsiteSlice) Len ¶
func (s TableWebsiteSlice) Len() int
Len returns the length and will satisfy the sort.Interface. Generated via tableToStruct.
func (TableWebsiteSlice) LessPK ¶
func (s TableWebsiteSlice) LessPK(i, j *TableWebsite) bool
LessPK helper functions for sorting by ascending primary key. Can be used as an argument in Sort(). Generated via tableToStruct.
func (*TableWebsiteSlice) Prepend ¶
func (s *TableWebsiteSlice) Prepend(n *TableWebsite)
Prepend will add a new item at the beginning of TableWebsiteSlice. Generated via tableToStruct.
func (*TableWebsiteSlice) SQLDelete ¶
func (s *TableWebsiteSlice) SQLDelete(dbrSess dbr.SessionRunner, cbs ...dbr.DeleteCb) (int, error)
SQLDelete deletes all record from the database @todo. Generated via tableToStruct.
func (*TableWebsiteSlice) SQLInsert ¶
func (s *TableWebsiteSlice) SQLInsert(dbrSess dbr.SessionRunner, cbs ...dbr.InsertCb) (int, error)
SQLInsert inserts all records into the database @todo. Generated via tableToStruct.
func (*TableWebsiteSlice) SQLSelect ¶
func (s *TableWebsiteSlice) SQLSelect(dbrSess dbr.SessionRunner, cbs ...dbr.SelectCb) (int, error)
SQLSelect uses a dbr session to load all data from the core_website table into the current slice. The variadic 2nd argument can be a call back function to manipulate the select. Additional columns or joins cannot be added. This method receiver should only be used in development. @see app/code/Magento/Store/Model/Resource/Website/Collection.php::Load()
func (*TableWebsiteSlice) SQLUpdate ¶
func (s *TableWebsiteSlice) SQLUpdate(dbrSess dbr.SessionRunner, cbs ...dbr.UpdateCb) (int, error)
SQLUpdate updates all record in the database @todo. Generated via tableToStruct.
func (TableWebsiteSlice) Sort ¶
func (s TableWebsiteSlice) Sort(less func(*TableWebsite, *TableWebsite) bool)
Sort will sort TableWebsiteSlice. Generated via tableToStruct.
func (TableWebsiteSlice) Swap ¶
func (s TableWebsiteSlice) Swap(i, j int)
Swap will satisfy the sort.Interface. Generated via tableToStruct.
type Tree ¶
type Tree struct { Scope scope.Type `json:"scope",xml:"scope"` ID int64 `json:"id",xml:"id"` Scopes []Tree `json:"scopes,omitempty",xml:"scopes,omitempty"` }
Tree represents a hierarchical structure of all available scopes.
type Website ¶
type Website struct { // Config contains the scoped configuration which cannot be changed once the // object has been created. Config config.Scoped // Data raw website data from DB table. If nil, website object is invalid Data *TableWebsite // Groups contains a slice to all groups associated to one website. This slice // can be nil. Groups GroupSlice // Stores contains a slice to all stores associated to one website. This slice // can be nil. Stores StoreSlice }
Website represents the overall parent structure of its children Group and Store. A website defines the default group ID. A website can contain custom configuration settings which overrides the default scope but get itself overridden by the Store scope.
func MustNewWebsite ¶
func MustNewWebsite(cfg config.Getter, tw *TableWebsite, tgs TableGroupSlice, tss TableStoreSlice) Website
MustNewWebsite same as NewWebsite but panics on error.
func NewWebsite ¶
func NewWebsite(cfg config.Getter, tw *TableWebsite, tgs TableGroupSlice, tss TableStoreSlice) (Website, error)
NewWebsite creates a new Website with its depended groups and stores.
func (Website) DefaultGroup ¶
DefaultGroup returns the default Group or an error if not found.
func (Website) DefaultGroupID ¶
DefaultGroupID returns the associated default group ID. If Data is nil, returns -1.
func (Website) DefaultStore ¶
DefaultStore returns the default store associated to the underlying group.
func (Website) DefaultStoreID ¶
DefaultStoreID returns the default store ID associated to the underlying group.
func (Website) MarshalJSON ¶
MarshalJSON satisfies interface for JSON marshalling. The TableWebsite struct will be encoded to JSON.
func (*Website) SetGroupsStores ¶
func (w *Website) SetGroupsStores(tgs TableGroupSlice, tss TableStoreSlice) error
SetGroupsStores uses a group slice and a table store slice to set the groups associated to this website and the stores associated to this website. It returns an error if the data integrity is incorrect.
type WebsiteSlice ¶
type WebsiteSlice []Website
WebsiteSlice contains pointer to Website struct and some nifty method receivers.
func (WebsiteSlice) Default ¶
func (ws WebsiteSlice) Default() (Website, error)
Default returns the default website or a not-found error.
func (WebsiteSlice) Each ¶
func (ws WebsiteSlice) Each(f func(Website)) WebsiteSlice
Each iterates over the slice applying predicate f without modifying the current item.
func (WebsiteSlice) Filter ¶
func (ws WebsiteSlice) Filter(f func(Website) bool) WebsiteSlice
Filter returns a new slice filtered by predicate f
func (WebsiteSlice) FindByID ¶
func (ws WebsiteSlice) FindByID(id int64) (Website, bool)
FindByID filters by Id, returns the website and true if found.
func (WebsiteSlice) Less ¶
func (ws WebsiteSlice) Less(i, j int) bool
Less checks the Data field SortOrder if index i < index j.
func (WebsiteSlice) Map ¶
func (ws WebsiteSlice) Map(f func(*Website)) WebsiteSlice
Map applies predicate f on each item within the slice and allows changing it.
func (*WebsiteSlice) Swap ¶
func (ws *WebsiteSlice) Swap(i, j int)
Swap swaps positions within the slice
func (WebsiteSlice) Tree ¶
func (ws WebsiteSlice) Tree() Tree
Tree returns the hierarchical overview of the scopes: default -> website -> group -> store represented in a Tree.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package scope defines the configuration of scopes default, website, group and store.
|
Package scope defines the configuration of scopes default, website, group and store. |
Package mock implements mocking of the store.Service for tests.
|
Package mock implements mocking of the store.Service for tests. |