Skip to main content
Version: 1.5.x

Extension Point: Validate Shopping Item at Add-to-Cart

Basics​

ParameterValue
Extension Point KeyVALIDATE_SHOPPING_ITEM_AT_ADD_TO_CART
Extension Point NameValidate Shopping Item at Add-to-Cart
Extension InterfaceShoppingItemValidator
Supports Multiple Extensions?Yes
Selector TypeStore
Available Since1.0.0

Use Cases​

Extensions implementing this Extension Point can enforce business rules that prevent items from being added to cart. This Extension Point has access to information that is not available to the Product Sku Validator Extension Points, such as the shopping cart, shopper, and any child items being added at the same time.

Methods​

validate​

The validate method is invoked when an item is about to be added to a shopping cart. In Cortex, this happens when the add-to-cart form for an item is POSTed. 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 item can’t be added to cart.

note

The Validate Product Sku During Add-to-Cart Extension Point is invoked at the same time as this Extension Point. This allows the product sku validators to be re-executed whenever an item is added to cart.

Extension Sample​

@Extension
@XPFAssignment(extensionPoint = XPFExtensionPointEnum.VALIDATE_SHOPPING_ITEM_AT_ADD_TO_CART, 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;
}
}