|
1 | 1 | ---
|
2 |
| -description: How-To Guide to limit order line quantity in Umbraco Commerce. |
| 2 | +description: Guide to limit order line quantity in Umbraco Commerce. |
3 | 3 | ---
|
4 | 4 |
|
5 | 5 | # Limit Order Line Quantity
|
6 | 6 |
|
7 |
| -In this guide, we will be looking at Validation events in Umbraco Commerce. These enabled you to limit order line quantity based on: |
| 7 | +{% hint style="info" %} |
| 8 | +Since Commerce 15.3.2, there is a built-in orderline quantity check that handles the validation automatically. |
| 9 | +{% endhint %} |
| 10 | + |
| 11 | +This guide explains custom validation event handlers in Umbraco Commerce that enable limiting order line quantities based on: |
8 | 12 |
|
9 | 13 | * The existing stock value of the product, and
|
10 | 14 | * The existing quantity of the product in the cart.
|
11 | 15 |
|
12 | 16 | ## ProductAddValidationHandler
|
13 | 17 |
|
14 |
| -When adding a product to the cart we need to verify that the product is in stock. We also need to verify that the customer does not already have the remaining quantities in the cart. |
| 18 | +When adding a product to the cart, verify that the product is in stock. Also, ensure the customer does not exceed the available quantity in the cart. |
15 | 19 |
|
16 | 20 | ```csharp
|
17 | 21 | public class ProductAddValidationHandler : ValidationEventHandlerBase<ValidateOrderProductAdd>
|
@@ -41,7 +45,7 @@ public class ProductAddValidationHandler : ValidationEventHandlerBase<ValidateOr
|
41 | 45 |
|
42 | 46 | ## OrderLineQuantityValidationHandler
|
43 | 47 |
|
44 |
| -When changing the order line quantity on the cart page, we need to ensure that the quantities being changed are in stock. |
| 48 | +When changing the order line quantity on the cart page, ensure that the quantities being changed are in stock. |
45 | 49 |
|
46 | 50 | ```csharp
|
47 | 51 | public class OrderLineQuantityValidationHandler : ValidationEventHandlerBase<ValidateOrderLineQuantityChange>
|
@@ -69,7 +73,7 @@ public class OrderLineQuantityValidationHandler : ValidationEventHandlerBase<Val
|
69 | 73 |
|
70 | 74 | ## Register event handlers
|
71 | 75 |
|
72 |
| -Finally, we need to register the Umbraco Commerce event handlers via an `IUmbracoCommerceBuilder` extension. |
| 76 | +Register the Umbraco Commerce event handlers via an `IUmbracoCommerceBuilder` extension method. |
73 | 77 |
|
74 | 78 | ```csharp
|
75 | 79 | public static class UmbracoCommerceUmbracoBuilderExtensions
|
|
0 commit comments