public function index($params)
 {
     $id = $params[0];
     $page = isset($params[1]) ? $params[1] : 1;
     $products = array();
     if ($pros = Product::query()->where([['`active`', '=', 1], ['`id_category`', '=', $id]])->order_by('`order`')->take(12)->skip($page * 12)->get()) {
         while ($row = $pros->fetch_assoc()) {
             $pro = new Product($row);
             if ($imgs = Product_Image::query()->where([['`id_product`', '=', $pro->id]])->take(1)->get()) {
                 $images = array();
                 while ($other_row = $imgs->fetch_assoc()) {
                     $image = new Product_Image($other_row);
                     array_push($images, $image);
                 }
                 $pro->images = $images;
                 $imgs->free();
             }
             array_push($products, $pro);
         }
         $pros->free();
     }
     if ($pros = Product::query()->where([['`active`', '=', 1], ['`id_category`', '=', $id]])->order_by('`view`')->take(1)->get()) {
         $featured = null;
         if ($row = $pros->fetch_assoc()) {
             $featured = new Product($row);
             if ($imgs = Product_Image::query()->where([['`id_product`', '=', $featured->id]])->take(1)->get()) {
                 $images = array();
                 while ($other_row = $imgs->fetch_assoc()) {
                     $image = new Product_Image($other_row);
                     array_push($images, $image);
                 }
                 $featured->images = $images;
                 $imgs->free();
             }
         }
         $pros->free();
     }
     if ($count = Product::query(['count(*) as `count`'])->where([['`active`', '=', 1], ['`id_category`', '=', $id]])->get()) {
         if ($row = $count->fetch_assoc()) {
             $cnt = ceil($row['count'] / 12);
         }
         $count->free();
     }
     $this->render('views/category/index.php', ['products' => $products, 'featured_product' => $featured, 'id_cat' => $id, 'page' => $page, 'total_page' => $cnt]);
 }
 public function _new_products()
 {
     //'select * from eli_product where `active` =1 order by `id` desc limit 8'
     $products = array();
     if ($pros = Product::query()->where([['`active`', '=', 1]])->order_by('`order`')->take(8)->get()) {
         while ($row = $pros->fetch_assoc()) {
             //'select * from eli_product_image where `id_product`='	.$pro->id. ' limit 1'
             $pro = new Product($row);
             if ($imgs = Product_Image::query()->where([['`id_product`', '=', $pro->id]])->take(1)->get()) {
                 $images = array();
                 if ($other_row = $imgs->fetch_assoc()) {
                     $image = new Product_Image($other_row);
                     array_push($images, $image);
                 }
                 $pro->images = $images;
                 $imgs->free();
             }
             array_push($products, $pro);
         }
         $pros->free();
     }
     return $products;
 }