stock

package
v1.4.5-alpha1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package stock is a default implementation of stock interface declared in "github.com/ottemo/commerce/app/models/checkout" package

Index

Constants

View Source
const (
	ConstCollectionNameStock = "stock"

	ConstConfigPathGroup   = "general.stock"
	ConstConfigPathEnabled = "general.stock.enabled"

	ConstErrorModule = "stock"
	ConstErrorLevel  = env.ConstErrorLevelActor
)

Package global constants

Variables

This section is empty.

Functions

func APIDeleteStockQty

func APIDeleteStockQty(context api.InterfaceApplicationContext) (interface{}, error)

APIDeleteStockQty deletes stock records for a product-options pair

  • product id should be specified in "productID" argument
  • product options should be specified in "options" field of content

func APIGetProductQty

func APIGetProductQty(context api.InterfaceApplicationContext) (interface{}, error)

APIGetProductQty returns available stock qty for particular product-options pair

  • product id should be specified in "productID" argument
  • product options should be specified in "options" field of content

func APIGetProductStock

func APIGetProductStock(context api.InterfaceApplicationContext) (interface{}, error)

APIGetProductStock returns stock information for particular product

  • returns qty for all specified product-option pairs
  • product id should be specified in "productID" argument

func APISetStockQty

func APISetStockQty(context api.InterfaceApplicationContext) (interface{}, error)

APISetStockQty sets amount qty for a particular product-options pair

  • product id and qty should be specified in "productID" and "qty" arguments
  • product options should be specified in "options" field of content

func APIUpdateStockQty

func APIUpdateStockQty(context api.InterfaceApplicationContext) (interface{}, error)

APIUpdateStockQty increases qty on particular product-options pair for a delta value

  • product id and delta should be specified in "productID" and "qty" arguments
  • negative delta will decrease amount
  • product options should be specified in "options" field of content

Types

type DefaultStock

type DefaultStock struct {
	// contains filtered or unexported fields
}

func (*DefaultStock) Delete

func (it *DefaultStock) Delete() error

Delete deletes model from storage

func (*DefaultStock) FromHashMap

func (it *DefaultStock) FromHashMap(input map[string]interface{}) error

FromHashMap converts object represented by hash map to object

func (*DefaultStock) Get

func (it *DefaultStock) Get(attribute string) interface{}

Get return model attribute by name

func (*DefaultStock) GetAttributesInfo

func (it *DefaultStock) GetAttributesInfo() []models.StructAttributeInfo

GetAttributesInfo describes model attributes

func (*DefaultStock) GetCollection

func (it *DefaultStock) GetCollection() models.InterfaceCollection

GetCollection returns collection of current instance type

func (*DefaultStock) GetID

func (it *DefaultStock) GetID() string

GetID returns database storage id of current object

func (*DefaultStock) GetImplementationName

func (it *DefaultStock) GetImplementationName() string

GetImplementationName returns default model implementation name

func (*DefaultStock) GetModelName

func (it *DefaultStock) GetModelName() string

GetModelName returns model name

func (*DefaultStock) GetOptions

func (it *DefaultStock) GetOptions() string

GetOptions returns database storage id of current object

func (*DefaultStock) GetProductID

func (it *DefaultStock) GetProductID() string

GetProductID returns database storage id of current object

func (*DefaultStock) GetProductOptions

func (it *DefaultStock) GetProductOptions(productID string) []map[string]interface{}

GetProductOptions returns list of existing product options

func (*DefaultStock) GetProductQty

func (it *DefaultStock) GetProductQty(productID string, options map[string]interface{}) int

GetProductQty returns stock qty for a requested product-options pair

func (*DefaultStock) GetQty

func (it *DefaultStock) GetQty() int

GetOptions returns database storage id of current object

func (*DefaultStock) Load

func (it *DefaultStock) Load(id string) error

Load loads model from storage

func (*DefaultStock) New

func (it *DefaultStock) New() (models.InterfaceModel, error)

New creates new model

func (*DefaultStock) RemoveProductQty

func (it *DefaultStock) RemoveProductQty(productID string, options map[string]interface{}) error

RemoveProductQty removes database records matching given product-options pair

func (*DefaultStock) Save

func (it *DefaultStock) Save() error

Save function check model and save it to storage

func (*DefaultStock) Set

func (it *DefaultStock) Set(attribute string, value interface{}) error

Set sets attribute value to object or returns error

func (*DefaultStock) SetID

