2

I want to restrict Magento to have one single product per order. If the user is trying to add more than one product to the cart it should be prohibited. I'm not talking about restricting one particular product. Generally whatever the product is, there should be one product at a time in the cart until place the order.

How can I achieve this?

1

3 Answers 3

1
<config>
    <modules>
        <cart_restrict>
            <version>0.1.0</version>
        </cart_restrict>
    </modules>
    <global>
        <models>
            <cart_restrict>
                <class>cart_restrict_Model</class>
            </cart_restrict>
        </models>
        <helpers>
            <cart_restrict>
                <class>cart_restrict_Helper</class>
            </cart_restrict>
        </helpers>
    </global>
    <frontend>
        <events>
            <catalog_product_type_prepare_full_options>
                <observers>
                    <cart_restrict_catalog_product_type_prepare>
                        <class>cart_restrict_Model_Observer</class>
                        <method>catalogProductTypePrepare</method>
                    </cart_restrict_catalog_product_type_prepare>
                </observers>
            </catalog_product_type_prepare_full_options>
        </events>
    </frontend>
</config>

In observer

class cart_restrict_Model_Observer
{
    public function catalogProductTypePrepare($observer)
    {
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        if($quote->getItemsCount()>=1){
            Mage::throwException('You can only buy one product at a time.');
        }
    }
}
0

you can do it by code,that is allow a product to add only if cart is empty..

create a local checkout module for overwriting core checkout module then overwrite CartController.php for addAction() method in to your local module then check this condition ,

if(Mage::getSingleton('checkout/session')->getQuote()->hasItems())
{
     //session message as only one product can add to cart
}
else
{
    //add to cart
}

Hope this is what you need..

0

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.

enter image description here

1
  • Sorry This is not the expected answer. I don't want to restrict one particular product
    – Sukeshini
    Dec 23, 2014 at 6:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.