I am implementing a plugin for a client that will use the 'Max Sale Quantity' value of a Magento Stock Item on a product as a means of setting an upper-bound on total customer purchases.

Because I need to check this condition in multiple events, controller actions, I cannot contain it to merely an Observer where I could create a local protected function that checks this condition from my Resource Model.

In my requirements I will be limiting the cart additions. But I find myself in a dilemma: from the controller addAction I need to rely on throw - however from sales_quote_merge_before it seems that I could effectively unset the offending products and post a message to the customer/session, though, I could throw and catch, respectively as with the controller action instead.

My questions are:

  • Is this bad practice to effectively rely on throw from the module helper?
  • Is this, rather, a model method that I need to invoke?
  • What is the best design strategy that allows me to keep my module DRY?


As of EE 1.12 I see only 4 instances of Helper/Data.php files that throw - 3 of them are Api2/Oauth. Mage/Core does it once as well, but this seems to be the only other instance. Various 3rd parties look like they take different approaches here.

Any feedback is welcome.

  • I think, generally, it's bad to use Exceptions for program logic control rather than actually handling 'Exceptional' circumstances. If you can solve the problem and avoid having to throw Exceptions to do it, I think that will lead to a 'better' solution. Sometimes though, you have to just deal with what the Framework gives you to work with... Commented Feb 28, 2013 at 8:00

1 Answer 1


Saying to the customer, "we are sorry, you can't purchase so much" is a exception. The expected case is, there is enough and you put the products in the cart. And one more word: There are try and catch blocks inside of magento, for example in \Mage_Checkout_CartController::addAction:

// [...]
} catch (Mage_Core_Exception $e) {
        if ($this->_getSession()->getUseNotice(true)) {
// [...]

Let me say it this way: They are there to be used :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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