I am working on a Magento store that has a custom embroidery option for clothing products. Adding embroidery is optional (not required.) HOWEVER, if you do choose the embroidery option, there are a number of options which then become required, such as the name, font, etc.
I thought I could accomplish this by using javascript to remove the embroidery option fields if the checkbox to “Add embroidery” was not checked, and then using this code in an the overloaded Checkout/CartController.php:
/* Options #23-40 are the embroidery details */
foreach($product->getOptions() as $_option){
if($_option->option_id >= 23 && $_option->option_id <= 40){
$_option->setIsRequire(false);
}
}
This ALMOST did the trick, however when I get to the view cart page, there is this error at the top:
“Some of the products below do not have all the required options. Please edit them and configure all the required options.”
Can someone suggest a different approach, or at least let me know if I’m on the right track? And I’m not interested in buying another module to accomplish this.
Thanks!
The easy “hack” would be to not make them required but add the “required” css class to the input fields in your javascript. This will make Magento complain when you click the “Add to cart” button.