infrastructure

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CartStorage

type CartStorage interface {
	GetCart(ctx context.Context, id string) (*domaincart.Cart, error)
	HasCart(ctx context.Context, id string) bool
	StoreCart(ctx context.Context, cart *domaincart.Cart) error
	RemoveCart(ctx context.Context, cart *domaincart.Cart) error
}

CartStorage Interface - might be implemented by other persistence types later as well

type DefaultCartBehaviour

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

DefaultCartBehaviour defines the default cart order behaviour

func (*DefaultCartBehaviour) AddToCart

func (cob *DefaultCartBehaviour) AddToCart(ctx context.Context, cart *domaincart.Cart, deliveryCode string, addRequest domaincart.AddRequest) (*domaincart.Cart, domaincart.DeferEvents, error)

AddToCart add an item to the cart

func (*DefaultCartBehaviour) ApplyAny

ApplyAny applies a voucher or giftcard to the cart

func (*DefaultCartBehaviour) ApplyGiftCard

func (cob *DefaultCartBehaviour) ApplyGiftCard(ctx context.Context, cart *domaincart.Cart, giftCardCode string) (*domaincart.Cart, domaincart.DeferEvents, error)

ApplyGiftCard applies a gift card to the cart if a GiftCard is applied, it will be added to the array AppliedGiftCards on the cart

func (*DefaultCartBehaviour) ApplyVoucher

func (cob *DefaultCartBehaviour) ApplyVoucher(ctx context.Context, cart *domaincart.Cart, couponCode string) (*domaincart.Cart, domaincart.DeferEvents, error)

ApplyVoucher applies a voucher to the cart

func (*DefaultCartBehaviour) CleanCart

CleanCart removes everything from the cart, e.g. deliveries, billing address, etc

func (*DefaultCartBehaviour) CleanDelivery

func (cob *DefaultCartBehaviour) CleanDelivery(ctx context.Context, cart *domaincart.Cart, deliveryCode string) (*domaincart.Cart, domaincart.DeferEvents, error)

CleanDelivery removes a complete delivery with its items from the cart

func (*DefaultCartBehaviour) Complete

Complete a cart and remove from storage

func (*DefaultCartBehaviour) DeleteItem

func (cob *DefaultCartBehaviour) DeleteItem(ctx context.Context, cart *domaincart.Cart, itemID string, deliveryCode string) (*domaincart.Cart, domaincart.DeferEvents, error)

DeleteItem removes an item from the cart

func (*DefaultCartBehaviour) GetCart

func (cob *DefaultCartBehaviour) GetCart(ctx context.Context, cartID string) (*domaincart.Cart, error)

GetCart returns the current cart from storage

func (*DefaultCartBehaviour) Inject

func (cob *DefaultCartBehaviour) Inject(
	cartStorage CartStorage,
	productService domain.ProductService,
	logger flamingo.Logger,
	voucherHandler VoucherHandler,
	giftCardHandler GiftCardHandler,
	config *struct {
		DefaultTaxRate  float64 `inject:"config:commerce.cart.defaultCartAdapter.defaultTaxRate,optional"`
		ProductPricing  string  `inject:"config:commerce.cart.defaultCartAdapter.productPrices"`
		DefaultCurrency string  `inject:"config:commerce.cart.defaultCartAdapter.defaultCurrency"`
	},
)

Inject dependencies

func (*DefaultCartBehaviour) RemoveGiftCard

func (cob *DefaultCartBehaviour) RemoveGiftCard(ctx context.Context, cart *domaincart.Cart, giftCardCode string) (*domaincart.Cart, domaincart.DeferEvents, error)

RemoveGiftCard removes a gift card from the cart if a GiftCard is removed, it will be removed from the array AppliedGiftCards on the cart

func (*DefaultCartBehaviour) RemoveVoucher

func (cob *DefaultCartBehaviour) RemoveVoucher(ctx context.Context, cart *domaincart.Cart, couponCode string) (*domaincart.Cart, domaincart.DeferEvents, error)

RemoveVoucher removes a voucher from the cart

