Example #1
0
 function save($object = '', $related_field = '')
 {
     if (!$this->exists()) {
         $o = new Productphoto();
         $o->where('product_id', $this->product_id);
         $o->select_max('position');
         $o->get();
         if (count($o->all) != 0) {
             $max = $o->position + 1;
             $this->position = $max;
         } else {
             $this->postion = 1;
         }
     }
     return parent::save($object, $related_field);
 }
Example #2
0
 function edit($id = 0, $productCatId = 0)
 {
     $product = new Product($id);
     if (!$product->exists()) {
         $product->isAutoGenerateUrl = 1;
         $product->active = 1;
     }
     /**
      * get list store
      */
     $stores = new Store();
     $stores->order_by('position', 'asc');
     $stores->get_iterated();
     $dis['stores'] = $stores;
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $this->load->library('file_lib');
         //save any param
         $product->productCode = $this->input->post('productCode');
         $product->name_vietnamese = $this->input->post('productName_vietnamese');
         $product->name_english = $this->input->post('productName_english');
         $product->name_japanese = $this->input->post('productName_japanese');
         $product->des_vietnamese = $this->input->post('des_vietnamese');
         $product->des_english = $this->input->post('des_english');
         $product->des_japanese = $this->input->post('des_japanese');
         $product->productstatu_id = $this->input->post('productstatu_id');
         $product->productmanufacture_id = $this->input->post('productManufactureId');
         $product->isSale = $this->input->post('isSale');
         $product->saleOffPrice = $this->input->post('saleOffPrice');
         $product->saleOffPriceText = $this->input->post('saleOffPriceText');
         $product->price = $this->input->post('price');
         $product->priceText = $this->input->post('priceText');
         $product->isUsed = $this->input->post('isUsed');
         $product->isGift = $this->input->post('isGift');
         $product->isHot = $this->input->post('isHot');
         $product->isNew = $this->input->post('isNew');
         $product->seo_title = $this->input->post('seo_title');
         $product->seo_description = $this->input->post('seo_description');
         $product->seo_keyword = $this->input->post('seo_keyword');
         $product->searchKey = $this->input->post('searchKey');
         $product->txtDescription_vietnamese = $this->input->post('txtDescription_vietnamese');
         $product->txtDescription_english = $this->input->post('txtDescription_english');
         $product->txtGift = $this->input->post('txtGift');
         $product->txtSumary = $this->input->post('txtSumary');
         $product->txtVideo = $this->input->post('txtVideo');
         $product->url_vietnamese = $this->input->post('url_vietnamese');
         $product->url_english = $this->input->post('url_english');
         $product->origin = $this->input->post('origin');
         $product->warranty = $this->input->post('warranty');
         $product->active = $this->input->post('isActive');
         $product->promotion = $this->input->post('promotion');
         $product->status = $this->input->post('productstatus');
         $product->inBox = $this->input->post('inBox');
         $product->isLinePrice = $this->input->post('isLinePrice');
         $product->isLinePriceSaleOff = $this->input->post('isLinePriceSaleOff');
         $product->isHighlightPriceSaleOff = $this->input->post('isHighlightPriceSaleOff');
         $product->priceColor = $this->input->post('priceColor');
         $product->saleOffPriceColor = $this->input->post('saleOffPriceColor');
         $product->color = $this->input->post('color');
         $product->weight = $this->input->post('weight');
         $product->materials = $this->input->post('materials');
         $product->size = $this->input->post('size');
         $product->style = $this->input->post('style');
         $product->productcat_id = $this->input->post('productcat_id');
         if (trim($product->saleOffPrice) == "") {
             $product->finalPrice = $product->price;
         } else {
             $product->finalPrice = $product->saleOffPrice;
         }
         if ($product->exists()) {
             $product->updator = $this->logged_in_user->username;
         } else {
             $product->creator = $this->logged_in_user->username;
         }
         //check product representive image is available inside post request
         if ($_FILES['logo']['name'] != "") {
             $dataupload = $this->file_lib->upload('logo', 'img/products/');
             if (is_array($dataupload)) {
                 $product->image = 'img/products/' . $dataupload['file_name'];
             } else {
                 flash_message('error', $dataupload);
             }
         }
         //first save
         if ($product->save()) {
         }
     }
     //create list product status
     $productstatus = new Productstatu();
     $productstatus->order_by('id', 'asc');
     $productstatus->get()->all;
     //create list productcomment.
     /*$productcomments = new Productcomment();
       $productcomments->order_by('id', 'desc');
       $productcomments->where('product_id', $id);
       $productcomments->get()->all;*/
     //create list productphotos
     $productphotos = new Productphoto();
     $productphotos->where('product_id', $id);
     $productphotos->order_by('position', 'asc');
     $productphotos->order_by('id', 'desc');
     $productphotos->get_iterated();
     $accessories = $product->accessory;
     $dis['accessories'] = $accessories;
     $productSpec = new productspec();
     $productSpec->where('product_id', $product->id);
     $productSpec->order_by('position', 'asc');
     $productSpec->get_iterated();
     $productCat = $product->productcat;
     $allSpec = new productspec();
     if ($product->exists()) {
         $allSpec->where('product_id', $product->id);
     } else {
         $allSpec->where('product_id', 0);
     }
     $allSpec->order_by('position', 'asc');
     $allSpec->get_iterated();
     //if create new product with productcat
     if (!$product->exists()) {
         if ($productCatId != 0) {
             $productCat = new Productcat($productCatId);
             $productSpec = $productCat->getSpec();
             $allSpec = $productCat->getSpec();
         }
     }
     $sitelanguage = new Sitelanguage();
     $sitelanguage->order_by('position', 'asc');
     $sitelanguage->get();
     $dis['sitelanguage'] = $sitelanguage;
     $productCat = new Productcat();
     $productCat->order_by('position', 'asc');
     $productCat->get_iterated();
     $dis['productSpec'] = $productSpec;
     $dis['productCat'] = $productCat;
     $dis['allSpec'] = $allSpec;
     //setPagination($this->admin.'productphoto/listAll/',$productphotos->paged->total_rows,$limit,4);
     $dis['title_table'] = "Trang hiện tại:";
     $dis['productphotos'] = $productphotos;
     $dis['base_url'] = base_url();
     $dis['object'] = $product;
     $dis['productcomments'] = $productcomments;
     $dis['productstatus'] = $productstatus;
     $dis['title'] = "Thêm/ Sửa sản phẩm";
     $dis['menu_active'] = "Sản phẩm";
     $dis['view'] = "products/edit";
     $dis['nav_menu'] = array(array("type" => "add", "text" => "Thêm sp khác", "link" => "{$this->admin_url}products/edit", "onclick" => ""));
     if ($product->exists()) {
         array_push($dis['nav_menu'], array("type" => "add", "text" => "Thêm hình ảnh", "link" => "{$this->admin_url}productphotos/edit/" . $product->id, "onclick" => ""));
     } else {
         $product->isAutoGenerateUrl = 1;
         $product->isActive = 1;
     }
     $this->viewadmin($dis);
 }
Example #3
0
 function setDefault($id)
 {
     $productphotos = new Productphoto($id);
     $photo = new Productphoto();
     $photo->where('product_id', $productphotos->product_id);
     $photo->get_iterated();
     foreach ($photo as $row) {
         $row->isDefault = 0;
         $row->save();
     }
     $product = new Product($productphotos->product_id);
     $product->image = $productphotos->path;
     $product->save();
     $productphotos->isDefault = 1;
     $productphotos->save();
     //$this->resize_image($productphotos->path);
     redirect($_SERVER['HTTP_REFERER']);
 }
Example #4
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);
 }