0

I want to set minimum order quantity (moq) based on category.

Say a product name A in catgeory 1 and category 2:

I want to set moq to be 2 for category 1 and moq to be 5 for category 2 based on which category user is browser.

Please guide me way to do this I need help to start off, i am new to Magento and need help in this issue.

1 Answer 1

0

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.

5
  • hey bro can u help me as paid support as i am new here
    – mcoder
    Commented Mar 6, 2016 at 3:47
  • Sorry, I can't. Commented Mar 6, 2016 at 7:37
  • ok np , but can u give me hint to do that which oberserver to use like that
    – mcoder
    Commented Mar 6, 2016 at 8:19
  • you have to implement your own observer, binding it to the event I pointed out; if you are not a Magento programmer you can't do that on your own; Commented Mar 6, 2016 at 8:45
  • i am newbie will try and ping u if needed
    – mcoder
    Commented Mar 6, 2016 at 8:48

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.