How to set minimum quantity in magento cart?

How to set minimum quantity in magento cart?

September 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to set minimum quantity in magento cart?

Setting Minimum Quantity Requirements in Magento Cart

In Magento, you have the capability to set minimum quantity requirements for individual products within your store. However, as a store owner, you might find yourself needing to enforce a higher level of control - setting a minimum total quantity requirement across all items in an order.

Understanding the Current Magento Configuration

By default, Magento allows you to configure a minimum quantity at the product level via the catalog > products interface. This is useful when you want to restrict the purchase of a single item below a certain threshold, but it doesn’t address your need for a site-wide or order-level minimum quantity.

For instance, let’s say you’re running an online grocery store and want customers to buy at least 10 items per order regardless of what products they choose. The current Magento configuration won’t achieve this out-of-the-box.

Setting Up Minimum Quantity Requirements

To implement minimum quantity requirements across all orders in your site, you’ll need to modify the core Magento functionality slightly. This involves creating a custom module and overriding the add_to_cart and estimate_shipping_amount event listeners.

Step 1: Create a Custom Module

Begin by creating a new folder for your module inside app/code/Company. The structure should look something like this:

- app
    - code
        - Company
            - MinimumQuantity
                - etc
                    - module.xml
                - etc
                    - config.xml
                - Model
                    - Observer.php

Step 2: Configure the Module

Update the module.xml file to include your module’s configuration:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Company_MinimumQuantity" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Checkout"/>
        </sequence>
    </module>
</config>

The etc/config.xml file will contain the configuration for your module’s settings, which you can adjust based on your specific needs.

Step 3: Implement the Observer

In the Observer.php file inside the Model directory, create a new observer class that will handle the catalog_product_add_to_cart_after event:

namespace Company\MinimumQuantity\Model;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class Observer implements ObserverInterface
{
    public function execute(Observer $observer)
    {
        // Your logic for enforcing minimum quantity here

        return $this;
    }
}

Step 4: Handle Minimum Quantity Enforcement

Within the execute method of your observer class, you’ll need to add the logic for validating and enforcing the minimum order quantity. This involves checking if the total number of items in the cart is less than the desired threshold.

If it is, display an error message or redirect the customer back to their shopping cart with a notification. Here’s a simple example:

namespace Company\MinimumQuantity\Model;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Message\ManagerInterface;

class Observer implements ObserverInterface
{
    private $messageManager;

    public function __construct(ManagerInterface $messageManager)
    {
        $this->messageManager = $messageManager;
    }

    public function execute(Observer $observer)
    {
        $quote = $observer->getQuote();
        $itemsCount = $quote->getItemsCollection()->count();

        if ($itemsCount < 10) { // Replace with your desired minimum quantity
            $this->messageManager->addErrorMessage('You must add at least 10 items to place an order.');
            return $this;
        }

        return $this;
    }
}

Conclusion

Setting a minimum total quantity requirement across all orders in Magento involves creating a custom module and overriding specific event listeners. By following the steps outlined above, you can achieve this functionality without having to modify the core Magento files directly.

Remember that implementing such restrictions may impact user experience, so ensure you have a clear communication strategy in place to inform your customers about these requirements.

For more advanced customizations or if you need assistance building your module, consider reaching out to Laravel Company, where our experienced Magento developers can help you implement complex features tailored to your business needs.

Checkout Catalog API Extensions

Our network