application

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: OSL-3.0 Imports: 17 Imported by: 14

Documentation

Index

Constants

View Source
const (
	// CartSessionCacheCacheKeyPrefix is a string prefix for Cart Cache Keys
	CartSessionCacheCacheKeyPrefix = "cart.sessioncache."
)
View Source
const (
	// GuestCartSessionKey is a prefix
	GuestCartSessionKey = "cart.guestid"
)

Variables

View Source
var (

	// ErrCacheIsInvalid sets generalized invalid Cache Error
	ErrCacheIsInvalid = errors.New("cache is invalid")
	// ErrNoCacheEntry - used if cahce is not found
	ErrNoCacheEntry = errors.New("cache entry not found")
)
View Source
var (
	//ErrTemporaryCartService - should be returned if it is likely that the backend service will return a cart on a next try
	ErrTemporaryCartService = errors.New("the cart could not be received currently - try again later")
)

Functions

This section is empty.

Types

type AuthManagerInterface

type AuthManagerInterface interface {
	Auth(c context.Context, session *web.Session) (OAuthDomain.Auth, error)
}

AuthManagerInterface is the interface required to get Auth infos for CustomerCart handling

type CachedCartEntry

type CachedCartEntry struct {
	IsInvalid bool
	Entry     cart.Cart
	ExpiresOn time.Time
}

CachedCartEntry defines a single Cart Cache Entry

type CartCache

CartCache describes a cart caches methods

type CartCacheIdentifier

type CartCacheIdentifier struct {
	GuestCartID    string
	IsCustomerCart bool
	CustomerID     string
}

CartCacheIdentifier identifies Cart Caches

func BuildIdentifierFromCart

func BuildIdentifierFromCart(cart *cart.Cart) (*CartCacheIdentifier, error)

BuildIdentifierFromCart creates a Cache Identifier from Cart Data DEPRICATED

func (*CartCacheIdentifier) CacheKey

func (ci *CartCacheIdentifier) CacheKey() string

CacheKey creates a Cache Key Identifier string

type CartReceiverService

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

CartReceiverService provides methods to get the correct cart

func (*CartReceiverService) DecorateCart

DecorateCart Get the correct Cart

func (*CartReceiverService) GetCart

GetCart Get the correct Cart (either Guest or User)

func (*CartReceiverService) GetCartWithoutCache

func (cs *CartReceiverService) GetCartWithoutCache(ctx context.Context, session *web.Session) (*cartDomain.Cart, error)

GetCartWithoutCache - forces to get the cart without cache

func (*CartReceiverService) GetDecoratedCart

GetDecoratedCart Get the correct Cart

func (*CartReceiverService) Inject

func (cs *CartReceiverService) Inject(
	guestCartService cartDomain.GuestCartService,
	customerCartService cartDomain.CustomerCartService,
	cartDecoratorFactory *decorator.DecoratedCartFactory,
	authManager AuthManagerInterface,
	userService authApplication.UserServiceInterface,
	logger flamingo.Logger,
	eventRouter flamingo.EventRouter,
	optionals *struct {
		CartCache CartCache `inject:",optional"`
	},
)

Inject the dependencies

func (*CartReceiverService) IsLoggedIn

func (cs *CartReceiverService) IsLoggedIn(ctx context.Context, session *web.Session) bool

IsLoggedIn returns the logged in state

func (*CartReceiverService) ModifyBehaviour added in v3.1.0

func (cs *CartReceiverService) ModifyBehaviour(ctx context.Context) (cartDomain.ModifyBehaviour, error)

ModifyBehaviour returns the correct behaviour to modify the cart for the current user (guest/customer)

func (*CartReceiverService) RestoreCart

func (cs *CartReceiverService) RestoreCart(ctx context.Context, session *web.Session, cartToRestore cart.Cart) (*cartDomain.Cart, error)

RestoreCart restores a previously used guest / customer cart deprecated: use CartService.RestoreCart(), ensure that your cart implements the CompleteBehaviour

func (*CartReceiverService) ShouldHaveCart

func (cs *CartReceiverService) ShouldHaveCart(ctx context.Context, session *web.Session) bool

ShouldHaveCart - checks if there should be a cart. Indicated if a call to GetCart should return a real cart

func (*CartReceiverService) ShouldHaveGuestCart

func (cs *CartReceiverService) ShouldHaveGuestCart(session *web.Session) bool

ShouldHaveGuestCart - checks if there should be guest cart

func (*CartReceiverService) ViewCart

func (cs *CartReceiverService) ViewCart(ctx context.Context, session *web.Session) (*cartDomain.Cart, error)

