private function createCategoryTree($id) { $cats = array(); $isfolder = false; $items = ProductsCategories::getbyParentId($id); foreach ($items as $category) { $subcategory = $this->createCategoryTree($category['category_id']); $isfolder = $subcategory ? true : false; if ($subcategory) { $cats[] = array('key' => $category['category_id'], 'title' => $category['name'], 'isFolder' => $isfolder, 'children' => $subcategory); } else { $cats[] = array('key' => $category['category_id'], 'title' => $category['name']); } } return $cats; }
public function listAction() { $ns = new Zend_Session_Namespace(); $products = array(); // get the category uri $uri = $this->getRequest()->getParam('q'); if (!empty($uri)) { // Save the path of the user $ns->lastcategory = $uri; // Get the category information $category = $this->categories->getAllInfobyURI($uri); if (!empty($category[0])) { $this->view->category = $category[0]; // Get the subcategories $this->view->subcategory = ProductsCategories::getbyParentId($category[0]['category_id'], 1, true); // Set the Metatag information $this->view->headTitle()->prepend($category[0]['name']); if (!empty($category[0]['keywords'])) { $this->view->headMeta()->setName('keywords', $category[0]['keywords']); } if (!empty($category[0]['description'])) { $this->view->headMeta()->setName('description', $category[0]['description'] ? Shineisp_Commons_Utilities::truncate(strip_tags($category[0]['description'])) : '-'); } $this->view->headertitle = $category[0]['name']; // Get the products information $fields = "pd.productdata_id as productdata_id, \n\t\t\t\t pd.name as name, \n\t\t\t\t pd.shortdescription as shortdescription, \n\t\t\t\t pd.metakeywords as metakeywords, \n\t\t\t\t pd.metadescription as metadescription, \n\t\t\t\t p.*, pag.code as groupcode"; $data = $this->categories->getProductListbyCatUri($uri, $fields, $ns->langid); if (!empty($data['records'])) { // Get the media information for each product foreach ($data['records'] as $product) { $product['reviews'] = Reviews::countItems($product['product_id']); $product['attributes'] = ProductsAttributes::getAttributebyProductID($product['product_id'], $ns->langid, true); $products[] = $product; } $this->view->products = $products; $this->view->pager = $data['pager']; } $this->view->layoutmode = !empty($ns->layoutmode) ? $ns->layoutmode : "list"; $this->_helper->viewRenderer($ns->layoutmode); } else { $this->_helper->redirector('index', 'index', 'default'); } } }
/** * Create the array category tree * @param string $uri */ public static function createCategoryTree($id, $categoriesel = array()) { $cats = array(); $isfolder = false; $items = ProductsCategories::getbyParentId($id, 0); foreach ($items as $category) { $subcategory = self::createCategoryTree($category['category_id'], $categoriesel); $isfolder = $subcategory ? true : false; $selected = in_array($category['category_id'], $categoriesel) ? true : false; if ($subcategory) { $expanded = in_array($category['category_id'], $categoriesel) ? true : false; $cats[] = array('key' => $category['category_id'], 'title' => $category['name'], 'expand' => $expanded, 'select' => $selected, 'isFolder' => $isfolder, 'children' => $subcategory); } else { $cats[] = array('key' => $category['category_id'], 'title' => $category['name'], 'select' => $selected); } } return $cats; }