Example #1
0
 function detail()
 {
     $urlCat = $this->uri->segment(2);
     if ($this->lang->lang() == 'vi') {
         $productCat = new Productcat();
         $productCat->where('url_vietnamese', $urlCat);
         $productCat->get()->all;
         if (!$productCat->exists()) {
             redirect("");
         }
     } else {
         $productCat = new Productcat();
         $productCat->where('url_english', $urlCat);
         $productCat->get()->all;
         if (!$productCat->exists()) {
             redirect("");
         }
     }
     $dis['productCat'] = $productCat;
     $url = $this->uri->segment(3);
     $arrTitle = explode('.', $url);
     if ($arrTitle[1] == '' || $arrTitle[1] != 'html') {
         $this->cat();
     }
     $url = $arrTitle[0];
     if ($this->lang->lang() == 'vi') {
         $product = new Product();
         $product->where('url_vietnamese', $url);
         $product->where('productcat_id', $productCat->id);
         $product->include_related('productphoto');
         $product->get();
         $product->view = $product->view + 1;
         $product->save();
         if (!$product->exists()) {
             redirect("");
         }
         $this->page_title = $product->seo_title_vietnamese;
         $this->page_description = $product->seo_description_vietnamese;
         $this->page_keyword = $product->seo_keyword_vietnamese;
     } else {
         $product = new Product();
         $product->where('url_english', $url);
         $product->where('productcat_id', $productCat->id);
         $product->include_related('productphoto');
         $product->get();
         if (!$product->exists()) {
             redirect("");
         }
         $this->page_title = $product->seo_title_english;
         $this->page_description = $product->seo_description_english;
         $this->page_keyword = $product->seo_keyword_english;
     }
     $dis['product'] = $product;
     // get all photo of product
     $productphotos = new Productphoto();
     $productphotos->where('product_id', $product->id);
     $productphotos->order_by('position', 'asc');
     $productphotos->order_by('id', 'desc');
     $productphotos->get();
     $dis['productPhotos'] = $productphotos;
     $productPhotosActive = $productphotos->limit(1);
     $dis['productPhotosActive'] = $productPhotosActive;
     $productSame = new Product();
     $productSame->order_by('id', 'desc');
     $productSame->where('productcat_id', $productCat->id);
     $productSame->where('id !=', $product->id);
     $productSame->get_iterated();
     $dis['productSame'] = $productSame;
     $dis['base_url'] = base_url();
     $dis['view'] = 'front/product/product_detail';
     $this->viewfront($dis);
 }