I am on the product page. I have a bundle product and when I press the add to cart
button I want to add a simple product programmatically to cart.
I'm using this event: checkout_cart_product_add_after
for my observer.
This is my code:
public function cartProductUpdateAfter($observer)
{
$this->cartProductAddAfter($observer);
}
public function cartProductAddAfter($observer)
{
$productToAdd = Mage::getModel('catalog/product');
$productToAdd->load(1745);
$this->_addProductToCart($productToAdd, 1);
}
protected function _addProductToCart($product, $qty)
{
$cart = Mage::getSingleton('checkout/cart');
if ($product->getId()) {
// infinite loop probably
$cart->addProduct($product, $qty);
return true;
}
return false;
}
I'm getting a maxium execution time exceeded error message, problably because it calls itself. Can you give me some ideas how to fix that ?