0

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.

5
1

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.

0

Try print_r($productInfo); to see what exactly that array holds, Magento requires a product object as well as a quantity array, as follows:

//load the $product model on an ID
$product_info = array('qty'=>1);
return parrent:addProduct($product, new Varien_Object($product_info));

Let me know if that gives you any luck.

1
  • moose, its not work. print_r($productInfo); prints list of values but same error occur
    – Helphin
    Feb 24 '14 at 8:37
0

Try Like this, in your Att_Membership_Model_Checkout_Cart

public function addProduct($productInfo, $requestInfo=null)
    {
      if (!Mage::helper('customer')->isLoggedIn())
      {
         echo Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
         exit();
      }
      $product = $this->_getProduct($productInfo);
      Mage::dispatchEvent('checkout_cart_product_add_before', array('product' => $product));
      return parent::addProduct($productInfo, $requestInfo=null);
    }
}

And remove the observer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.