Home > widget-integration > CartDrawerRecommendationController > getAddToCartQuantity
CartDrawerRecommendationController.getAddToCartQuantity() method
Get the quantity to add when clicking the Add to Cart button. Override to implement quantity pickers or per-product custom quantities.
Signature:
protected getAddToCartQuantity(productItem: HTMLElement): number;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
productItem |
HTMLElement |
The product item element (for reading data attributes) |
Returns:
number
Quantity to add (default: 1)
Example
Override to read quantity from a number input on the product card:
window.boostWidgetIntegration.extend('CartDrawerRecommendationController', (Base) => {
return class extends Base {
getAddToCartQuantity(productItem) {
const input = productItem.querySelector('input[type="number"]');
return input ? parseInt(input.value, 10) || 1 : 1;
}
};
});