Example #1
0
 function get_nutrition_by_product()
 {
     $return_arr['status'] = false;
     $product_selected_id = $this->input->post('product_selected_id');
     if (!$product_selected_id) {
         return;
     }
     $product = new Product();
     $nutrition_categories = new Nutrition_category();
     $product->get_full_info($product_selected_id);
     if (!$product->exists()) {
         return;
     }
     $product->nutrition->get_full_info();
     $meras_available = '<option value = 0> 100 gramms </option>';
     foreach ($product->mera as $mera) {
         $meras_available .= '<option value = ' . $mera->join_seq . '> ' . $mera->join_name . ' ( ' . $mera->join_value . ' gm ) </option>';
     }
     #print_flex($meras_available);
     $nutrition_categories->get_full_info();
     $this->data['dm_nutrition_categories'] = $nutrition_categories;
     $return_arr['nutrition_facts'] = $this->load->view('shared/nutrition_facts', array('dm_nutritions' => $product->nutrition), true);
     $return_arr['nutrition_tables'] = $this->load->view('products/nutrition_tables', array('dm_product' => $product, 'dm_nutrition_categories' => $nutrition_categories), true);
     $return_arr['meras_available'] = $meras_available;
     $return_arr['status'] = true;
     echo json_encode($return_arr);
     return;
 }
require_once "DataBase/Product.php";
require_once "DataBase_Net/Price_Net.php";
require_once "DataBase/Price.php";
require_once "DataBase/Priceset.php";
// sync Product database
$product = new Product();
$product_net = new Product_Net();
$price = new Price();
$price_net = new Price_Net();
$priceset = new Priceset();
$new_product_count = 0;
$del_product_count = 0;
// delete remote products if not locally available anymore
$remote_product = $product_net->get('', array('product_id'));
foreach ($remote_product as $tmp) {
    if ($product->exists($tmp[0], " available=1 ") == false) {
        $product_net->delete($tmp[0]);
        // delete also the prices
        $local_pricesets = $priceset->get('');
        foreach ($local_pricesets as $tmp_priceset) {
            $tmp_price = $price_net->getPrice($tmp_priceset[0], $tmp[0]);
            if (count($tmp_price) > 0) {
                $price_net->delete($tmp_price[0][0]);
            }
        }
        $del_product_count++;
    }
}
// add products remote if newly available locally
$remote_products = $product_net->get('', array('product_id'));
$local_products = $product->get('', array('product_id'), " available=1 ");
Example #3
0
 function _product_name_exists($product_name)
 {
     $product = new Product();
     $product->where('name', $product_name)->get();
     if ($product->exists()) {
         return false;
     }
     return true;
 }
Example #4
0
 function active($id = 0, $value)
 {
     if ($id != 0) {
         $products = new Product($id);
         if (!$products->exists()) {
             show_404();
         }
         $products->active = ($products->active + 1) % 2;
         $products->save();
     } else {
         $arr = $this->input->post('checkinput');
         foreach ($arr as $row) {
             $products = new Product($row);
             $products->active = $value;
             $products->save();
             $products->clear();
         }
     }
     flash_message('success', "Kích hoạt thành công.");
     redirect($_SERVER['HTTP_REFERER']);
 }
Example #5
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);
 }
