{"id":96,"date":"2011-03-31T07:53:50","date_gmt":"2011-03-31T07:53:50","guid":{"rendered":"http:\/\/www.evermoredevnotes.com\/?p=96"},"modified":"2011-03-31T07:53:50","modified_gmt":"2011-03-31T07:53:50","slug":"magento-1-5-downloadable-products-error-when-adding-to-cart","status":"publish","type":"post","link":"https:\/\/www.evermoretechnologies.com\/blog\/2011\/03\/magento-1-5-downloadable-products-error-when-adding-to-cart\/","title":{"rendered":"Magento 1.5 Downloadable Products Error When adding to cart"},"content":{"rendered":"<p>I added downloadable products to a store, but wasn&#8217;t able to check out with them.  They were straight-forward products with a single pdf as the sample and downloadable product.<\/p>\n<p>Everything looked fine, but when I added the product to the cart, it threw this error:<\/p>\n<p>Look at \/app\/code\/core\/Mage\/Downloadable\/Product\/Type.php line 326<br \/>\n[sourcecode language=&#8221;php&#8221;]<br \/>\n    \/**<br \/>\n     * Check if product can be bought<br \/>\n     *<br \/>\n     * @param Mage_Catalog_Model_Product $product<br \/>\n     * @return Mage_Bundle_Model_Product_Type<br \/>\n     * @throws Mage_Core_Exception<br \/>\n     *\/<br \/>\n    public function checkProductBuyState($product = null)<br \/>\n    {<br \/>\n        parent::checkProductBuyState($product);<br \/>\n        $product = $this-&gt;getProduct($product);<br \/>\n        $option = $product-&gt;getCustomOption(&#8216;info_buyRequest&#8217;);<br \/>\n        if ($option instanceof Mage_Sales_Model_Quote_Item_Option) {<br \/>\n            $buyRequest = new Varien_Object(unserialize($option-&gt;getValue()));<br \/>\n            if (!$buyRequest-&gt;hasLinks()) {<br \/>\n                Mage::throwException(<br \/>\n                    Mage::helper(&#8216;downloadable&#8217;)-&gt;__(&#8216;Please specify product link(s).&#8217;)<br \/>\n                );<br \/>\n            }<br \/>\n        }<br \/>\n        return $this;<br \/>\n    }<br \/>\n[\/sourcecode]<\/p>\n<p>The problem, and I honestly don&#8217;t know why, is in the nested if&#8217;s that throw the exception.  No big shock there since that&#8217;s the exception we see.<\/p>\n<p>Turns out, you don&#8217;t select links for downloadable products that don&#8217;t allow separate link purchasing.  Simply change the second if statement to account for this and it works fine.  The final source code for the function is:<br \/>\n[sourcecode language=&#8221;php&#8221;]<br \/>\n    \/**<br \/>\n     * Check if product can be bought<br \/>\n     *<br \/>\n     * @param Mage_Catalog_Model_Product $product<br \/>\n     * @return Mage_Bundle_Model_Product_Type<br \/>\n     * @throws Mage_Core_Exception<br \/>\n     *\/<br \/>\n\tpublic function checkProductBuyState($product = null)<br \/>\n\t{<br \/>\n\t\tparent::checkProductBuyState($product);<br \/>\n\t\t$product = $this-&gt;getProduct($product);<br \/>\n\t\t$option = $product-&gt;getCustomOption(&#8216;info_buyRequest&#8217;);<br \/>\n\t\tif ($option instanceof Mage_Sales_Model_Quote_Item_Option) {<br \/>\n\t\t\t$buyRequest = new Varien_Object(unserialize($option-&gt;getValue()));<br \/>\n\t\t\tif (!$buyRequest-&gt;hasLinks() &amp;&amp; $this-&gt;getProduct($product)-&gt;getLinksPurchasedSeparately()) {<br \/>\n\t\t\t\tMage::throwException(<br \/>\n\t\t\t\t\tMage::helper(&#8216;downloadable&#8217;)-&gt;__(&#8216;Please specify product link(s).&#8217;)<br \/>\n\t\t\t\t);<br \/>\n\t\t\t}<br \/>\n\t\t}<br \/>\n\t\treturn $this;<br \/>\n\t}<br \/>\n[\/sourcecode]<\/p>\n<p>Of course, the recommended way to make this override is to copy the file to \/app\/code\/local\/Mage\/Downloadable\/Model\/Product\/Type.php then make updates.<\/p>\n<p>The source of this solution is from the <a href=\"http:\/\/www.magentocommerce.com\/boards\/viewthread\/220106\/\">Magento Commerce Forums: Magento 1.5.0.1 : Downloadable product (missing required options) when adding to cart<\/a>  I simply posted it here for my own quick lookup and added a little clarification on the code change.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I added downloadable products to a store, but wasn&#8217;t able to check out with them. They were straight-forward products with a single pdf as the sample and downloadable product. Everything&#8230; <a href=\"https:\/\/www.evermoretechnologies.com\/blog\/2011\/03\/magento-1-5-downloadable-products-error-when-adding-to-cart\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[],"_links":{"self":[{"href":"https:\/\/www.evermoretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/96"}],"collection":[{"href":"https:\/\/www.evermoretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.evermoretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.evermoretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.evermoretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=96"}],"version-history":[{"count":0,"href":"https:\/\/www.evermoretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/96\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.evermoretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.evermoretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.evermoretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}