Magento – Adding Product to Cart,Got Error Please specify the product’s option(s)

configurable-productevent-observer

In magento, i have rewrite the Mage_Checkout_Model_Cart class for adding the dispatch event checkout_cart_product_add_before,
Due to this simple product added to the cart without problem, but while adding configurable products to the cart i got the error Please specify the product's option(s).

I have selected required options, even though i got this error.

when i remove checkout_cart_product_add_before event, this problem has been solved.
but i need checkout_cart_product_add_before event, how to overcome this problem.

Here is my code for adding checkout_cart_product_add_before event,

Config file for Rewriting "Mage_Checkout_Model_Cart",

<config>
    <global>
        ..
        <models>
            <checkout>
                <rewrite>
                    <cart>Att_Membership_Model_Checkout_Cart</cart>
                </rewrite>
            </checkout>
        </models>
        ..
    </global>
</config>

and model class file as below,

class Att_Membership_Model_Checkout_Cart extends Mage_Checkout_Model_Cart
{
    public function addProduct($productInfo, $requestInfo=null)
    {
        $product = $this->_getProduct($productInfo);
        Mage::dispatchEvent('checkout_cart_product_add_before', array('product' => $product));

        return parent::addProduct($productInfo, $requestInfo=null);
    }
}

obeserver:

   public function checkLogin($observer)
   {
      if (!Mage::helper('customer')->isLoggedIn())
      {
         echo Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
         exit();
      }
   }

any solution?

thanks.

Best Answer

There is a mistake you made here.. in your code

public function addProduct($productInfo, $requestInfo=null)
{
    $product = $this-&gt;_getProduct($productInfo);
    Mage::dispatchEvent('checkout_cart_product_add_before', array('product' =&gt; $product));

    return parent::addProduct($productInfo, $requestInfo=null);
}

You can see there is two parameters of function :

  1. $productinfo: which contain product details eg: name, id, sku etc.
  2. $requestinfo: which conatin your requested data eg: you selected options.

So mistake is here: return parent::addProduct($productInfo, **$requestInfo=null**);

you are passing $requestinfo as null always that's why parent model didn't get required options value here.

I hope you under stand. you just remove "=null" from that parameter. it will definitely run.

Related Topic