Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function getSubCatsAction($params){
  2.         $parentCatId = $this->getRequest()->getPost();
  3.         $parentCat = Mage::getModel('catalog/category')->load($parentCatId['id']);
  4.         $allChildren = $parentCat->getAllChildren();
  5.         $allChildren = explode(',', $allChildren);
  6.         //var_dump($allChildren);
  7.         $subCategories = Mage::getModel('catalog/category')->getCollection()
  8.             ->addAttributeToSelect('*')
  9.             ->addAttributeToFilter('include_in_menu','1')
  10.             ->addAttributeToFilter('is_active','1')
  11.             ->addAttributeToFilter('entity_id', array('in' => $allChildren));
  12. $text = '<select id="search-field-sub-category" name="search-field-sub-category">';
  13.         foreach($subCategories as $subCat){
  14.             if($parentCatId['id'] != $subCat->getId()){
  15.                 $text.='<option value="'.$subCat->getId().'">'.$subCat->getName().'('.$subCat->getDynamicProductsCount().')'."</option>";
  16.             }
  17.             else if($parentCatId['id'] == $subCat->getId()){
  18.                 $text.='<option value="'.$subCat->getId().'"> All '.$subCat->getName().' ('.$subCat->getDynamicProductsCount().')'."</option>";
  19.             }
  20.         }
  21.         $text.= '</select>';
  22.  
  23.  
  24. $this->getResponse()->setHeader('Content-type', 'application/json',true);
  25.         $this->getResponse()->setBody(json_encode($text));
  26.  
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement