I'm creating a product page for a product with multiple variants. In this case the variant represents a different size (with unique SKU, stock, etc..).
It's laid out like so (don't mind the ugly styling):
I don't want to pre-select a size option because I want to avoid people adding the wrong product to their cart.
In the template there's a hidden field with the purchasableId
of the variant. The value attribute starts empty and when people click one of the options it is set to the corresponding id.
<input type="hidden" name="purchasableId" value="">
However, when people click 'Add to cart' right away, without selecting a size the following Craft\Exception is shown:
Not a purchasable ID
How can I customize this error message to notify the customer that they have to select a size option?
I could of course solve this problem by using javascript but that doesn't seem very solid to me. So is there a way of validating the stuff added to the cart in the back-end and getting something like a JSON response?