Friday 30 October 2015

Magento - blocks not showing problems after installing SUPEE-6788

Hi recently i have install a latest patch from magento  SUPEE-6788 in my magento store.
But it has causes  block not render problem, no  blocks was visible on frontend .

than i troubleshoot it and found that in this patch magento has added a 2 new tables named as

permission_variable   and   permission_block 

  • first of all check if these tables exist in your database or not
  •  if they exist than check in permission_block table that your  block value exist in that table or not like below


 you will need to be insert your block name in the permission_block  as above
once you will  done with your block name and your blocks should be visible on frontend



Sunday 25 October 2015

how to check admin is logged in or not in Magento

 Hi with the below peace of code you can check admin user is logged in or not anywhere is magento

$sesId = isset($_COOKIE['adminhtml']) ? $_COOKIE['adminhtml'] : false ;
$session = false;
if($sesId){
    $session = Mage::getSingleton('core/resource_session')->read($sesId);
}
$loggedIn = false;
if($session)
{
    if(stristr($session,'Mage_Admin_Model_User'))
    {
        $loggedIn = true;
    }
}
var_dump($loggedIn);// this will be true if admin logged in and false if not

Thursday 8 October 2015

How to get category tree structure in Magento programatically ?

In many places we will need to get the category tree in magento programmatically. With the below peace of code you can get the tree anywhere in magento



   $rootCatId = Mage::app()->getStore()->getRootCategoryId(); // it will fetch your current store root id
   $catlistHtml = getTreeCategories($rootCatId, false);
   echo $catlistHtml;

function getTreeCategories($parentId, $isChild){
    $allCats = Mage::getModel('catalog/category')->getCollection()
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('is_active','1')  // is acategory active
                ->addAttributeToFilter('include_in_menu','1') //  to check include_in_menu yes or no
                ->addAttributeToFilter('parent_id',array('eq' => $parentId))  // filter parent id
                ->addAttributeToSort('position', 'asc');
              
    $class = ($isChild) ? "sub-cat-list" : "cat-list";
    $html .= '<ul class="'.$class.'">';
    foreach($allCats as $category)
    {
        $html .= '<li><span>'.$category->getName()."</span>";
        $subcats = $category->getChildren();
        if($subcats != ''){
            $html .= getTreeCategories($category->getId(), true);
        }
        $html .= '</li>';
    }
    $html .= '</ul>';
    return $html;
}


Please let me know if there is other such easy way to do this.I will love to hear and update my post.

thanks

Wednesday 7 October 2015

How to get products of particular category in Magento ?

Hi it is very easy to get products of particular category in magento.
Check the below peace of code , with this you can get the products of your desored category


$products =
              Mage::getModel('catalog/category')->load('put your category id here')
            ->getProductCollection()
            ->addAttributeToSelect('*') ;
          

                foreach($products as $productsss){
                                  print_r($productsss->getData());
                    }


you can also add the filters in the above collection to get your desired products
like if you want to get only enabled products in the particular category like

$products = Mage::getModel('catalog/category')->load($catid)
            ->getProductCollection()
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('status', 1) ;


with this only products enabled will be show in list. You can add as many as filters you want.

Hope it will help somebody.

Thanks