func (it *DefaultStock) SetID(id string) error

SetID sets database storage id for current object

func (*DefaultStock) SetOptions

func (it *DefaultStock) SetOptions(options string) error

SetOptions sets database storage id for current object

func (*DefaultStock) SetProductID

func (it *DefaultStock) SetProductID(product_id string) error

SetProductID sets database storage id for current object

func (*DefaultStock) SetProductQty

func (it *DefaultStock) SetProductQty(productID string, options map[string]interface{}, qty int) error

SetProductQty updates stock qty for a product-options pair to be exact given value

  • use UpdateProductQty in all cases you can as it is more safer option

func (*DefaultStock) SetQty

func (it *DefaultStock) SetQty(qty int) error

SetOptions sets database storage id for current object

func (*DefaultStock) ToHashMap

func (it *DefaultStock) ToHashMap() map[string]interface{}

ToHashMap converts object data to hash map presentation

func (*DefaultStock) UpdateProductQty

func (it *DefaultStock) UpdateProductQty(productID string, options map[string]interface{}, deltaQty int) error

UpdateProductQty updates stock qty for a product-options pair on delta value which can be positive or negative

type DefaultStockCollection

type DefaultStockCollection struct {
	// contains filtered or unexported fields
}

DefaultStockCollection is a default implementer of InterfaceStockCollection

func (*DefaultStockCollection) GetDBCollection

func (it *DefaultStockCollection) GetDBCollection() db.InterfaceDBCollection

GetDBCollection returns database collection

func (*DefaultStockCollection) GetImplementationName

func (it *DefaultStockCollection) GetImplementationName() string

GetImplementationName returns model implementation name

func (*DefaultStockCollection) GetModelName

func (it *DefaultStockCollection) GetModelName() string

GetModelName returns model name

func (*DefaultStockCollection) List

List enumerates items of model type

func (*DefaultStockCollection) ListAddExtraAttribute

func (it *DefaultStockCollection) ListAddExtraAttribute(attribute string) error

ListAddExtraAttribute allows to obtain additional attributes from List() function

func (*DefaultStockCollection) ListFilterAdd

func (it *DefaultStockCollection) ListFilterAdd(attribute string, operator string, value interface{}) error

ListFilterAdd adds selection filter to List() function

func (*DefaultStockCollection) ListFilterReset

func (it *DefaultStockCollection) ListFilterReset() error

ListFilterReset clears presets made by ListFilterAdd() and ListAddExtraAttribute() functions

func (*DefaultStockCollection) ListLimit

func (it *DefaultStockCollection) ListLimit(offset int, limit int) error

ListLimit specifies selection paging

func (*DefaultStockCollection) ListStocks

func (it *DefaultStockCollection) ListStocks() []stock.InterfaceStock

ListStocks returns array of stock items in model instance form

func (*DefaultStockCollection) New

New returns new instance of model implementation object

type StockDelegate

type StockDelegate struct {
	Inventory []map[string]interface{}
	Qty       int
	// contains filtered or unexported fields
}

StockDelegate type implements InterfaceAttributesDelegate and have handles on InterfaceStorable methods which should have call-back on model method call in order to test it we are pushing the callback status to model instance

func (*StockDelegate) Delete

func (it *StockDelegate) Delete() error

Delete is a modelInstance.Delete() method handler for external attributes

func (*StockDelegate) Get

func (it *StockDelegate) Get(attribute string) interface{}

Get is a getter for external attributes This method should not read data from db. It is Load responsibility.

func (*StockDelegate) GetAttributesInfo

func (it *StockDelegate) GetAttributesInfo() []models.StructAttributeInfo

GetAttributesInfo is a specification of external attributes

func (*StockDelegate) Load

func (it *StockDelegate) Load(productID string) error

Load is a modelInstance.Load() method handler for external attributes, updates qty and inventory values

func (*StockDelegate) New

func (it *StockDelegate) New(instance interface{}) (models.InterfaceAttributesDelegate, error)

New instantiates delegate

func (*StockDelegate) Save

func (it *StockDelegate) Save() error

Save is a modelInstance.Save() method handler for external attributes, updates qty and inventory values methods toHashMap is called to Save instance so Get methods would be executed before Save

func (*StockDelegate) Set

func (it *StockDelegate) Set(attribute string, value interface{}) error

Set is a setter for external attributes, allow only to set value for current model

Jump to

Keyboard shortcuts

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