function renderXml() { //$this->id_lang $list = dibi::fetchAll(' SELECT product.id_product FROM `product` JOIN category_product USING (id_product) JOIN category USING (id_category) WHERE product.active = 1 AND product.added = 1 AND category.active = 1 GROUP BY (id_product)'); $this->template->baseUri = 'http://' . $_SERVER['HTTP_HOST']; $this->id_lang = 1; $this->template->items = array(); foreach ($list as $k => $l) { $this->template->items[$k] = ProductModel::getProductWithParams($l['id_product'], $this->id_lang, NULL); $this->template->items[$k]['url'] = $this->link(':Front:Product:default', array('id' => $l['id_product'], 'id_category' => $this->template->items[$k]['main_category'])); //zisti nazvy kategorii $category = array(); foreach ($this->template->items[$k]['categories'] as $cat) { $tmp = CategoryModel::get($cat['id_category'], $this->id_lang); $category[] = $tmp['name']; } $this->template->items[$k]['categories_name'] = implode(" | ", $category); } // dde($this->template->items); }
function beforeRender() { parent::beforeRender(); $this->template->id_category = $this->id; $this->template->category_parents = CategoryModel::getParents($this->template->id_category, $this->id_lang); //ak je iba jeden parent zobraz kategorie, inak zobraz produkty if (count($this->template->category_parents) == 1) { $id_parent = current($this->template->category_parents); $category_list = CategoryModel::getFluent('id_category')->where('id_parent = %i', $id_parent)->fetchAll(); $this->template->categories = array(); foreach ($category_list as $l) { $_tmp = CategoryModel::get($l->id_category, $this->id_lang); $_tmp['product_count'] = dibi::fetchSingle("SELECT COUNT(id_product) FROM [product] JOIN [category_product] USING(id_product) WHERE id_category = %i", $l->id_category); $this->template->categories[] = $_tmp; } $this->template->product_count = dibi::fetchSingle("SELECT COUNT(id_product) FROM [product] JOIN [category_product] USING(id_product) WHERE id_category = %i", $this->id); } else { $list = dibi::select('id_product')->from('product')->join('category_product')->using('(id_product)')->join('product_param')->using('(id_product)')->where('id_category = ', $this->id, 'AND product.active = 1'); /* * Filter */ $orderSession = $this['quickFilter']->getSession(); // dde($orderSession['order']); // $orderSession['order'] = 'price'; if ($orderSession['order']) { $list->orderBy($orderSession['order']); } else { $order_array = $this['quickFilter']->getOrderFilterArray(); $list->orderBy(key($order_array)); } $list->groupBy('id_product'); // dump($order); // print_r($list); $count_list = clone $list; // $count = $count_list->removeClause('select')->select('COUNT(id_product)')->fetchSingle(); $count = count($count_list); $vp = new VisualPaginator($this, 'paginator'); $paginator = $vp->getPaginator(); $numOnPageSession = $this['quickFilter']->getSession(); if ($numOnPageSession['num']) { $paginator->itemsPerPage = $numOnPageSession['num']; } else { $num_on_page_array = $this['quickFilter']->getNumOnPageFilterArray(); $paginator->itemsPerPage = key($num_on_page_array); } $paginator->itemCount = (int) $count; $this->template->product_count = $count; $this->template->products = $list->limit($paginator->offset . ',' . $paginator->itemsPerPage)->fetchAll(); //dump($this->template->products); $this->template->paginator = $paginator; foreach ($this->template->products as $k => $p) { $this->template->products[$k] = ProductModel::getProductWithParams($p['id_product'], $this->id_lang, $this->user); } // }; } // print_r($this->template->products);exit; }