Magento 1.5 Downloadable Products Error When adding to cart

I added downloadable products to a store, but wasn’t able to check out with them. They were straight-forward products with a single pdf as the sample and downloadable product.

Everything looked fine, but when I added the product to the cart, it threw this error:

Look at /app/code/core/Mage/Downloadable/Product/Type.php line 326
[sourcecode language=”php”]
/**
* Check if product can be bought
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Bundle_Model_Product_Type
* @throws Mage_Core_Exception
*/
public function checkProductBuyState($product = null)
{
parent::checkProductBuyState($product);
$product = $this->getProduct($product);
$option = $product->getCustomOption(‘info_buyRequest’);
if ($option instanceof Mage_Sales_Model_Quote_Item_Option) {
$buyRequest = new Varien_Object(unserialize($option->getValue()));
if (!$buyRequest->hasLinks()) {
Mage::throwException(
Mage::helper(‘downloadable’)->__(‘Please specify product link(s).’)
);
}
}
return $this;
}
[/sourcecode]

The problem, and I honestly don’t know why, is in the nested if’s that throw the exception. No big shock there since that’s the exception we see.

Turns out, you don’t select links for downloadable products that don’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:
[sourcecode language=”php”]
/**
* Check if product can be bought
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Bundle_Model_Product_Type
* @throws Mage_Core_Exception
*/
public function checkProductBuyState($product = null)
{
parent::checkProductBuyState($product);
$product = $this->getProduct($product);
$option = $product->getCustomOption(‘info_buyRequest’);
if ($option instanceof Mage_Sales_Model_Quote_Item_Option) {
$buyRequest = new Varien_Object(unserialize($option->getValue()));
if (!$buyRequest->hasLinks() && $this->getProduct($product)->getLinksPurchasedSeparately()) {
Mage::throwException(
Mage::helper(‘downloadable’)->__(‘Please specify product link(s).’)
);
}
}
return $this;
}
[/sourcecode]

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.

The source of this solution is from the Magento Commerce Forums: Magento 1.5.0.1 : Downloadable product (missing required options) when adding to cart I simply posted it here for my own quick lookup and added a little clarification on the code change.

Leave a Reply

Your email address will not be published. Required fields are marked *