Documentation ¶
Overview ¶
Package product is a implementation of interfaces declared in "github.com/ottemo/commerce/app/models/product" package
Index ¶
- Constants
- func APIAddMediaForProduct(context api.InterfaceApplicationContext) (interface{}, error)
- func APICreateProduct(context api.InterfaceApplicationContext) (interface{}, error)
- func APICreateProductAttribute(context api.InterfaceApplicationContext) (interface{}, error)
- func APIDeleteProduct(context api.InterfaceApplicationContext) (interface{}, error)
- func APIDeleteProductsAttribute(context api.InterfaceApplicationContext) (interface{}, error)
- func APIGetMedia(context api.InterfaceApplicationContext) (interface{}, error)
- func APIGetMediaPath(context api.InterfaceApplicationContext) (interface{}, error)
- func APIGetProduct(context api.InterfaceApplicationContext) (interface{}, error)
- func APIListMedia(context api.InterfaceApplicationContext) (interface{}, error)
- func APIListProductAttributes(context api.InterfaceApplicationContext) (interface{}, error)
- func APIListProducts(context api.InterfaceApplicationContext) (interface{}, error)
- func APIListRelatedProducts(context api.InterfaceApplicationContext) (interface{}, error)
- func APIPatchOptions(context api.InterfaceApplicationContext) (interface{}, error)
- func APIRemoveMediaForProduct(context api.InterfaceApplicationContext) (interface{}, error)
- func APIRenameMediaForProduct(context api.InterfaceApplicationContext) (interface{}, error)
- func APIUpdateProduct(context api.InterfaceApplicationContext) (interface{}, error)
- func APIUpdateProductAttribute(context api.InterfaceApplicationContext) (interface{}, error)
- func ConvertProductOptionsToSnakeCase(product product.InterfaceProduct) map[string]interface{}
- type DefaultProduct
- func (it *DefaultProduct) AddExternalAttributes(delegate models.InterfaceAttributesDelegate) error
- func (it *DefaultProduct) AddMedia(mediaType string, mediaName string, content []byte) error
- func (it *DefaultProduct) AddNewAttribute(newAttribute models.StructAttributeInfo) error
- func (it *DefaultProduct) ApplyOptions(options map[string]interface{}) error
- func (it *DefaultProduct) Delete() error
- func (it *DefaultProduct) EditAttribute(attributeName string, attributeValues models.StructAttributeInfo) error
- func (it *DefaultProduct) FromHashMap(input map[string]interface{}) error
- func (it *DefaultProduct) Get(attribute string) interface{}
- func (it *DefaultProduct) GetAppliedOptions() map[string]interface{}
- func (it *DefaultProduct) GetAttributesInfo() []models.StructAttributeInfo
- func (it *DefaultProduct) GetCollection() models.InterfaceCollection
- func (it *DefaultProduct) GetCustomAttributeCollectionName() string
- func (it *DefaultProduct) GetDefaultImage() string
- func (it *DefaultProduct) GetDescription() string
- func (it *DefaultProduct) GetEnabled() bool
- func (it *DefaultProduct) GetExtendedInstance() interface{}
- func (it *DefaultProduct) GetID() string
- func (it *DefaultProduct) GetImplementationName() string
- func (it *DefaultProduct) GetInstance() interface{}
- func (it *DefaultProduct) GetMedia(mediaType string, mediaName string) ([]byte, error)
- func (it *DefaultProduct) GetMediaPath(mediaType string) (string, error)
- func (it *DefaultProduct) GetModelName() string
- func (it *DefaultProduct) GetName() string
- func (it *DefaultProduct) GetOptions() map[string]interface{}
- func (it *DefaultProduct) GetPrice() float64
- func (it *DefaultProduct) GetRelatedProductIds() []string
- func (it *DefaultProduct) GetRelatedProducts() []product.InterfaceProduct
- func (it *DefaultProduct) GetShortDescription() string
- func (it *DefaultProduct) GetSku() string
- func (it *DefaultProduct) GetWeight() float64
- func (it *DefaultProduct) ListExternalAttributes() map[string]models.InterfaceAttributesDelegate
- func (it *DefaultProduct) ListMedia(mediaType string) ([]string, error)
- func (it *DefaultProduct) Load(id string) error
- func (it *DefaultProduct) LoadExternalAttributes() error
- func (it *DefaultProduct) New() (models.InterfaceModel, error)
- func (it *DefaultProduct) RemoveAttribute(attributeName string) error
- func (it *DefaultProduct) RemoveExternalAttributes(delegate models.InterfaceAttributesDelegate) error
- func (it *DefaultProduct) RemoveMedia(mediaType string, mediaName string) error
- func (it *DefaultProduct) Save() error
- func (it *DefaultProduct) Set(attribute string, value interface{}) error
- func (it *DefaultProduct) SetID(id string) error
- func (it *DefaultProduct) ToHashMap() map[string]interface{}
- type DefaultProductCollection
- func (it *DefaultProductCollection) GetDBCollection() db.InterfaceDBCollection
- func (it *DefaultProductCollection) GetImplementationName() string
- func (it *DefaultProductCollection) GetModelName() string
- func (it *DefaultProductCollection) List() ([]models.StructListItem, error)
- func (it *DefaultProductCollection) ListAddExtraAttribute(attribute string) error
- func (it *DefaultProductCollection) ListFilterAdd(Attribute string, Operator string, Value interface{}) error
- func (it *DefaultProductCollection) ListFilterReset() error
- func (it *DefaultProductCollection) ListLimit(offset int, limit int) error
- func (it *DefaultProductCollection) ListProducts() []product.InterfaceProduct
- func (it *DefaultProductCollection) New() (models.InterfaceModel, error)
Constants ¶
const ( ConstCollectionNameProduct = "product" ConstErrorModule = "product" ConstErrorLevel = env.ConstErrorLevelActor ConstProductMediaTypeImage = "image" ConstSwatchImageDefaultFormat = "jpeg" ConstSwatchImageDefaultExtention = "jpeg" )
Package global constants
Variables ¶
This section is empty.
Functions ¶
func APIAddMediaForProduct ¶
func APIAddMediaForProduct(context api.InterfaceApplicationContext) (interface{}, error)
APIAddMediaForProduct uploads and assigns media file send in request for a specified product
- product id, media type and media name should be specified in "productID", "mediaType" and "mediaName" arguments
- media file should be provided in "file" field
func APICreateProduct ¶
func APICreateProduct(context api.InterfaceApplicationContext) (interface{}, error)
APICreateProduct creates a new product
- product attributes must be provided in request content
- "sku" and "name" attributes are required
func APICreateProductAttribute ¶
func APICreateProductAttribute(context api.InterfaceApplicationContext) (interface{}, error)
APICreateProductAttribute creates a new custom attribute for a product model
- attribute parameters "Attribute" and "Label" are required
func APIDeleteProduct ¶
func APIDeleteProduct(context api.InterfaceApplicationContext) (interface{}, error)
APIDeleteProduct deletes existing product
- product id must be specified in "productID" argument
func APIDeleteProductsAttribute ¶
func APIDeleteProductsAttribute(context api.InterfaceApplicationContext) (interface{}, error)
APIDeleteProductsAttribute removes existing custom attribute of a product model
- attribute name/code should be provided in "attribute" argument
func APIGetMedia ¶
func APIGetMedia(context api.InterfaceApplicationContext) (interface{}, error)
APIGetMedia returns media contents for a product (file assigned to a product)
- product id, media type and media name must be specified in "productID", "mediaType" and "mediaName" arguments
- on success case not a JSON data returns, but media file
func APIGetMediaPath ¶
func APIGetMediaPath(context api.InterfaceApplicationContext) (interface{}, error)
APIGetMediaPath returns relative path to product media files within media library
- product id, media type must be specified in "productID" and "mediaType" arguments
func APIGetProduct ¶
func APIGetProduct(context api.InterfaceApplicationContext) (interface{}, error)
APIGetProduct return specified product information
- product id should be specified in "productID" argument
func APIListMedia ¶
func APIListMedia(context api.InterfaceApplicationContext) (interface{}, error)
APIListMedia returns lost of media files assigned to specified product
- product id, media type must be specified in "productID" and "mediaType" arguments
func APIListProductAttributes ¶
func APIListProductAttributes(context api.InterfaceApplicationContext) (interface{}, error)
APIListProductAttributes returns a list of product attributes
func APIListProducts ¶
func APIListProducts(context api.InterfaceApplicationContext) (interface{}, error)
APIListProducts returns a list of available products
- if "action" parameter is set to "count" result value will be just a number of list items
- visitors can not see disabled products, but administrators can
func APIListRelatedProducts ¶
func APIListRelatedProducts(context api.InterfaceApplicationContext) (interface{}, error)
APIListRelatedProducts returns related products list for a given product
func APIPatchOptions ¶
func APIPatchOptions(context api.InterfaceApplicationContext) (interface{}, error)
APIPatchOptions converts product options to snake case in products and subscriptions TODO: remove after patching
func APIRemoveMediaForProduct ¶
func APIRemoveMediaForProduct(context api.InterfaceApplicationContext) (interface{}, error)
APIRemoveMediaForProduct removes media content from specified product
- product id, media type and media name should be specified in "productID", "mediaType" and "mediaName" arguments
func APIRenameMediaForProduct ¶
func APIRenameMediaForProduct(context api.InterfaceApplicationContext) (interface{}, error)
APIRenameMediaForProduct renames media file for a specified product
- product id, media type and media name should be specified in "productID", "mediaType" and "mediaName" arguments
- new media name should be provided in "newMediaName" field
func APIUpdateProduct ¶
func APIUpdateProduct(context api.InterfaceApplicationContext) (interface{}, error)
APIUpdateProduct updates existing product
- product id should be specified in "productID" argument
- product attributes should be specified in content
func APIUpdateProductAttribute ¶
func APIUpdateProductAttribute(context api.InterfaceApplicationContext) (interface{}, error)
APIUpdateProductAttribute updates existing custom attribute of product model
- attribute name/code should be provided in "attribute" argument
- attribute parameters should be provided in request content
- attribute parameters "id" and "name" will be ignored
- static attributes can not be changed
func ConvertProductOptionsToSnakeCase ¶
func ConvertProductOptionsToSnakeCase(product product.InterfaceProduct) map[string]interface{}
ConvertProductOptionsToSnakeCase updates option keys for product to case_snake TODO: remove after patching
Types ¶
type DefaultProduct ¶
type DefaultProduct struct { Enabled bool Sku string Name string ShortDescription string Description string DefaultImage string Price float64 Weight float64 Options map[string]interface{} RelatedProductIds []string Visible bool // contains filtered or unexported fields }
DefaultProduct is a default implementer of InterfaceProduct
func (*DefaultProduct) AddExternalAttributes ¶
func (it *DefaultProduct) AddExternalAttributes(delegate models.InterfaceAttributesDelegate) error
AddExternalAttributes registers new delegate for a given attribute
func (*DefaultProduct) AddMedia ¶
func (it *DefaultProduct) AddMedia(mediaType string, mediaName string, content []byte) error
AddMedia adds new media assigned to product
func (*DefaultProduct) AddNewAttribute ¶
func (it *DefaultProduct) AddNewAttribute(newAttribute models.StructAttributeInfo) error
AddNewAttribute extends collection with new custom attribute
func (*DefaultProduct) ApplyOptions ¶
func (it *DefaultProduct) ApplyOptions(options map[string]interface{}) error
ApplyOptions updates current product attributes according to given product options, returns error if specified option are not possible for the product
func (*DefaultProduct) Delete ¶
func (it *DefaultProduct) Delete() error
Delete removes current product from DB
func (*DefaultProduct) EditAttribute ¶
func (it *DefaultProduct) EditAttribute(attributeName string, attributeValues models.StructAttributeInfo) error
EditAttribute modifies custom attribute for collection
func (*DefaultProduct) FromHashMap ¶
func (it *DefaultProduct) FromHashMap(input map[string]interface{}) error
FromHashMap will populate object attributes from map[string]interface{}
func (*DefaultProduct) Get ¶
func (it *DefaultProduct) Get(attribute string) interface{}
Get returns an object attribute value or nil
func (*DefaultProduct) GetAppliedOptions ¶
func (it *DefaultProduct) GetAppliedOptions() map[string]interface{}
GetAppliedOptions returns applied options for current product instance
func (*DefaultProduct) GetAttributesInfo ¶
func (it *DefaultProduct) GetAttributesInfo() []models.StructAttributeInfo
GetAttributesInfo returns the requested object attributes
func (*DefaultProduct) GetCollection ¶
func (it *DefaultProduct) GetCollection() models.InterfaceCollection
GetCollection returns collection of current instance type
func (*DefaultProduct) GetCustomAttributeCollectionName ¶
func (it *DefaultProduct) GetCustomAttributeCollectionName() string
GetCustomAttributeCollectionName returns collection name you can use to fill ModelCustomAttributes struct
func (*DefaultProduct) GetDefaultImage ¶
func (it *DefaultProduct) GetDefaultImage() string
GetDefaultImage returns the imaged identified as defult for the given product
func (*DefaultProduct) GetDescription ¶
func (it *DefaultProduct) GetDescription() string
GetDescription returns the long description of the requested product
func (*DefaultProduct) GetEnabled ¶
func (it *DefaultProduct) GetEnabled() bool
GetEnabled returns enabled flag for the given product
func (*DefaultProduct) GetExtendedInstance ¶
func (it *DefaultProduct) GetExtendedInstance() interface{}
GetExtendedInstance returns current instance delegate attached to
func (*DefaultProduct) GetID ¶
func (it *DefaultProduct) GetID() string
GetID returns current product id
func (*DefaultProduct) GetImplementationName ¶
func (it *DefaultProduct) GetImplementationName() string
GetImplementationName returns model implementation name
func (*DefaultProduct) GetInstance ¶
func (it *DefaultProduct) GetInstance() interface{}
GetInstance returns current instance delegate attached to
func (*DefaultProduct) GetMedia ¶
func (it *DefaultProduct) GetMedia(mediaType string, mediaName string) ([]byte, error)
GetMedia returns content of media assigned to product
func (*DefaultProduct) GetMediaPath ¶
func (it *DefaultProduct) GetMediaPath(mediaType string) (string, error)
GetMediaPath returns relative location of media assigned to product in media storage
func (*DefaultProduct) GetModelName ¶
func (it *DefaultProduct) GetModelName() string
GetModelName returns model name
func (*DefaultProduct) GetName ¶
func (it *DefaultProduct) GetName() string
GetName returns the name of the given product
func (*DefaultProduct) GetOptions ¶
func (it *DefaultProduct) GetOptions() map[string]interface{}
GetOptions returns current products possible options as a map[string]interface{}
func (*DefaultProduct) GetPrice ¶
func (it *DefaultProduct) GetPrice() float64
GetPrice returns the price as a float64 for the given product
func (*DefaultProduct) GetRelatedProductIds ¶
func (it *DefaultProduct) GetRelatedProductIds() []string
GetRelatedProductIds returns the related product id list
func (*DefaultProduct) GetRelatedProducts ¶
func (it *DefaultProduct) GetRelatedProducts() []product.InterfaceProduct
GetRelatedProducts returns related products instances list
func (*DefaultProduct) GetShortDescription ¶
func (it *DefaultProduct) GetShortDescription() string
GetShortDescription returns the short description of the requested product
func (*DefaultProduct) GetSku ¶
func (it *DefaultProduct) GetSku() string
GetSku returns requested sku for the given product
func (*DefaultProduct) GetWeight ¶
func (it *DefaultProduct) GetWeight() float64
GetWeight returns the weight for the given product
func (*DefaultProduct) ListExternalAttributes ¶
func (it *DefaultProduct) ListExternalAttributes() map[string]models.InterfaceAttributesDelegate
ListExternalAttributes registers new delegate for a given attribute
func (*DefaultProduct) ListMedia ¶
func (it *DefaultProduct) ListMedia(mediaType string) ([]string, error)
ListMedia lists media assigned to product
func (*DefaultProduct) Load ¶
func (it *DefaultProduct) Load(id string) error
Load loads product information from DB
func (*DefaultProduct) LoadExternalAttributes ¶
func (it *DefaultProduct) LoadExternalAttributes() error
LoadExternalAttributes loads external attributes from storage
func (*DefaultProduct) New ¶
func (it *DefaultProduct) New() (models.InterfaceModel, error)
New returns new instance of model implementation object
func (*DefaultProduct) RemoveAttribute ¶
func (it *DefaultProduct) RemoveAttribute(attributeName string) error
RemoveAttribute removes custom attribute from collection
func (*DefaultProduct) RemoveExternalAttributes ¶
func (it *DefaultProduct) RemoveExternalAttributes(delegate models.InterfaceAttributesDelegate) error
RemoveExternalAttributes registers new delegate for a given attribute
func (*DefaultProduct) RemoveMedia ¶
func (it *DefaultProduct) RemoveMedia(mediaType string, mediaName string) error
RemoveMedia removes media assigned to product
func (*DefaultProduct) Save ¶
func (it *DefaultProduct) Save() error
Save stores current product to DB
func (*DefaultProduct) Set ¶
func (it *DefaultProduct) Set(attribute string, value interface{}) error
Set will apply the given attribute value to the product or return an error
func (*DefaultProduct) SetID ¶
func (it *DefaultProduct) SetID(id string) error
SetID sets current product id
func (*DefaultProduct) ToHashMap ¶
func (it *DefaultProduct) ToHashMap() map[string]interface{}
ToHashMap returns a map[string]interface{}
type DefaultProductCollection ¶
type DefaultProductCollection struct {
// contains filtered or unexported fields
}
DefaultProductCollection is a default implementer of InterfaceProduct
func (*DefaultProductCollection) GetDBCollection ¶
func (it *DefaultProductCollection) GetDBCollection() db.InterfaceDBCollection
GetDBCollection returns database collection
func (*DefaultProductCollection) GetImplementationName ¶
func (it *DefaultProductCollection) GetImplementationName() string
GetImplementationName returns model implementation name
func (*DefaultProductCollection) GetModelName ¶
func (it *DefaultProductCollection) GetModelName() string
GetModelName returns model name
func (*DefaultProductCollection) List ¶
func (it *DefaultProductCollection) List() ([]models.StructListItem, error)
List enumerates items of Product model type
func (*DefaultProductCollection) ListAddExtraAttribute ¶
func (it *DefaultProductCollection) ListAddExtraAttribute(attribute string) error
ListAddExtraAttribute allows to obtain additional attributes from List() function
func (*DefaultProductCollection) ListFilterAdd ¶
func (it *DefaultProductCollection) ListFilterAdd(Attribute string, Operator string, Value interface{}) error
ListFilterAdd adds selection filter to List() function
func (*DefaultProductCollection) ListFilterReset ¶
func (it *DefaultProductCollection) ListFilterReset() error
ListFilterReset clears presets made by ListFilterAdd() and ListAddExtraAttribute() functions
func (*DefaultProductCollection) ListLimit ¶
func (it *DefaultProductCollection) ListLimit(offset int, limit int) error
ListLimit specifies selection paging
func (*DefaultProductCollection) ListProducts ¶
func (it *DefaultProductCollection) ListProducts() []product.InterfaceProduct
ListProducts returns array of products in model instance form
func (*DefaultProductCollection) New ¶
func (it *DefaultProductCollection) New() (models.InterfaceModel, error)
New returns new instance of model implementation object