Magento: limit product max quantity to 1 per order. quantity 2 = 2 orders

后端 未结 4 1643
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 09:46

Is it anyhow possible to limit specific products in Magento to a max quantity of one per order? This means the user can only order one product at a time. If he wants to orde

4条回答
  •  我在风中等你
    2020-12-11 10:10

    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

    
        
            
                
                    
                        
                            inchoo_maxorderamount/observer
                            enforceSingleOrderLimit
                        
                    
                
            
        
    
    

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

提交回复
热议问题