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

自闭症网瘾萝莉.ら 提交于 2019-11-27 07:15:49

问题


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 order the product twice he has to do a second order. This is very important for me for the later order workflow.

Thx for your help, I appreciate it!

Kind regards, Manu


回答1:


Yes, you can limit the maximum quantity of a product in the shopping cart by editing the value on the Inventory tab when editing a product. See screenshot below. In your case, you'd want to uncheck Use Config Settings and set the value to 1.




回答2:


Well above answer is useful to restrict a single product to add in cart not for Restricting Maximum Qty Allowed in Shopping Car. To change this setting fallow bellow steps.

First login into Magento admin then Go to System>>Configuration then use this configuration settings.




回答3:


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


The below should fix your issue:

public function enforceSingleOrderLimit($observer){
     if (!$this->_helper->isModuleEnabled()) {
        return;
    }
    $cart = Mage::getModel('checkout/cart')->getQuote();
    if ($cart->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;
    }
}


来源:https://stackoverflow.com/questions/10856770/magento-limit-product-max-quantity-to-1-per-order-quantity-2-2-orders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!