Apr 7 2009

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. :lol:

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:
:arrow: Magento – Option validation failed to add product to cart – Magento 1.3.0 Upgrade Issues – eCommerce Software for Growth.

Possibly Related Posts:



Apr 1 2009

Magento Login Error after 1.3.0 upgrade fix

After upgrading a fresh out of box 1.2.1.2 and upgrading via MagentoConnect I noticed an error others have reported as well.

:!: Invalid method Mage_Adminhtml_Model_Url::useSecretKey(Array)

It may merely be a permission issue as I didn’t use SSH to perform the upgrade with PEAR, to avoid permission issues. :x

Here’s what fixed it for me, for some reason Usesecretkey.php was not created during an upgrade through MagentoConnect, and Url.php was not updated…

Download the full 1.3.0 zip or tarball and copy Usessecretkey.php and overwriting Url.php:

1
2
\app\code\core\Mage\Adminhtml\Model\System\Config\Backend\Admin\Usesecretkey.php
\app\code\core\Mage\Adminhtml\Model\Url.php

Usesecreykey.php is in the .diff file, and my original install before upgrade was 1.2.1.2, the file didn’t exist before: Note the revision number, and all +’s in the .diff file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Index: app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Usesecretkey.php
===================================================================
--- app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Usesecretkey.php	(revision 0)
+++ app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Usesecretkey.php	(revision 37005)
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category   Mage
+ * @package    Mage_Adminhtml
+ * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+
+/**
+ * Adminhtml backend model for "Use secret key in Urls" option
+ *
+ * @category   Mage
+ * @package    Mage_Adminhtml
+ * @author     Magento Core Team <core@magentocommerce.com>
+ */
+class Mage_Adminhtml_Model_System_Config_Backend_Admin_Usesecretkey extends Mage_Core_Model_Config_Data
+{
+    protected function _afterSave()
+    {
+        Mage::getSingleton('adminhtml/url')->renewSecretUrls();
+        return $this;
+    }
+}

:arrow: Magento – Login error after upgrade – Magento 1.3.0 Upgrade Issues – eCommerce Software for Growth.

There may be some other inconsistencies but at the moment this is the only issue I’ve encountered with 1.3.0 after an upgrade, feel free to comment and I make no warranty for the above, its merely a fix that worked for me, and isn’t official by any means.

Possibly Related Posts:



Mar 10 2009

Elias Interactive ask’s: What’s your biggest Magento pet peeve?

Even with the screencasts and guides Magento/Varient Posted I could instantly tell the designer or HTML/CSS monkey’s didn’t have much say in the structure. It was the Programmers who overly structured the templating system. It takes me atleast 5-7 folders to follow through JUST to get to a folder to upload images, edit a CSS file or even modify the templates themselves. I understand the needs for this sort of thing with Magento’s complex backend functionality but there is such a thing as being to Organized it slows down development processes. I believe the saying goes if your desk isn’t messy your not being very productive!

What I did was take a good base template to start with and started deconstructing the internal workings as much as I could grasp at the time to learn more of how Magento is building the pages up. This was before a lot of the community was asking for a very basic stripped down template that we could use as a base for creating new templates. I believe you can find it on MagentoConnect.

There is also a nifty feature that is somewhat hidden in Magento’s Admin that will display the Block controllers and the actual .phtml file that make up any page you are looking at. You can find this under the Admin area -> System -> Configuration. Select the “Current Configuration Scope:” to the left. <- This is an important step to get to this feature. After you have selected the Store of your choice proceed to the “Developer” Subsection to the left you’ll notice a “Template Path Hints” field with a drop down to enable/disable it. Coming from X-Cart and utilizing Smarty’s Debug Console popup to find template files and variables used I found this most useful feature for designers.

Templates are a headache but try extending the code base with notepad.exe You’ll quickly become overwhelmed with Magento/Varien OOP Voodoo, and PHP docs as nice is it is still doesn’t cut the mustard of someone really documenting methods, attributes, classes, etc. like most other great API’s especially from Google or PHP themselves.

Eventually I found it was time to get a more up-to-date IDE and decided to go with ZendStudio, and I haven’t looked back, the code completion was Exactly what I was missing coming from Micro$ofts Visual Studio. I believe others are also using Eclipse as an IDE to extend Magento more easily.

The other gripe I have with Magento is its speed, its defiantly a luxury car and not some sports car! I know Magento has mentioned improving the speed in future versions as one of their main focuses but for now we are left with server tweaks and hardware upgrades to make things run smoother. I believe I read somewhere that some pages can take as much as 20mb of the servers memory to generate if its not cached.

Besides all of these items I am all for Magento and think its simply the best E-Commerce package to date. I’ve used quite a few in the past and all lacked in features or were a PITA to upgrade!

Here’s is the original blog posting to Elias Interactive’s post:
What’s your biggest Magento pet peeve? | Elias Interactive.

Possibly Related Posts: