cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 1.9 Observer If condition partially working

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Magento 1.9 Observer If condition partially working

My Observer :

 

<?php
class Gta_KolupadiRestrict_Model_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()->getItemsQty();

        if(in_array(681, $categoryIds))
        {
            error_log("line 31-".$categoryIds[0]);
            $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");
                  }
            }
        }elseif(!in_array(681, $categoryIds)){
            error_log("line 31-".$categoryIds[0]);
            $quote = Mage::getModel('checkout/cart')->getQuote();
            foreach ($quote->getAllItems() as $item) {
                $_product1 = $item->getProduct();
    
                $categoryIds1 = $_product1->getCategoryIds();
                error_log("line 34-".$item->getProductId()."-".$categoryIds1[0]);
                if(in_array(681, $categoryIds1)) {
                    Mage::throwException("If you want Kolu Padi, Purchase alone not mixed with other Products");
                 }
    
    
            }

        }
    }   
}
?>

Observer & my logic working fine, but observer not throw exception message instead of keep loading add-to-cart. How to show exception if condition match?