flamingo.me/flamingo-commerce/v3@v3.11.0/cart/application/service.go (about)

     1  package application
     2  
     3  //go:generate go run github.com/vektra/mockery/v2@v2.42.3 --name Service --case snake --structname CartService
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  
     9  	"flamingo.me/flamingo/v3/framework/web"
    10  
    11  	cartDomain "flamingo.me/flamingo-commerce/v3/cart/domain/cart"
    12  	"flamingo.me/flamingo-commerce/v3/cart/domain/decorator"
    13  	"flamingo.me/flamingo-commerce/v3/cart/domain/placeorder"
    14  	"flamingo.me/flamingo-commerce/v3/cart/domain/validation"
    15  	productDomain "flamingo.me/flamingo-commerce/v3/product/domain"
    16  )
    17  
    18  type (
    19  	// Service that provides functionality regarding the cart
    20  	Service interface {
    21  		GetCartReceiverService() *CartReceiverService
    22  		ValidateCart(ctx context.Context, session *web.Session, decoratedCart *decorator.DecoratedCart) validation.Result
    23  		ValidateCurrentCart(ctx context.Context, session *web.Session) (validation.Result, error)
    24  		UpdatePaymentSelection(ctx context.Context, session *web.Session, paymentSelection cartDomain.PaymentSelection) error
    25  		UpdateBillingAddress(ctx context.Context, session *web.Session, billingAddress *cartDomain.Address) error
    26  		UpdateDeliveryInfo(ctx context.Context, session *web.Session, deliveryCode string, deliveryInfo cartDomain.DeliveryInfoUpdateCommand) error
    27  		UpdatePurchaser(ctx context.Context, session *web.Session, purchaser *cartDomain.Person, additionalData *cartDomain.AdditionalData) error
    28  		UpdateItemQty(ctx context.Context, session *web.Session, itemID string, deliveryCode string, qty int) error
    29  		UpdateItemSourceID(ctx context.Context, session *web.Session, itemID string, sourceID string) error
    30  		UpdateItems(ctx context.Context, session *web.Session, updateCommands []cartDomain.ItemUpdateCommand) error
    31  		UpdateItemBundleConfig(ctx context.Context, session *web.Session, updateCommand cartDomain.ItemUpdateCommand) error
    32  		DeleteItem(ctx context.Context, session *web.Session, itemID string, deliveryCode string) error
    33  		DeleteAllItems(ctx context.Context, session *web.Session) error
    34  		CompleteCurrentCart(ctx context.Context) (*cartDomain.Cart, error)
    35  		RestoreCart(ctx context.Context, cart *cartDomain.Cart) (*cartDomain.Cart, error)
    36  		Clean(ctx context.Context, session *web.Session) error
    37  		DeleteDelivery(ctx context.Context, session *web.Session, deliveryCode string) (*cartDomain.Cart, error)
    38  		// Deprecated: build your own add request
    39  		BuildAddRequest(ctx context.Context, marketplaceCode string, variantMarketplaceCode string, qty int, additionalData map[string]string) cartDomain.AddRequest
    40  		AddProduct(ctx context.Context, session *web.Session, deliveryCode string, addRequest cartDomain.AddRequest) (productDomain.BasicProduct, error)
    41  		CreateInitialDeliveryIfNotPresent(ctx context.Context, session *web.Session, deliveryCode string) (*cartDomain.Cart, error)
    42  		GetInitialDelivery(deliveryCode string) (*cartDomain.DeliveryInfo, error)
    43  		ApplyVoucher(ctx context.Context, session *web.Session, couponCode string) (*cartDomain.Cart, error)
    44  		ApplyAny(ctx context.Context, session *web.Session, anyCode string) (*cartDomain.Cart, error)
    45  		RemoveVoucher(ctx context.Context, session *web.Session, couponCode string) (*cartDomain.Cart, error)
    46  		ApplyGiftCard(ctx context.Context, session *web.Session, couponCode string) (*cartDomain.Cart, error)
    47  		RemoveGiftCard(ctx context.Context, session *web.Session, couponCode string) (*cartDomain.Cart, error)
    48  		DeleteCartInCache(ctx context.Context, session *web.Session, cart *cartDomain.Cart)
    49  		ReserveOrderIDAndSave(ctx context.Context, session *web.Session) (*cartDomain.Cart, error)
    50  		ForceReserveOrderIDAndSave(ctx context.Context, session *web.Session) (*cartDomain.Cart, error)
    51  		PlaceOrderWithCart(ctx context.Context, session *web.Session, cart *cartDomain.Cart, payment *placeorder.Payment) (placeorder.PlacedOrderInfos, error)
    52  		PlaceOrder(ctx context.Context, session *web.Session, payment *placeorder.Payment) (placeorder.PlacedOrderInfos, error)
    53  		CancelOrder(ctx context.Context, session *web.Session, orderInfos placeorder.PlacedOrderInfos, cart cartDomain.Cart) (*cartDomain.Cart, error)
    54  		CancelOrderWithoutRestore(ctx context.Context, session *web.Session, orderInfos placeorder.PlacedOrderInfos) error
    55  		GetDefaultDeliveryCode() string
    56  		AdjustItemsToRestrictedQty(ctx context.Context, session *web.Session) (QtyAdjustmentResults, error)
    57  		UpdateAdditionalData(ctx context.Context, session *web.Session, additionalData map[string]string) (*cartDomain.Cart, error)
    58  		UpdateDeliveryAdditionalData(ctx context.Context, session *web.Session, deliveryCode string, additionalData map[string]string) (*cartDomain.Cart, error)
    59  	}
    60  )
    61  
    62  var (
    63  	// ErrNoBundleConfigurationGiven returned when bundle configuration is not provided
    64  	ErrNoBundleConfigurationGiven = errors.New("no bundle configuration given for configurable product")
    65  
    66  	// ErrNoVariantForConfigurable returned when type configurable with active variant do not have variant selected
    67  	ErrNoVariantForConfigurable = errors.New("no variant given for configurable product")
    68  
    69  	// ErrVariantDoNotExist returned when selected variant do not exist
    70  	ErrVariantDoNotExist = errors.New("product has not the given variant")
    71  )