Advertisement
Guest User

test

a guest
Sep 16th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  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.  
  25.         header('Content-type: application/json');
  26.         print json_encode($text);
  27.  
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement