You need to develop a small extension:

Please follow the Steps:

just create the following file with code:

app/code/local/Sushant/Cartlimit/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Sushant_Cartlimit>
            <version>0.0.1</version>
        </Sushant_Cartlimit>
    </modules>
    <global>
        <models>
            <sushant_cartlimit>
                <class>Sushant_Cartlimit_Model</class>
            </sushant_cartlimit>
        </models>
        <helpers>
            <sushant_cartlimit>
                <class>Sushant_Cartlimit_Helper</class>
            </sushant_cartlimit>
        </helpers>
    </global>
    <frontend>
        <events>
            <catalog_product_type_prepare_full_options>
                <observers>
                    <sushant_cartlimit_catalog_product_type_prepare>
                        <class>Sushant_Cartlimit_Model_Observer</class>
                        <method>catalogProductTypePrepare</method>
                    </sushant_cartlimit_catalog_product_type_prepare>
                </observers>
            </catalog_product_type_prepare_full_options>
        </events>
    </frontend>
</config>

app/code/local/Sushant/Cartlimit/Helper/Data.php

<?php
class Sushant_Cartlimit_Helper_Data extends Mage_Core_Helper_Abstract
{
    
}

&#91;/code&#93;

app/code/local/Sushant/Cartlimit/Model/Observer.php

&#91;code language="php"&#93;
<?php class Sushant_Cartlimit_Model_Observer { public function catalogProductTypePrepare($observer) { $quote = Mage::getSingleton('checkout/session')->getQuote();			
		//echo $quote->getItemsCount();exit;
        if($quote->getItemsCount()>=1){
			//$currentparams = Mage::app()->getRequest()->getParams('product');
			Mage::getSingleton('core/session')->addError('You can only buy one product at a time.');
			// Redirect your custom module	//Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('test/index/index/id/'.$currentparams['product']));
			// Redirect product page
			//Mage::throwException('You can only buy one product at a time.');
			// Redirect cart page
			Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
			Mage::app()->getResponse()->sendResponse();
			exit;            
        }
    }
}

app/etc/modules/Sushant_Cartlimit.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Sushant_Cartlimit>
      <active>true</active>
      <codePool>local</codePool>
    </Sushant_Cartlimit>
  </modules>
</config>

working-on-a-computer-smiley-emoticon

Categories: Extension

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *