Observer :
public function cartevent(Varien_Event_Observer $observer) {
// Load product
$product = $observer->getProduct();
$prodID = $product->getId();
$_product = Mage::getModel('catalog/product')->load($prodID);
// get category id
$categoryIds = $_product->getCategoryIds();
// check cart
$cart_qty = (int)Mage::getModel('checkout/cart')->getQuote()->getItemQty();
// check conditiion cart has other products
if(in_array(681, $categoryIds) && $cart_qty > 0) {
Mage::throwException("You can not add This special Product, empty cart before add it");
}
// check if other products add to cart
$quote = Mage::getModel('checkout/cart')->getQuote();
foreach ($quote->getAllItems() as $item) {
$_product1 = $item->getProduct();
$categoryIds1 = $_product1->getCategoryIds();
if(in_array(681, $categoryIds1)) {
Mage::throwException("If you want Kolu Padi, Purchase alone not mixed with other Products");
break;
}
}
}
If try to add cart in website, gettin error,
a:5:{i:0;s:67:"If you want Kolu Padi, Purchase alone not mixed with other Products";i:1;s:1835:"#0 /home/abc/public_html/app/code/local/Gta/KolupadiRestrict/Model/Observer.php(21): Mage::throwException('If you want Kol...')
#1 /home/abc/public_html/app/code/core/Mage/Core/Model/App.php(1358): Gta_KolupadiRestrict_Model_Observer->cartevent(Object(Varien_Event_Observer))
#2 /home/abc/public_html/app/code/core/Mage/Core/Model/App.php(1337): Mage_Core_Model_App->_callObserverMethod(Object(Gta_KolupadiRestrict_Model_Observer), 'cartevent', Object(Varien_Event_Observer))
#3 /home/abc/public_html/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('checkout_cart_p...', Array)
#4 /home/abc/public_html/app/code/core/Mage/Checkout/Model/Cart.php(290): Mage::dispatchEvent('checkout_cart_p...', Array)
#5 /home/abc/public_html/app/code/local/Cmsmart/AjaxCart/controllers/IndexController.php(315): Mage_Checkout_Model_Cart->addProduct('5071', Array)
#6 /home/abc/public_html/app/code/local/Cmsmart/AjaxCart/controllers/IndexController.php(133): Cmsmart_AjaxCart_IndexController->tryaddAction(Object(Mage_Catalog_Model_Product), Array)
#7 /home/abc/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Cmsmart_AjaxCart_IndexController->indexAction()
#8 /home/abc/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('index')
#9 /home/abc/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#10 /home/abc/public_html/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#11 /home/abc/public_html/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#12 /home/abc/public_html/australia/index.php(93): Mage::run('australia', 'website')
#13 {main}";s:3:"url";s:100:"/ajaxcart/index/index/?form_key=MtlJbvKkqPQKCLJR&product=5071&related_product=&qty=1&_=1565155804563";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:9:"australia";}