Example #6
0
 public function upload_photo($product_id = NULL)
 {
     if (is_null($product_id)) {
         add_error_flash_message('Produkt sa nenašiel.');
         redirect(site_url('products'));
     }
     $product = new Product();
     $product->get_by_id((int) $product_id);
     if (!$product->exists()) {
         add_error_flash_message('Produkt sa nenašiel.');
         redirect(site_url('products'));
     }
     $upload_config = array('upload_path' => 'user/products/data/' . (int) $product->id . '/', 'allowed_types' => 'jpg|png', 'max_size' => '1024', 'max_width' => '1024', 'max_height' => '1024', 'file_name' => 'temp_product.png', 'overwrite' => TRUE);
     $this->load->library('upload', $upload_config);
     @mkdir($upload_config['upload_path'], DIR_WRITE_MODE, TRUE);
     if ($this->upload->do_upload('photo')) {
         $resize_config = array('image_library' => 'gd2', 'source_image' => $upload_config['upload_path'] . $upload_config['file_name'], 'create_thumb' => FALSE, 'maintain_ratio' => TRUE, 'width' => 256, 'height' => 256, 'quality' => '90%', 'new_image' => $upload_config['upload_path'] . 'product.png');
         $this->load->library('image_lib', $resize_config);
         if ($this->image_lib->resize()) {
             $resize_config['width'] = 64;
             $resize_config['height'] = 64;
             $resize_config['new_image'] = $upload_config['upload_path'] . 'product_min.png';
             @unlink($upload_config['new_image']);
             $this->image_lib->initialize($resize_config);
             $this->image_lib->resize();
             @unlink($resize_config['source_image']);
             add_success_flash_message('Súbor úspešne nahraný.');
             redirect(site_url('products/edit_photo/' . (int) $product->id));
         } else {
             @unlink($resize_config['source_image']);
             add_error_flash_message('Súbor sa nepodarilo preškálovať:' . $this->image_lib->display_errors('<br /><br />', ''));
             redirect(site_url('products/edit_photo/' . (int) $product->id));
         }
     } else {
         add_error_flash_message('Súbor sa nepodarilo nahrať, vznikla nasledujúca chyba:' . $this->upload->display_errors('<br /><br />', ''));
         redirect(site_url('products/edit_photo/' . (int) $product->id));
     }
 }
Example #7
0
 /**
  * Will test the build of the more comples many-to-many and the case where there is more than one relationships.
  */
 public function testComplexBuild()
 {
     self::reset();
     fFixture::setDatabase(fORMDatabase::retrieve());
     $fixture = fFixture::create(FIXTURES_ROOT);
     // includes: categories.json, products.json, users.json, shops.json and the join table categories_products.json
     $fixture->build();
     $shop = new Shop(1);
     $user = new User(1);
     $category = new Category(1);
     $product = new Product(1);
     $this->assertTrue($shop->exists());
     $this->assertTrue($user->exists());
     $this->assertTrue($category->exists());
     $this->assertTrue($product->exists());
     // Shop has manu users and products
     $this->assertEquals(1, $shop->buildUsers()->count());
     $this->assertEquals(1, $shop->buildProducts()->count());
     // User and product has a shop
     $this->assertTrue($user->createShop()->exists());
     $this->assertTrue($product->createShop()->exists());
     // Product and category has many of eachother
     $this->assertEquals(1, $product->buildCategories()->count());
     $this->assertEquals(1, $category->buildProducts()->count());
 }
Example #8
0
 function delete($id = NULL, $category_id = NULL, $page = NULL)
 {
     $this->load->helper('file');
     //filter & Sanitize $id
     $id = $id != 0 ? filter_var($id, FILTER_VALIDATE_INT) : NULL;
     //redirect if it´s no correct
     if (!$id) {
         $this->session->set_flashdata('message', array('type' => 'warning', 'text' => lang('web_object_not_exist')));
         redirect('admin/products/');
     }
     //search the item to delete
     if (Product::exists($id)) {
         $product = Product::find($id);
         $image = $product->image;
     } else {
         $this->session->set_flashdata('message', array('type' => 'warning', 'text' => lang('web_object_not_exist')));
         redirect('admin/products/');
     }
     //delete the item
     if ($product->delete() == TRUE) {
         //delete all the images
         if (is_file(FCPATH . 'public/uploads/products/img/' . $image)) {
             unlink(FCPATH . 'public/uploads/products/img/' . $image);
         }
         if (is_file(FCPATH . 'public/uploads/products/img/thumbs/' . $image)) {
             unlink(FCPATH . 'public/uploads/products/img/thumbs/' . $image);
         }
         $this->session->set_flashdata('message', array('type' => 'success', 'text' => lang('web_delete_success')));
         if ($category_id != 0) {
             redirect('admin/products/product_list/' . $category_id . '/' . $page);
         } else {
             redirect('admin/products/' . $page);
         }
     } else {
         $this->session->set_flashdata('message', array('type' => 'error', 'text' => lang('web_delete_failed')));
         redirect('admin/products/');
     }
 }