I'm trying to add a simple product to the cart, but addProduct() is failing.

For what it's worth, I'm running the code from inside the checkout_cart_product_add_after event.

$cart = Mage::getSingleton('checkout/cart'); 

//exit('a'); // when uncommented, this does get outputted
$cart->addProduct($secondaryProductId, $primaryProductQty);
//exit('b'); // when uncommented, this does not get outputted.

The $secondaryProductId variable is type integer and is value 103, a simple product with that ID exists and the product is enabled.

The $primaryProductQty variable is type integer and is value 1


I have realised the problem.

Magento's $cart->addProduct() method actually triggers the checkout_cart_product_add_after event, and whilst this was causing recursion, it wasn't causing infinite recursion, but the second call to my event's code (from the recursion) was causing some other invalid code to run.

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.