A very lightweight plugin to have custom cart validation rules before proceeding to checkout. For example to check current stock, or check for limited products. You can implement your own validation rules by implementing the CartValidatorStrategy interface.
Add the plugin to your config:
This will add a validateActiveOrder mutation to the shop API.
Depending on your validation strategy, you probably want to call the validateActiveOrder mutation in the cart page, and again on the payment page:
If any validation errors are returned, you can display the error to the user with the corresponding order lines. You could even automatically remove the items from the cart based on the relatedOrderLineIds. The order field returns the active order after validation, including any modifications made by a custom validation strategy.
This action is a mutation rather than a query, because your custom validation logic might need to modify the order, for example to 'lock' an order after validation until payment is completed.
You can implement your own validation rules by implementing the CartValidatorStrategy interface. For example, to check if active promotions are still valid for the items in the cart.
The property totalQuantity on the Order entity requires the Order.lines relation to be joined when querying calculated Order fields (e.g. totalQuantity, total, totalWithTax, subTotal) on the validateActiveOrder result. The lines relation is now always joined when refetching the order.validateActiveOrder now returns a ValidateActiveOrderResult object with both errors and order fields.@Relations decorator to load the requested order relations in the response.validateActiveOrder mutation return type changed from [ActiveOrderValidationError!]! to ValidateActiveOrderResult!.