Exemple #1
0
 /**
  * Displays a product category
  *
  * (non-PHPdoc)
  * @see tienda/admin/TiendaController#display($cachable)
  */
 function display($cachable = false, $urlparams = false)
 {
     JRequest::setVar('view', $this->get('suffix'));
     JRequest::setVar('search', false);
     $view = $this->getView($this->get('suffix'), JFactory::getDocument()->getType());
     $model = $this->getModel($this->get('suffix'));
     $state = $this->_setModelState();
     $session = JFactory::getSession();
     $app = JFactory::getApplication();
     $ns = $app->getName() . '::' . 'com.tienda.products.state.' . $this->itemid;
     $session->set($ns, $state);
     $app = JFactory::getApplication();
     $ns_general = $app->getName() . '::' . 'com.tienda.products.state';
     $session->set($ns_general, $state);
     // get the category we're looking at
     $filter_category = $model->getState('filter_category', JRequest::getVar('filter_category'));
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     $cmodel = JModel::getInstance('Categories', 'TiendaModel');
     $cat = $cmodel->getTable();
     $cat->load($filter_category);
     // set the title based on the selected category
     $title = empty($cat->category_name) ? JText::_('COM_TIENDA_ALL_CATEGORIES') : JText::_($cat->category_name);
     $level = !empty($filter_category) ? $filter_category : '1';
     // breadcrumb support
     $app = JFactory::getApplication();
     $pathway = $app->getPathway();
     // does this item have its own itemid?  if so, let joomla handle the breadcrumb,
     // otherwise, help it out a little bit
     $category_itemid = $this->router->category($filter_category, true);
     if (!$category_itemid) {
         $category_itemid = JRequest::getInt('Itemid');
         $items = Tienda::getClass("TiendaHelperCategory", 'helpers.category')->getPathName($filter_category, 'array');
         if (!empty($items)) {
             // add the categories to the pathway
             Tienda::getClass("TiendaHelperPathway", 'helpers.pathway')->insertCategories($items, $category_itemid);
         }
         // add the item being viewed to the pathway
         $pathway_values = $pathway->getPathway();
         $pathway_names = Tienda::getClass("TiendaHelperBase", 'helpers._base')->getColumn($pathway_values, 'name');
         $pathway_links = Tienda::getClass("TiendaHelperBase", 'helpers._base')->getColumn($pathway_values, 'link');
         $cat_url = "index.php?Itemid={$category_itemid}";
         if (!in_array($cat->category_name, $pathway_names)) {
             $pathway->addItem($title);
         }
     }
     $cat->itemid = $category_itemid;
     // get the category's sub categories
     $cmodel->setState('filter_level', $level);
     $cmodel->setState('filter_enabled', '1');
     $cmodel->setState('order', 'tbl.lft');
     $cmodel->setState('direction', 'ASC');
     if ($citems = $cmodel->getList()) {
         foreach ($citems as $item) {
             $item->itemid_string = null;
             $item->itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($item->category_id, true);
             if (!empty($item->itemid)) {
                 $item->itemid_string = "&Itemid=" . $item->itemid;
             }
         }
     }
     $this->_list = true;
     // if you want to display a slightly differen add-to-cart area for list view, check this boolean
     // get the products to be displayed in this category
     if ($items = $model->getList()) {
         JRequest::setVar('page', 'category');
         // for "getCartButton"
         $this->display_cartbutton = Tienda::getInstance()->get('display_category_cartbuttons', '1');
         foreach ($items as $item) {
             $item->itemid_string = null;
             $item->itemid = (int) Tienda::getClass("TiendaHelperRoute", 'helpers.route')->product($item->product_id, null, true);
             if (!empty($item->itemid)) {
                 $item->itemid_string = "&Itemid=" . $item->itemid;
             }
         }
     }
     if ($model->getState('filter_price_from') > '0' || $model->getState('filter_price_to') > '0') {
         $url = "index.php?option=com_tienda&view=products&filter_category={$filter_category}&filter_price_from=&filter_price_to=";
         $from = TiendaHelperBase::currency($model->getState('filter_price_from'));
         $to = $model->getState('filter_price_to') > 0 ? TiendaHelperBase::currency($model->getState('filter_price_to')) : JText::_('COM_TIENDA_MAXIMUM_PRICE');
         $view->assign('remove_pricefilter_url', $url);
         $view->assign('pricefilter_applied', true);
         $view->assign('filterprice_from', $from);
         $view->assign('filterprice_to', $to);
     }
     if (Tienda::getInstance()->get('enable_product_compare', '1')) {
         Tienda::load("TiendaHelperProductCompare", 'helpers.productcompare');
         $compareitems = TiendaHelperProductCompare::getComparedProducts();
         $view->assign('compareitems', $compareitems);
     }
     $view->assign('level', $level);
     $view->assign('title', $title);
     $view->assign('cat', $cat);
     $view->assign('citems', $citems);
     $view->assign('items', $items);
     $view->set('_doTask', true);
     $view->setModel($model, true);
     // add the media/templates folder as a valid path for templates
     $view->addTemplatePath(Tienda::getPath('categories_templates'));
     // but add back the template overrides folder to give it priority
     $template_overrides = JPATH_BASE . '/templates/' . $app->getTemplate() . '/html/com_tienda/' . $view->getName();
     $view->addTemplatePath($template_overrides);
     // using a helper file, we determine the category's layout
     $layout = Tienda::getClass('TiendaHelperCategory', 'helpers.category')->getLayout($cat->category_id);
     $view->setLayout($layout);
     $view->display();
     $this->footer();
     return;
 }