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); }
function copyProduct() { $sourceProduct = new Product($this->input->post('productId')); if (!$sourceProduct->exists()) { show_404(); } else { //copy product first $product = $sourceProduct->get_copy(); $i = 0; do { $i++; $name = "COPY " . $i . " OF - " . $sourceProduct->name; $checkName = new Product(); $checkName->where('name', $name); $checkName->get(); } while ($checkName->result_count() > 0); $product->name = $name; $product->productCode = ""; $product->save(); //copy category $sourceCategory = $sourceProduct->productcat; $product->save($sourceCategory->all); //copy spec $sourceSpec = $sourceProduct->productspec; foreach ($sourceSpec as $row) { $specItem = $row->get_copy(); $specItem->product_id = $product->id; $specItem->save(); $specItem->clear(); } //photo copy $photo = new Productphoto(); $photo->where('product_id', $sourceProduct->id); $photo->get(); foreach ($photo as $row) { $photoitem = $row->get_copy(); $photoitem->product_id = $product->id; $photoitem->save(); $photoitem->clear(); } //store copy $store = $sourceProduct->store; $product->save($store->all); //accessory $acces = $sourceProduct->accessory; foreach ($acces as $row) { $accessory = new Product($row->id); $product->save(array('accessories' => $accessory)); $accessory->clear(); } redirect("admin/products/edit/" . $product->id); } }
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); }