Extension Point: Validate Shopping Item at Checkout
Basics
Parameter | Value |
---|---|
Extension Point Key | VALIDATE_SHOPPING_ITEM_AT_CHECKOUT |
Extension Point Name | Validate Shopping Item at Checkout |
Extension Interface | ShoppingItemValidator |
Supports Multiple Extensions? | Yes |
Selector Type | Store |
Available Since | 1.0.0 |
Use Cases
Extensions implementing this Extension Point can enforce business rules that prevent items from being purchased. This Extension Point has access to information that is not available to the Product Sku Validator Extension Points, such as the complete shopping cart, the shopper details, and any child items being added at the same time.
Methods
validate
The validate
method is invoked for each item in the shopping cart during checkout. In Cortex, this happens when the cart order resource is read (with a GET
operation), when the purchase form resource is read (with a GET
operation), and when the purchase form is submitted (with a POST
operation).
For the GET
operations, if one or more extensions returns StructuredErrorMessage
objects, then the action link is omitted, and the error message details are returned in the "messages" section of the response so that the shopper can understand why the cart can’t be purchased.
For the POST
operation, if one or more extensions returns StructuredErrorMessage
objects, then a 400 BAD REQUEST
response is returned, and the error message details are returned in the response body so that the shopper can understand why the cart can’t be purchased.
note
The Validate Product Sku at Checkout and Validate Shopping Cart at Checkout Extension Points are invoked at the same time as this Extension Point.
Extension Sample
@Extension
@XPFAssignment(extensionPoint = XPFExtensionPointEnum.VALIDATE_SHOPPING_ITEM_AT_CHECKOUT, priority = 100)
public class BlockingShoppingItemValidator extends XPFExtensionPointImpl implements ShoppingItemValidator {
@Override
public Collection<XPFStructuredErrorMessage> validate(final XPFShoppingItemValidationContext context) {
List<XPFStructuredErrorMessage> results = new ArrayList<>();
results.add(new XPFStructuredErrorMessage("block-add-to-cart", "Always block add-to-cart.", Collections.emptyMap()));
return results;
}
}