Limit Order Line Quantity
How-To Guide to limit order line quantity in Umbraco Commerce.
ProductAddValidationHandler
public class ProductAddValidationHandler : ValidationEventHandlerBase<ValidateOrderProductAdd>
{
private readonly IProductService _productService;
public ProductAddValidationHandler(IProductService productService)
{
_productService = productService;
}
public override void Validate(ValidateOrderProductAdd evt)
{
var order = evt.Order;
var productReference = evt.ProductReference;
var stock = _productService.GetProductStock(evt.Order.StoreId, productReference);
if (stock.HasValue && evt.Quantity > stock.Value)
evt.Fail($"Only {stock} quantities can be purchased for {productReference}.");
}
}
OrderLineQuantityValidationHandler
Register event handlers
Last updated
Was this helpful?