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
You can see there is two parameters of function :
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.