Let's try to make some reasonment for what you are asking.
First of all: products are not necessarily added to cart by navigating a category; some examples are:
- I add a product to cart from a search result
- I add a product to cart by performing a re-order
- I update a product quantity of a product in a saved cart
these are only a few that come in my mind but there are more.
So first of all you have to define a strategy, that is what to do in these cases and what (if any) minimum quantity you will allow to be added to cart.
So said, let's try to understand how product minimum quantity check is performed.
You can start from Mage_Sales_Model_Quote_Item::setQty()
method which is called when an item is added to cart.
That method dispatches a sales_quote_item_qty_set_after
event which is observed by Mage_CatalogInventory_Model_Observer::checkQuoteItemQty()
method;
it's a very long method which in turn delegates the minimum allowed quantity check to Mage_CatalogInventory_Model_Stock_Item::checkQuoteItemQty()
method;
this in turn delegates to Mage_CatalogInventory_Model_Stock_Item::getMinSaleQty()
that is where the chain ends up.
I encourage you to study that code to understand what happens under the hood.
As you can guess, you can observe the sales_quote_item_qty_set_after
event to inject your logic through a custom module.
Pay attention to add a dependency to Mage_CatalogInventory
module in your module activation XML file under {magento_root}/app/etc/modules
; this is necessary in order for your observer to be called after Mage_CatalogInventory_Model_Observer::checkQuoteItemQty()
.
At this point you can check whether you are adding a product from a specific category; to do that, simply invoke Mage::helper('catalog')->getCategory()
which will return a Mage_Catalog_Model_Category
object if you are adding a product to cart from a category (or from a product page reached by navigating a category), null
otherwise.
In case of null
you have to apply the strategy I mentioned at the beginning.
Hope it helps.