Basket Validators (Checkout Validation)
The BASKET_VALIDATORS setting defines validation rules applied before checkout. These validators ensure basket contents meet business requirements before order creation.
Validator Structure:
{
"condition_klass": "path.to.ValidatorClass",
"kwargs": {
"param1": "value1",
"param2": "value2"
},
"message": {
"en": "Error message in English",
"tr": "Türkçe hata mesajı"
}
}Available Validators:
1. BasketItemQuantityValidator
Validates total quantity of items with specific attribute value
Parameters:
attribute_name: Product attribute to checkattribute_value: Value to matchupper_limit: Maximum allowed quantitylower_limit: Minimum allowed quantity
Use Case: Limit promotional items or restrict bulk purchases by category
Configuration Example:
{ "condition_klass": "omnishop.baskets.validator.BasketItemQuantityValidator", "kwargs": { "attribute_name": "promotion_category", "attribute_value": "black_friday_deal", "upper_limit": 5, "lower_limit": 1 }, "message": { "en": "You can only add between 1 and 5 Black Friday deal items per order", "tr": "Sipariş başına sadece 1 ile 5 arasında Black Friday ürünü ekleyebilirsiniz" } }Product Example: Products tagged with
promotion_category: "black_friday_deal"limited to 5 total units
2. BasketItemBaseCodeQuantityValidator
Validates quantity per product base code
Parameters: Same as BasketItemQuantityValidator
Checks each unique base code separately (prevents buying same product in different variants)
Use Case: Limit purchases per product family regardless of size/color variants
Configuration Example:
Product Example: Shirt with base_code "SHIRT-001" (variants: SHIRT-001-S-RED, SHIRT-001-M-BLUE) limited to 2 total across all variants
3. BasketItemSteppedQuantityValidator
Enforces quantity steps (multiples) with min/max bounds
Parameters:
attribute_name: Attribute containing step value (from product)upper_limit_attribute_name: Attribute for max quantity (from product)lower_limit_attribute_name: Attribute for min quantity (from product)
Use Case: Bulk-only products (wholesale, packaging constraints)
Configuration Example:
Product Example:
Product attributes:
order_step: 6,min_order_quantity: 12,max_order_quantity: 60Valid quantities: 12, 18, 24, 30, 36, 42, 48, 54, 60
Invalid quantities: 10, 15, 70 (not multiples of 6 or outside bounds)
4. AttributeValidator
Validates product attribute has expected value
Parameters:
attribute_name: Attribute to checkexpected_value: Required valuedisabled_on_sub_basket_items: Skip sub-items (default: false)
Use Case: Ensure all basket items meet specific criteria (shipping, region, etc.)
Configuration Example 1 - Shipping Validation:
Configuration Example 2 - Region Lock:
5. SingleDataSourceValidator
Ensures all basket items from same seller (marketplace)
No parameters required
Prevents mixing products from different sellers in single order
Critical for marketplace multi-vendor scenarios
Use Case: Enforce single-seller per order policy in marketplace
Configuration Example:
Behavior: If basket has items from Seller A, cannot add items from Seller B
Validation Timing:
Validators run before checkout/order creation
Errors block order submission
Messages support internationalization
Failed validations return all error messages
Last updated
Was this helpful?