ViewCart return a Cart for view

func (*CartReceiverService) ViewDecoratedCart

func (cs *CartReceiverService) ViewDecoratedCart(ctx context.Context, session *web.Session) (*decorator.DecoratedCart, error)

ViewDecoratedCart return a Cart for view

func (*CartReceiverService) ViewDecoratedCartWithoutCache

func (cs *CartReceiverService) ViewDecoratedCartWithoutCache(ctx context.Context, session *web.Session) (*decorator.DecoratedCart, error)

ViewDecoratedCartWithoutCache return a Cart for view

func (*CartReceiverService) ViewGuestCart

func (cs *CartReceiverService) ViewGuestCart(ctx context.Context, session *web.Session) (*cartDomain.Cart, error)

ViewGuestCart try to get the guest Cart - even if the user is logged in

type CartService

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

CartService provides methods to modify the cart

func (*CartService) AddProduct

func (cs *CartService) AddProduct(ctx context.Context, session *web.Session, deliveryCode string, addRequest cartDomain.AddRequest) (productDomain.BasicProduct, error)

AddProduct adds a product to the cart

func (*CartService) AdjustItemsToRestrictedQty

func (cs *CartService) AdjustItemsToRestrictedQty(ctx context.Context, session *web.Session) (QtyAdjustmentResults, error)

AdjustItemsToRestrictedQty checks the quantity restrictions for each item of the cart and returns what quantities have been adjusted

func (*CartService) ApplyAny

func (cs *CartService) ApplyAny(ctx context.Context, session *web.Session, anyCode string) (*cartDomain.Cart, error)

ApplyAny applies a voucher or giftcard to the cart

func (*CartService) ApplyGiftCard

func (cs *CartService) ApplyGiftCard(ctx context.Context, session *web.Session, couponCode string) (*cartDomain.Cart, error)

ApplyGiftCard adds a giftcard to the cart

func (*CartService) ApplyVoucher

func (cs *CartService) ApplyVoucher(ctx context.Context, session *web.Session, couponCode string) (*cartDomain.Cart, error)

ApplyVoucher applies a voucher to the cart

func (*CartService) BuildAddRequest

func (cs *CartService) BuildAddRequest(ctx context.Context, marketplaceCode string, variantMarketplaceCode string, qty int, additionalData map[string]string) cartDomain.AddRequest

BuildAddRequest Helper to build

func (*CartService) CancelOrder

func (cs *CartService) CancelOrder(ctx context.Context, session *web.Session, orderInfos placeorder.PlacedOrderInfos, cart cartDomain.Cart) (*cartDomain.Cart, error)

CancelOrder cancels a previously placed order and restores the cart content

func (*CartService) CancelOrderWithoutRestore added in v3.1.0

func (cs *CartService) CancelOrderWithoutRestore(ctx context.Context, session *web.Session, orderInfos placeorder.PlacedOrderInfos) error

CancelOrderWithoutRestore cancels a previously placed order

func (*CartService) Clean

func (cs *CartService) Clean(ctx context.Context, session *web.Session) error

Clean current cart

func (*CartService) CompleteCurrentCart added in v3.1.0

func (cs *CartService) CompleteCurrentCart(ctx context.Context) (*cartDomain.Cart, error)

CompleteCurrentCart and remove from cache

func (*CartService) CreateInitialDeliveryIfNotPresent

func (cs *CartService) CreateInitialDeliveryIfNotPresent(ctx context.Context, session *web.Session, deliveryCode string) (*cartDomain.Cart, error)

CreateInitialDeliveryIfNotPresent creates the initial delivery

func (*CartService) DeleteAllItems

func (cs *CartService) DeleteAllItems(ctx context.Context, session *web.Session) error

DeleteAllItems in current cart

func (*CartService) DeleteCartInCache

func (cs *CartService) DeleteCartInCache(ctx context.Context, session *web.Session, cart *cartDomain.Cart)

DeleteCartInCache removes the cart from cache

func (*CartService) DeleteDelivery

func (cs *CartService) DeleteDelivery(ctx context.Context, session *web.Session, deliveryCode string) (*cartDomain.Cart, error)

DeleteDelivery in current cart

func (*CartService) DeleteItem

func (cs *CartService) DeleteItem(ctx context.Context, session *web.Session, itemID string, deliveryCode string) error

DeleteItem in current cart

func (*CartService) DeleteSavedSessionGuestCartID

func (cs *CartService) DeleteSavedSessionGuestCartID(session *web.Session) error

DeleteSavedSessionGuestCartID deletes a guest cart Key from the Session Values

