Magento – Magento 2 : How to Set Maximum Purchase Order Amount

magento2sales-order

My client want to set Maximum purchase order amount in magento2? and they need options like Minimum purchase order amount in admin.

can anyone please help..

Best Answer

Inchoo Wrote a nice article on Magento Maximum Allowed Order Amount Which States,

If you look at the Magento admin configuration area, you will see that Magento offers the opposite feature called Minimum Order Amount. You can find it under System > Configuration > Sales > Sales > Minimum Order Amount.

And this functionalty is not more diffrent from our Maximum Order Amount, The main difference is that with Maximum Allowed Order Amount you are not suppose to add anything new to the cart itself if it exceeds the maximum limit.

For our Functionality we are going to use event/observer with sales_quote_save_before

we only needed to add the following to our extension's config.xml file:

<config>
    <frontend>
        <events>
            <sales_quote_save_before> 
                <observers>
                    <inchoo_maxorderamount_enforceSingleOrderLimit>
                        <class>inchoo_maxorderamount/observer</class>
                        <method>enforceSingleOrderLimit</method>
                    </inchoo_maxorderamount_enforceSingleOrderLimit>
                </observers>
            </sales_quote_save_before>
        </events>
    </frontend>
</config>

And the following logic into our Observer.php model class file:

class Inchoo_MaxOrderAmount_Model_Observer
{
    private $_helper;

    public function __construct() 
    {
        $this->_helper = Mage::helper('inchoo_maxorderamount');
    }

    /**
     * No single order can be placed over the amount of X
     */
    public function enforceSingleOrderLimit($observer)
    {
        if (!$this->_helper->isModuleEnabled()) {
            return;
        }

        $quote = $observer->getEvent()->getQuote();

        if ((float)$quote->getGrandTotal() > (float)$this->_helper->getSingleOrderTopAmount()) {

            $formattedPrice = Mage::helper('core')->currency($this->_helper->getSingleOrderTopAmount(), true, false);

            Mage::getSingleton('checkout/session')->addError(
                $this->_helper->__($this->_helper->getSingleOrderTopAmountMsg(), $formattedPrice));

            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
            Mage::app()->getResponse()->sendResponse();
            exit;
        }
    }
}

This method allow us to use maximum order amount.

Or you can even download a inchoo extension For this Functionalty from this link

Hope this helps.