1

I want to limit the product max qty per customer to only 1.

Example: If you buy the product my_product_per_customer as a registered customer you can not buy again with the same account.

Does anyone know a way to achieve this?

My config.xml is

  <?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Inchoo_MaxOrderAmount>
<version>0.0.2</version>
</Inchoo_MaxOrderAmount>
</modules>
    <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>

My observer.php is

<?php 
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;
        }
        echo 1; die;
        //todo - look up customer info and check if they already purchase this item
        $quote = $observer->getEvent()->getQuote();
        if ($quote->getCart()->getItemsCount() == 1) {

            Mage::getSingleton('checkout/session')->addError('limit only one product per order');
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
            Mage::app()->getResponse()->sendResponse();
            exit;
        }
    }
}

1 Answer 1

1

Take a look @ Magento Maximum Allowed Order Amount, you would have to create a custom module to add this feature.

Create an observer for sales_quote_save_before

<config>
    <frontend>
        <events>
            <sales_quote_save_before>
                <observers>
                    <inchoo_maxorderamount_enforceSingleOrderLimit>
                        <type>singleton</type>
                        <class>Inchoo_MaxOrderAmount/observer</class>
                        <method>enforceSingleOrderLimit</method>
                    </inchoo_maxorderamount_enforceSingleOrderLimit>
                </observers>
            </sales_quote_save_before>
        </events>
    </frontend>
</config>

In your observer

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;
        }

        //todo - look up customer info and check if they already purchase this item
        $quote = $observer->getEvent()->getQuote();
        if ($quote->getCart()->getItemsCount() == 1) {

            Mage::getSingleton('checkout/session')->addError('limit only one product per order');
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
            Mage::app()->getResponse()->sendResponse();
            exit;
        }
    }
}
4
  • I am trying to follow your advice and i try to create the module but i am getting this error "Mage registry key "_singleton/inchoo_maxorderamount/observer" already exists"
    – Spm
    Commented Feb 13, 2015 at 16:00
  • I just copied and pasted the code which you suggested when i am doing the order i getting this message
    – Spm
    Commented Feb 13, 2015 at 16:05
  • I have add them my question.
    – Spm
    Commented Feb 13, 2015 at 16:14
  • Take a look at stackoverflow.com/questions/22608376/… Commented Feb 13, 2015 at 16:46

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.