func (*CartService) ForceReserveOrderIDAndSave

func (cs *CartService) ForceReserveOrderIDAndSave(ctx context.Context, session *web.Session) (*cartDomain.Cart, error)

ForceReserveOrderIDAndSave reserves order id by using the PlaceOrder behaviour, sets and saves it on the cart. Each call of this method reserves a new order ID, even if it is already set on the cart. You may want to use this before proceeding with payment to ensure having a useful reference in the payment processing

func (*CartService) GetCartReceiverService

func (cs *CartService) GetCartReceiverService() *CartReceiverService

GetCartReceiverService returns the injected cart receiver service

func (*CartService) GetDefaultDeliveryCode

func (cs *CartService) GetDefaultDeliveryCode() string

GetDefaultDeliveryCode returns the configured default deliverycode

func (*CartService) GetInitialDelivery

func (cs *CartService) GetInitialDelivery(deliveryCode string) (*cartDomain.DeliveryInfo, error)

GetInitialDelivery - calls the registered deliveryInfoBuilder to get the initial values for a Delivery based on the given code

func (*CartService) Inject

func (cs *CartService) Inject(
	cartReceiverService *CartReceiverService,
	productService productDomain.ProductService,
	eventPublisher events.EventPublisher,
	eventRouter flamingo.EventRouter,
	deliveryInfoBuilder cartDomain.DeliveryInfoBuilder,
	restrictionService *validation.RestrictionService,
	authManager AuthManagerInterface,
	logger flamingo.Logger,
	config *struct {
		DefaultDeliveryCode string `inject:"config:commerce.cart.defaultDeliveryCode,optional"`
		DeleteEmptyDelivery bool   `inject:"config:commerce.cart.deleteEmptyDelivery,optional"`
	},
	optionals *struct {
		CartValidator     validation.Validator     `inject:",optional"`
		ItemValidator     validation.ItemValidator `inject:",optional"`
		CartCache         CartCache                `inject:",optional"`
		PlaceOrderService placeorder.Service       `inject:",optional"`
	},
)

Inject dependencies

func (*CartService) PlaceOrder

func (cs *CartService) PlaceOrder(ctx context.Context, session *web.Session, payment *placeorder.Payment) (placeorder.PlacedOrderInfos, error)

PlaceOrder converts the cart (possibly cached) with payments into orders by calling the Service

func (*CartService) PlaceOrderWithCart

func (cs *CartService) PlaceOrderWithCart(ctx context.Context, session *web.Session, cart *cartDomain.Cart, payment *placeorder.Payment) (placeorder.PlacedOrderInfos, error)

PlaceOrderWithCart converts the given cart with payments into orders by calling the Service

func (*CartService) RemoveGiftCard

func (cs *CartService) RemoveGiftCard(ctx context.Context, session *web.Session, couponCode string) (*cartDomain.Cart, error)

RemoveGiftCard removes a giftcard from the cart

func (*CartService) RemoveVoucher

func (cs *CartService) RemoveVoucher(ctx context.Context, session *web.Session, couponCode string) (*cartDomain.Cart, error)

RemoveVoucher removes a voucher from the cart

func (*CartService) ReserveOrderIDAndSave

func (cs *CartService) ReserveOrderIDAndSave(ctx context.Context, session *web.Session) (*cartDomain.Cart, error)

ReserveOrderIDAndSave reserves order id by using the PlaceOrder behaviour, sets and saves it on the cart. If the cart already holds a reserved order id no set/save is performed and the existing cart is returned. You may want to use this before proceeding with payment to ensure having a useful reference in the payment processing

func (*CartService) RestoreCart added in v3.1.0

func (cs *CartService) RestoreCart(ctx context.Context, cart *cartDomain.Cart) (*cartDomain.Cart, error)

RestoreCart and cache

func (*CartService) UpdateBillingAddress

func (cs *CartService) UpdateBillingAddress(ctx context.Context, session *web.Session, billingAddress *cartDomain.Address) error

UpdateBillingAddress updates the billing address on the cart

func (*CartService) UpdateDeliveryInfo

func (cs *CartService) UpdateDeliveryInfo(ctx context.Context, session *web.Session, deliveryCode string, deliveryInfo cartDomain.DeliveryInfoUpdateCommand) error

UpdateDeliveryInfo updates the delivery info on the cart

func (*CartService) UpdateItemQty

func (cs *CartService) UpdateItemQty(ctx context.Context, session *web.Session, itemID string, deliveryCode string, qty int) error

UpdateItemQty updates a single cart item qty

func (*CartService) UpdateItemSourceID

