Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1.     public function selection($cat = '*', $nb = 3)
  2.     {
  3.         $prevs = $categories = $rows = array();
  4.         if(is_numeric($cat)){
  5.             $cats = array(['id_category'=>$cat]);
  6.         }else{
  7.             $sql = "SELECT l.id_category FROM ps_category_lang l JOIN ps_category c ON l.id_category = c.id_category WHERE l.name LIKE '$cat%' ORDER BY c.position";
  8.             $cats = Db::getInstance()->ExecuteS($sql);
  9.         }
  10.         foreach ($cats as $k => $v) {
  11.             if (in_array($v['id_category'], $prevs)) continue;
  12.             $category = $categories[$k] = new Category($v['id_category'], (int)Context::getContext()->language->id);
  13.             $rows[$k] = $category->getProducts((int)Context::getContext()->language->id, 1, $nb, 'position');
  14.             $prevs[ ] = $v['id_category'];
  15.             if ($rows === false || empty($rows))    return false;
  16.         }
  17.         $this->smarty->assign([
  18.             'rows' => $rows,
  19.             'categories' => $categories,
  20.             'size' => $nb
  21.         ]);
  22.         return $this->display(__FILE__, 'selection.tpl');
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement