Skip to main content
Version: 1.4.x

Extension Point: Validate Product Sku at Add-to-Cart Read

Basics​

ParameterValue
Extension Point KeyVALIDATE_PRODUCT_SKU_AT_ADD_TO_CART_READ
Extension Point NameValidate Sku at Add-to-Cart Read
Extension InterfaceProductSkuValidator
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.

Methods​

validate​

The validate method is invoked when Cortex needs to determine if a product SKU can be added to a shopping cart. In Cortex, this happens when the add-to-cart form is read with a GET operation. 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.

Extension Sample​

@Extension
@XPFAssignment(extensionPoint = XPFExtensionPointEnum.VALIDATE_PRODUCT_SKU_AT_ADD_TO_CART_READ, priority = 100)
public class SampleProductSkuValidator extends XPFExtensionPointImpl implements ProductSkuValidator {
@Override
public Collection<StructuredErrorMessage> validate(final XPFProductSkuValidationContext context) {
List<StructuredErrorMessage> results = new ArrayList<>();
if (context.getProductSku().getAttributeValueByKey("block-purchase")
.map(attributeValue -> (boolean) attributeValue.getValue())
.orElse(false)) {
results.add(new StructuredErrorMessage("unpurchasable-product", "Product has 'block-purchase' attribute set.", Collections.emptyMap()));
}
return results;
}
}