func (*DefaultCartBehaviour) Restore

Restore supplied cart (implements CompleteBehaviour)

func (*DefaultCartBehaviour) StoreNewCart

func (cob *DefaultCartBehaviour) StoreNewCart(ctx context.Context, cart *domaincart.Cart) (*domaincart.Cart, error)

StoreNewCart created and stores a new cart.

func (*DefaultCartBehaviour) UpdateAdditionalData

func (cob *DefaultCartBehaviour) UpdateAdditionalData(ctx context.Context, cart *domaincart.Cart, additionalData *domaincart.AdditionalData) (*domaincart.Cart, domaincart.DeferEvents, error)

UpdateAdditionalData updates additional data

func (*DefaultCartBehaviour) UpdateBillingAddress

func (cob *DefaultCartBehaviour) UpdateBillingAddress(ctx context.Context, cart *domaincart.Cart, billingAddress domaincart.Address) (*domaincart.Cart, domaincart.DeferEvents, error)

UpdateBillingAddress - updates address

func (*DefaultCartBehaviour) UpdateDeliveryInfo

func (cob *DefaultCartBehaviour) UpdateDeliveryInfo(ctx context.Context, cart *domaincart.Cart, deliveryCode string, deliveryInfoUpdateCommand domaincart.DeliveryInfoUpdateCommand) (*domaincart.Cart, domaincart.DeferEvents, error)

UpdateDeliveryInfo updates a delivery info

func (*DefaultCartBehaviour) UpdateDeliveryInfoAdditionalData

func (cob *DefaultCartBehaviour) UpdateDeliveryInfoAdditionalData(ctx context.Context, cart *domaincart.Cart, deliveryCode string, additionalData *domaincart.AdditionalData) (*domaincart.Cart, domaincart.DeferEvents, error)

UpdateDeliveryInfoAdditionalData @todo implement when needed

func (*DefaultCartBehaviour) UpdateItem

UpdateItem updates a cart item

func (*DefaultCartBehaviour) UpdateItems

UpdateItems updates multiple cart items

func (*DefaultCartBehaviour) UpdatePaymentSelection

func (cob *DefaultCartBehaviour) UpdatePaymentSelection(ctx context.Context, cart *domaincart.Cart, paymentSelection domaincart.PaymentSelection) (*domaincart.Cart, domaincart.DeferEvents, error)

UpdatePaymentSelection updates payment on cart

func (*DefaultCartBehaviour) UpdatePurchaser

func (cob *DefaultCartBehaviour) UpdatePurchaser(ctx context.Context, cart *domaincart.Cart, purchaser *domaincart.Person, additionalData *domaincart.AdditionalData) (*domaincart.Cart, domaincart.DeferEvents, error)

UpdatePurchaser - updates purchaser

type DefaultCustomerCartService

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

DefaultCustomerCartService defines the in memory customer cart service

func (*DefaultCustomerCartService) GetCart

func (cs *DefaultCustomerCartService) GetCart(ctx context.Context, identity auth.Identity, _ string) (*cart.Cart, error)

GetCart gets a customer cart from the in memory customer cart service

func (*DefaultCustomerCartService) GetModifyBehaviour

GetModifyBehaviour gets the cart order behaviour of the service

func (*DefaultCustomerCartService) Inject

func (cs *DefaultCustomerCartService) Inject(
	behaviour *DefaultCartBehaviour,
	logger flamingo.Logger,
)

Inject dependencies

func (*DefaultCustomerCartService) RestoreCart

func (cs *DefaultCustomerCartService) RestoreCart(ctx context.Context, _ auth.Identity, cart cart.Cart) (*cart.Cart, error)

RestoreCart restores a previously used cart Deprecated: (deprecated in the interface)

type DefaultGiftCardHandler

type DefaultGiftCardHandler struct{}

DefaultGiftCardHandler implements a basic gift card handler

func (DefaultGiftCardHandler) ApplyGiftCard

func (DefaultGiftCardHandler) ApplyGiftCard(ctx context.Context, cart *domaincart.Cart, _ string) (*domaincart.Cart, error)

