Magento v1.3.0: Option validation failed to add product to cart
After upgrading a clients Magento site from 1.2.1.2 to version 1.3.0, they reported an issue not being able to add products with required selectable options, as it would always return “Option validation failed to add product to cart” Message even though all requirements are met.
The issue I’ve found to be is in a newly created file in 1.3.0: /app/code/core/Mage/Catalog/Model/Product/Option/Type/Select.php
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * Prepare option value for cart * * @throws Mage_Core_Exception * @return mixed Prepared option value */ public function prepareForCart() { if ($this->getIsValid()) { return is_array($this->getUserValue()) ? implode(',', $this->getUserValue()) : $this->getUserValue(); } #Mage::throwException(Mage::helper('catalog')->__('Option validation failed to add product to cart')); } |
Apply a comment to the Mage::throwException … and it will fix the issue.
Note the use of a shorthand if statement within the return for the function, which in all honesty is bad coding practice. I say Magento makes the developer go onto code review for the next week for punishment. I’ve known some shops to do this when they get lazy. ![]()
However, $this->getIsValid() will return true, for a few cycles through but ultimately seems to come back to the exception and return false, which leads me to thing there is more to bug than just a simple conditional return statement.
Keep in mind this is by no means a official fix but will tie you over until the bug fix is released, which has already been reported and assigned. Also if you do make this change you may want to keep a copy of the original file as modifying app/core/ can lead to upgrade issues in the future, and you’ll need to restore the original file upon upgrading.
It appears this also has fixed another issue I noticed, within the Admin, attempting to Create a New Order, upon attempting to add products to the order, nothing would be returned and no error presented. After my fix above this now working properly as well. This other issue has also been reported already and assigned as well.
According the 1.2.1.2 to 1.3.0 .diff file, this file is a newly created file.
Here is a forum thread discussing the issue:
Magento – Option validation failed to add product to cart – Magento 1.3.0 Upgrade Issues – eCommerce Software for Growth.
Possibly Related Posts:
- Magento vs X-Cart
- Magento version 2.0 (X.Commerce) and eBay
- Magento Supercharged Development Tools and Links
- Book Review: Magento 1.4 Themes Design by PacktLib
- Magento modules post deployment uninstall & downgrading
07Apr2009










Pingback: failed validation