func (cs *CartService) UpdateItemSourceID(ctx context.Context, session *web.Session, itemID string, sourceID string) error

UpdateItemSourceID updates an item source id

func (*CartService) UpdateItems

func (cs *CartService) UpdateItems(ctx context.Context, session *web.Session, updateCommands []cartDomain.ItemUpdateCommand) error

UpdateItems updates multiple items

func (*CartService) UpdatePaymentSelection

func (cs *CartService) UpdatePaymentSelection(ctx context.Context, session *web.Session, paymentSelection cartDomain.PaymentSelection) error

UpdatePaymentSelection updates the paymentselection in the cart

func (*CartService) UpdatePurchaser

func (cs *CartService) UpdatePurchaser(ctx context.Context, session *web.Session, purchaser *cartDomain.Person, additionalData *cartDomain.AdditionalData) error

UpdatePurchaser updates the purchaser on the cart

func (*CartService) ValidateCart

func (cs *CartService) ValidateCart(ctx context.Context, session *web.Session, decoratedCart *decorator.DecoratedCart) validation.Result

ValidateCart validates a carts content

func (*CartService) ValidateCurrentCart

func (cs *CartService) ValidateCurrentCart(ctx context.Context, session *web.Session) (validation.Result, error)

ValidateCurrentCart validates the current active cart

type CartSessionCache

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

CartSessionCache defines a Cart Cache

func (*CartSessionCache) BuildIdentifier

func (cs *CartSessionCache) BuildIdentifier(ctx context.Context, session *web.Session) (CartCacheIdentifier, error)

BuildIdentifier creates a CartCacheIdentifier based on the login state

func (*CartSessionCache) CacheCart

func (cs *CartSessionCache) CacheCart(ctx context.Context, session *web.Session, id CartCacheIdentifier, cartForCache *cart.Cart) error

CacheCart adds a Cart to the Cache

func (*CartSessionCache) Delete

func (cs *CartSessionCache) Delete(ctx context.Context, session *web.Session, id CartCacheIdentifier) error

Delete a Cache entry

func (*CartSessionCache) DeleteAll

func (cs *CartSessionCache) DeleteAll(ctx context.Context, session *web.Session) error

DeleteAll empties the Cache

func (*CartSessionCache) GetCart

func (cs *CartSessionCache) GetCart(ctx context.Context, session *web.Session, id CartCacheIdentifier) (*cart.Cart, error)

GetCart fetches a Cart from the Cache

func (*CartSessionCache) Inject

func (cs *CartSessionCache) Inject(
	authManager *authApplication.AuthManager,
	userService *authApplication.UserService,
	logger flamingo.Logger,
	config *struct {
		LifetimeSeconds float64 `inject:"config:commerce.cart.cacheLifetime"` // in seconds
	},
)

Inject the dependencies

func (*CartSessionCache) Invalidate

func (cs *CartSessionCache) Invalidate(ctx context.Context, session *web.Session, id CartCacheIdentifier) error

Invalidate a Cache Entry

type EventReceiver

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

EventReceiver - handles events from other packages

func (*EventReceiver) Inject

func (e *EventReceiver) Inject(
	logger flamingo.Logger,
	cartService *CartService,
	cartReceiverService *CartReceiverService,
	optionals *struct {
		CartCache CartCache `inject:",optional"`
	},
)

Inject dependencies

func (*EventReceiver) Notify

func (e *EventReceiver) Notify(ctx context.Context, event flamingo.Event)

Notify should get called by flamingo Eventlogic

type QtyAdjustmentResult

type QtyAdjustmentResult struct {
	OriginalItem          cartDomain.Item
	DeliveryCode          string
	WasDeleted            bool
	RestrictionResult     *validation.RestrictionResult
	NewQty                int
	HasRemovedCouponCodes bool
}

QtyAdjustmentResult restriction result enriched with the respective item

type QtyAdjustmentResults

type QtyAdjustmentResults []QtyAdjustmentResult

QtyAdjustmentResults slice of QtyAdjustmentResult

func (QtyAdjustmentResults) HasRemovedCouponCodes added in v3.0.1

func (qar QtyAdjustmentResults) HasRemovedCouponCodes() bool

HasRemovedCouponCodes returns if a QtyAdjustmentResults has any adjustment that removed a coupon code from the cart

type RestrictionError

type RestrictionError struct {
	CartItemID        string
	RestrictionResult validation.RestrictionResult
	// contains filtered or unexported fields
}

RestrictionError error enriched with result of restrictions

func (*RestrictionError) Error

func (e *RestrictionError) Error() string

Error fetch error message

Jump to

Keyboard shortcuts

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