ApplyGiftCard is called when applying a gift card

func (DefaultGiftCardHandler) RemoveGiftCard

func (DefaultGiftCardHandler) RemoveGiftCard(ctx context.Context, cart *domaincart.Cart, _ string) (*domaincart.Cart, error)

RemoveGiftCard is called when removing a gift card

type DefaultGuestCartService

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

DefaultGuestCartService defines the in memory guest cart service

func (*DefaultGuestCartService) GetCart

func (gcs *DefaultGuestCartService) GetCart(ctx context.Context, cartID string) (*cart.Cart, error)

GetCart fetches a cart from the in memory guest cart service

func (*DefaultGuestCartService) GetModifyBehaviour

func (gcs *DefaultGuestCartService) GetModifyBehaviour(ctx context.Context) (cart.ModifyBehaviour, error)

GetModifyBehaviour returns the cart order behaviour of the service

func (*DefaultGuestCartService) GetNewCart

func (gcs *DefaultGuestCartService) GetNewCart(ctx context.Context) (*cart.Cart, error)

GetNewCart gets a new cart from the in memory guest cart service

func (*DefaultGuestCartService) Inject

func (gcs *DefaultGuestCartService) Inject(
	InMemoryCartOrderBehaviour *DefaultCartBehaviour,
	logger flamingo.Logger,
)

Inject dependencies

func (*DefaultGuestCartService) RestoreCart

func (gcs *DefaultGuestCartService) RestoreCart(ctx context.Context, cart cart.Cart) (*cart.Cart, error)

RestoreCart restores a previously used guest cart Deprecated: (deprecated in the interface)

type DefaultVoucherHandler

type DefaultVoucherHandler struct{}

DefaultVoucherHandler implements a basic voucher handler

func (DefaultVoucherHandler) ApplyVoucher

ApplyVoucher is called when applying a voucher

func (DefaultVoucherHandler) RemoveVoucher

func (DefaultVoucherHandler) RemoveVoucher(ctx context.Context, cart *domaincart.Cart, _ string) (*domaincart.Cart, error)

RemoveVoucher is called when removing a voucher

type GiftCardHandler

type GiftCardHandler interface {
	ApplyGiftCard(ctx context.Context, cart *domaincart.Cart, giftCardCode string) (*domaincart.Cart, error)
	RemoveGiftCard(ctx context.Context, cart *domaincart.Cart, giftCardCode string) (*domaincart.Cart, error)
}

GiftCardHandler enables the projects to have specific GiftCard handling

type InMemoryCartStorage

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

InMemoryCartStorage - for now the default implementation of GuestCartStorage

func (*InMemoryCartStorage) GetCart

func (s *InMemoryCartStorage) GetCart(ctx context.Context, id string) (*domaincart.Cart, error)

GetCart returns a cart with the given id from the cart storage

func (*InMemoryCartStorage) HasCart

func (s *InMemoryCartStorage) HasCart(ctx context.Context, id string) bool

HasCart checks if the cart storage has a cart with a given id

func (*InMemoryCartStorage) Inject

Inject dependencies and prepare storage Important: InMemoryStorage MUST be bound AsEagerSingleton, Inject MUST be called in tests to behave as expected

func (*InMemoryCartStorage) RemoveCart

func (s *InMemoryCartStorage) RemoveCart(ctx context.Context, cart *domaincart.Cart) error

RemoveCart from storage

func (*InMemoryCartStorage) StoreCart

func (s *InMemoryCartStorage) StoreCart(ctx context.Context, cart *domaincart.Cart) error

StoreCart stores a cart in the storage

type VoucherHandler

type VoucherHandler interface {
	ApplyVoucher(ctx context.Context, cart *domaincart.Cart, couponCode string) (*domaincart.Cart, error)
	RemoveVoucher(ctx context.Context, cart *domaincart.Cart, couponCode string) (*domaincart.Cart, error)
}

VoucherHandler enables the projects to have specific Voucher handling

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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