cart

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: 14 Imported by: 0

Documentation

Overview

Package cart is a default implementation of interfaces declared in "github.com/ottemo/commerce/app/models/cart" package

Index

Constants

View Source
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

type AbandonVisitor struct {
	Email     string
	FirstName string
	LastName  string
}

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) GetID

func (it *DefaultCart) GetID() string

GetID returns id of current cart

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) Save

func (it *DefaultCart) Save() error

Save stores current cart in DB

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) SetID

func (it *DefaultCart) SetID(NewID string) error

SetID sets id for cart

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

Jump to

Keyboard shortcuts

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