Documentation ¶
Overview ¶
Package cart is a default implementation of interfaces declared in "github.com/ottemo/commerce/app/models/cart" package
Index ¶
- Constants
- func APICartInfo(context api.InterfaceApplicationContext) (interface{}, error)
- func APICartItemAdd(context api.InterfaceApplicationContext) (interface{}, error)
- func APICartItemDelete(context api.InterfaceApplicationContext) (interface{}, error)
- func APICartItemUpdate(context api.InterfaceApplicationContext) (interface{}, error)
- type AbandonCart
- type AbandonCartEmailData
- type AbandonVisitor
- type DefaultCart
- func (it *DefaultCart) Activate() error
- func (it *DefaultCart) AddItem(productID string, qty int, options map[string]interface{}) (cart.InterfaceCartItem, error)
- func (it *DefaultCart) Deactivate() error
- func (it *DefaultCart) Delete() error
- func (it *DefaultCart) GetCartInfo() map[string]interface{}
- func (it *DefaultCart) GetCustomInfo() map[string]interface{}
- func (it *DefaultCart) GetID() string
- func (it *DefaultCart) GetImplementationName() string
- func (it *DefaultCart) GetItems() []cart.InterfaceCartItem
- func (it *DefaultCart) GetLastUpdateTime() time.Time
- func (it *DefaultCart) GetModelName() string
- func (it *DefaultCart) GetSessionID() string
- func (it *DefaultCart) GetSubtotal() float64
- func (it *DefaultCart) GetVisitor() visitor.InterfaceVisitor
- func (it *DefaultCart) GetVisitorID() string
- func (it *DefaultCart) IsActive() bool
- func (it *DefaultCart) Load(ID string) error
- func (it *DefaultCart) MakeCartForVisitor(visitorID string) error
- func (it *DefaultCart) New() (models.InterfaceModel, error)
- func (it *DefaultCart) RemoveItem(itemIdx int) error
- func (it *DefaultCart) Save() error
- func (it *DefaultCart) SetCartInfo(infoAttribute string, infoValue interface{}) error
- func (it *DefaultCart) SetCustomInfo(info map[string]interface{})
- func (it *DefaultCart) SetID(NewID string) error
- func (it *DefaultCart) SetQty(itemIdx int, qty int) error
- func (it *DefaultCart) SetSessionID(sessionID string) error
- func (it *DefaultCart) SetVisitorID(visitorID string) error
- func (it *DefaultCart) ValidateCart() error
- type DefaultCartItem
- func (it *DefaultCartItem) GetCart() cart.InterfaceCart
- func (it *DefaultCartItem) GetID() string
- func (it *DefaultCartItem) GetIdx() int
- func (it *DefaultCartItem) GetOptions() map[string]interface{}
- func (it *DefaultCartItem) GetProduct() product.InterfaceProduct
- func (it *DefaultCartItem) GetProductID() string
- func (it *DefaultCartItem) GetQty() int
- func (it *DefaultCartItem) Remove() error
- func (it *DefaultCartItem) SetID(newID string) error
- func (it *DefaultCartItem) SetIdx(newIdx int) error
- func (it *DefaultCartItem) SetOption(optionName string, optionValue interface{}) error
- func (it *DefaultCartItem) SetQty(qty int) error
- func (it *DefaultCartItem) ValidateProduct() error
Constants ¶
const ( ConstCartCollectionName = "cart" ConstCartItemsCollectionName = "cart_items" ConstErrorModule = "cart" ConstErrorLevel = env.ConstErrorLevelActor ConstEventAPIAdd = "api.cart.addToCart" ConstEventAPIUpdate = "api.cart.update" ConstConfigPathCartAbandonEmailSendTime = "general.checkout.abandonEmailSendTime" ConstConfigPathCartAbandonEmailTemplate = "general.checkout.abandonEmailTemplate" )
Package global constants
Variables ¶
This section is empty.
Functions ¶
func APICartInfo ¶
func APICartInfo(context api.InterfaceApplicationContext) (interface{}, error)
APICartInfo returns get cart related information
func APICartItemAdd ¶
func APICartItemAdd(context api.InterfaceApplicationContext) (interface{}, error)
APICartItemAdd adds specified product to cart
- "productID" and "qty" should be specified as arguments
func APICartItemDelete ¶
func APICartItemDelete(context api.InterfaceApplicationContext) (interface{}, error)
APICartItemDelete removes specified item from cart item from cart
- "itemIdx" should be specified as argument (item index can be obtained from APICartInfo)
func APICartItemUpdate ¶
func APICartItemUpdate(context api.InterfaceApplicationContext) (interface{}, error)
APICartItemUpdate changes qty and/or option for cart item
- "itemIdx" and "qty" should be specified as arguments
Types ¶
type AbandonCart ¶
type AbandonCart struct {
ID string
}
AbandonCart is a struct holding the ID of the abandoned cart.
type AbandonCartEmailData ¶
type AbandonCartEmailData struct { Visitor AbandonVisitor Cart AbandonCart }
AbandonCartEmailData is a container for carts and visitors who have items in their cart and still have a valid session.
type AbandonVisitor ¶
AbandonVisitor is a struct to hold the info needed to contact a visitor with items in their cart who has not checked out yet.
type DefaultCart ¶
type DefaultCart struct { VisitorID string SessionID string Info map[string]interface{} CustomInfo map[string]interface{} Items map[int]cart.InterfaceCartItem Active bool UpdatedAt time.Time Subtotal float64 // contains filtered or unexported fields }
DefaultCart is a default implementer of InterfaceCart
func (*DefaultCart) Activate ¶
func (it *DefaultCart) Activate() error
Activate makes cart active
- only one cart can be active for particular visitor
func (*DefaultCart) AddItem ¶
func (it *DefaultCart) AddItem(productID string, qty int, options map[string]interface{}) (cart.InterfaceCartItem, error)
AddItem adds item to the current cart
- returns added item or nil if error happened
func (*DefaultCart) Deactivate ¶
func (it *DefaultCart) Deactivate() error
Deactivate makes cart un-active
- so new cart will be created on next request
func (*DefaultCart) Delete ¶
func (it *DefaultCart) Delete() error
Delete removes current cart from DB
func (*DefaultCart) GetCartInfo ¶
func (it *DefaultCart) GetCartInfo() map[string]interface{}
GetCartInfo returns current cart info assigned
func (*DefaultCart) GetCustomInfo ¶
func (it *DefaultCart) GetCustomInfo() map[string]interface{}
func (*DefaultCart) GetImplementationName ¶
func (it *DefaultCart) GetImplementationName() string
GetImplementationName returns name of current model implementation
func (*DefaultCart) GetItems ¶
func (it *DefaultCart) GetItems() []cart.InterfaceCartItem
GetItems enumerates current cart items sorted by item idx
func (*DefaultCart) GetLastUpdateTime ¶
func (it *DefaultCart) GetLastUpdateTime() time.Time
GetLastUpdateTime returns cart last update time
func (*DefaultCart) GetModelName ¶
func (it *DefaultCart) GetModelName() string
GetModelName returns model name we have implementation for
func (*DefaultCart) GetSessionID ¶
func (it *DefaultCart) GetSessionID() string
GetSessionID returns session id last time used for cart
func (*DefaultCart) GetSubtotal ¶
func (it *DefaultCart) GetSubtotal() float64
GetSubtotal returns subtotal for cart items
func (*DefaultCart) GetVisitor ¶
func (it *DefaultCart) GetVisitor() visitor.InterfaceVisitor
GetVisitor returns visitor model represents owner or current cart or nil if visitor was not set to cart
func (*DefaultCart) GetVisitorID ¶
func (it *DefaultCart) GetVisitorID() string
GetVisitorID returns visitor id this cart belongs to
func (*DefaultCart) IsActive ¶
func (it *DefaultCart) IsActive() bool
IsActive returns active flag status of cart
func (*DefaultCart) Load ¶
func (it *DefaultCart) Load(ID string) error
Load loads cart information from DB
func (*DefaultCart) MakeCartForVisitor ¶
func (it *DefaultCart) MakeCartForVisitor(visitorID string) error
MakeCartForVisitor loads cart for given visitor from database or creates new one
func (*DefaultCart) New ¶
func (it *DefaultCart) New() (models.InterfaceModel, error)
New makes new instance of model
func (*DefaultCart) RemoveItem ¶
func (it *DefaultCart) RemoveItem(itemIdx int) error
RemoveItem removes item from cart
- you need to know index you can get from ListItems()
func (*DefaultCart) SetCartInfo ¶
func (it *DefaultCart) SetCartInfo(infoAttribute string, infoValue interface{}) error
SetCartInfo assigns some information to current cart
func (*DefaultCart) SetCustomInfo ¶
func (it *DefaultCart) SetCustomInfo(info map[string]interface{})
func (*DefaultCart) SetQty ¶
func (it *DefaultCart) SetQty(itemIdx int, qty int) error
SetQty sets new qty for particular item in cart
- you need to it's index, use ListItems() for that
func (*DefaultCart) SetSessionID ¶
func (it *DefaultCart) SetSessionID(sessionID string) error
SetSessionID sets session id associated to cart
func (*DefaultCart) SetVisitorID ¶
func (it *DefaultCart) SetVisitorID(visitorID string) error
SetVisitorID sets new owner of cart
func (*DefaultCart) ValidateCart ¶
func (it *DefaultCart) ValidateCart() error
ValidateCart returns nil of cart is valid, error otherwise
type DefaultCartItem ¶
type DefaultCartItem struct { ProductID string Qty int Options map[string]interface{} Cart *DefaultCart // contains filtered or unexported fields }
DefaultCartItem is a default implementer of InterfaceCart
func (*DefaultCartItem) GetCart ¶
func (it *DefaultCartItem) GetCart() cart.InterfaceCart
GetCart returns cart that item belongs to
func (*DefaultCartItem) GetID ¶
func (it *DefaultCartItem) GetID() string
GetID returns id of cart item
func (*DefaultCartItem) GetIdx ¶
func (it *DefaultCartItem) GetIdx() int
GetIdx returns index value for current cart item
func (*DefaultCartItem) GetOptions ¶
func (it *DefaultCartItem) GetOptions() map[string]interface{}
GetOptions returns all item options or nil
func (*DefaultCartItem) GetProduct ¶
func (it *DefaultCartItem) GetProduct() product.InterfaceProduct
GetProduct returns product instance which cart item represents
func (*DefaultCartItem) GetProductID ¶
func (it *DefaultCartItem) GetProductID() string
GetProductID returns product id which cart item represents
func (*DefaultCartItem) GetQty ¶
func (it *DefaultCartItem) GetQty() int
GetQty returns current cart item qty
func (*DefaultCartItem) Remove ¶
func (it *DefaultCartItem) Remove() error
Remove removes item from the cart
func (*DefaultCartItem) SetID ¶
func (it *DefaultCartItem) SetID(newID string) error
SetID sets id to cart item
func (*DefaultCartItem) SetIdx ¶
func (it *DefaultCartItem) SetIdx(newIdx int) error
SetIdx changes index value for current cart item if it is possible
func (*DefaultCartItem) SetOption ¶
func (it *DefaultCartItem) SetOption(optionName string, optionValue interface{}) error
SetOption sets an option to cart item
func (*DefaultCartItem) SetQty ¶
func (it *DefaultCartItem) SetQty(qty int) error
SetQty sets qty for current cart item
func (*DefaultCartItem) ValidateProduct ¶
func (it *DefaultCartItem) ValidateProduct() error
ValidateProduct checks that cart product is existent and have available qty