flamingo.me/flamingo-commerce/v3@v3.11.0/test/integrationtest/projecttest/modules/cart/fake_qty_restrictor.go (about)

     1  package cart
     2  
     3  import (
     4  	"context"
     5  
     6  	domainCart "flamingo.me/flamingo-commerce/v3/cart/domain/cart"
     7  	"flamingo.me/flamingo-commerce/v3/cart/domain/validation"
     8  	"flamingo.me/flamingo-commerce/v3/product/domain"
     9  
    10  	"flamingo.me/flamingo/v3/framework/web"
    11  )
    12  
    13  type (
    14  	// FakeQtyRestrictor used to restrict
    15  	FakeQtyRestrictor struct{}
    16  )
    17  
    18  var (
    19  	_ validation.MaxQuantityRestrictor = &FakeQtyRestrictor{}
    20  )
    21  
    22  // Name fake implementation
    23  func (f FakeQtyRestrictor) Name() string {
    24  	return "Name"
    25  }
    26  
    27  // Restrict fake implementation
    28  func (f FakeQtyRestrictor) Restrict(ctx context.Context, session *web.Session, product domain.BasicProduct, cart *domainCart.Cart, deliveryCode string) *validation.RestrictionResult {
    29  	if product.BaseData().MarketPlaceCode == "fake_simple" {
    30  		return &validation.RestrictionResult{
    31  			IsRestricted:        true,
    32  			MaxAllowed:          10,
    33  			RemainingDifference: 10,
    34  			RestrictorName:      f.Name(),
    35  		}
    36  	}
    37  	return &validation.RestrictionResult{
    38  		IsRestricted: false,
    39  	}
    40  }