Example #1
0
 public function productsBySubCatagory($id)
 {
     $query = Product::where('subcatagory_id', '=', $id)->paginate(12);
     $catagory = Catagory::all();
     $subcatagory = Subcatagory::all();
     return View::make('Products.ProductsByCatagory', ['catagories' => $catagory, 'products' => $query, 'subcatagories' => $subcatagory]);
 }
 /**
  * Display all comments by productId.
  *
  * @return Response
  */
 public function index($productId)
 {
     $product = Product::where('id', $productId)->first();
     $reviews = Review::where('productId', $productId)->get();
     $product["reviews"] = $reviews;
     return $product;
 }
 public function postUpdateCard()
 {
     // Add Curl library
     require_once app_path() . "/libraries/Curl/Curl.php";
     // Get Product
     $product = Product::where('code', Input::get('code'))->first();
     // Get Expiry month and year
     $expiry = explode(' / ', Input::get('ccExpire'));
     // Put all values in session
     Session::flash('ccNum', Input::get('ccNum'));
     Session::flash('ccExpire', Input::get('ccExpire'));
     Session::flash('ccCVC', Input::get('ccCVC'));
     $data = array('email' => Input::get('email'), 'code' => Input::get('code'), 'number' => Input::get('ccNum'), 'exp_month' => !empty($expiry[0]) ? $expiry[0] : NULL, 'exp_year' => !empty($expiry[1]) ? $expiry[1] : NULL, 'cvc' => Input::get('ccCVC'));
     $data['key'] = DKHelpers::GenerateHash($data, $product->api_key);
     $url = url() . "/api/v1/update-card";
     // Post data to IPN
     $curl = new Curl();
     $response = $curl->simple_post($url, $data, array(CURLOPT_BUFFERSIZE => 10));
     $response = json_decode($response);
     if (empty($response->error)) {
         $success = "Your card (**** **** **** {$response->last4}) has been updated successfully.";
         return Redirect::back()->with('success', $success);
     } else {
         return Redirect::back()->with('error', $response->error);
     }
 }
Example #4
0
 /**
  * Display Home Page
  * @return mixed
  */
 public function getIndex()
 {
     // Session::flush();
     $data['sales'] = Product::where('price_sale', '<>', 0)->get();
     $data['bestsaller'] = Product::where('price_bestsaller', '<>', 0)->get();
     return View::make('index', $data);
 }
 /**
  * Generate license
  */
 public function postGenerateLicense()
 {
     $rules = array('transaction_id' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('admin/utilities/generate-license')->withErrors($validator)->withInput();
     } else {
         $transaction_id = Input::get('transaction_id');
         if ($transaction = Transaction::where('id', '=', $transaction_id)->first()) {
             if ($license = License::where('transaction_id', '=', $transaction_id)->first()) {
                 Session::flash('alert_error', '<strong>Ooops!</strong> License for given transaction already exists.');
                 return Redirect::to('admin/licenses?q=' . $license->license_key . '&param=key');
             }
             $plan = Plan::where('id', '=', $transaction->plan_id)->first();
             if ($plan->has_license) {
                 $product = Product::where('id', '=', $plan->product_id)->first();
                 $license_key = License::generate($product->code);
                 // Save license
                 $license = new License();
                 $license->license_key = $license_key;
                 $license->transaction_id = $transaction_id;
                 $license->allowed_usage = $plan->license_allowed_usage;
                 $license->save();
                 Session::flash('alert_message', '<strong>Well done!</strong> You successfully have generated license key.');
                 return Redirect::to('admin/licenses?q=' . $license_key . '&param=key');
             } else {
                 Session::flash('alert_error', '<strong>Ooops!</strong> This plan does not allow to generate a license key.');
                 return Redirect::to('admin/utilities/generate-license');
             }
         } else {
             Session::flash('alert_error', '<strong>Ooops!</strong> Transaction was not found.');
             return Redirect::to('admin/utilities/generate-license');
         }
     }
 }
 public function search()
 {
     $query_supplier = '%' . Input::get('supplier') . '%';
     $query_metal = '%' . Input::get('metal') . '%';
     $query_city = '%' . Input::get('city') . '%';
     $query_grade_a = '%' . Input::get('grade_a') . '%';
     $query_grade_b = '%' . Input::get('grade_b') . '%';
     $query_thickness = '%' . Input::get('thickness') . '%';
     $query_shape = '%' . Input::get('shape') . '%';
     if (Input::has('volume_from')) {
         $query_volume_from = Input::get('volume_from');
     } else {
         $query_volume_from = 0;
     }
     if (Input::has('volume_to')) {
         $query_volume_to = Input::get('volume_to');
     } else {
         $query_volume_to = Product::max('volume');
     }
     if (Input::has('date_from')) {
         $query_date_from = date('Y-m-d H:i:s', strtotime(Input::get('date_from')));
     } else {
         $query_date_from = date('Y-m-d H:i:s', strtotime("1-1-1970"));
     }
     if (Input::has('date_to')) {
         $query_date_to = date('Y-m-d H:i:s', strtotime(Input::get('date_to') . " 23:59"));
     } else {
         $query_date_to = date('Y-m-d H:i:s', strtotime("now"));
     }
     $products = Product::where('supplier', 'LIKE', $query_supplier)->where('metal', 'LIKE', $query_metal)->where('city', 'LIKE', $query_city)->where('grade_a', 'LIKE', $query_grade_a)->where('grade_b', 'LIKE', $query_grade_b)->where('thickness', 'LIKE', $query_thickness)->where('shape', 'LIKE', $query_shape)->whereBetween('created_at', array($query_date_from, $query_date_to))->whereBetween('volume', array($query_volume_from, $query_volume_to))->paginate(5);
     $suppliers = Product::lists('supplier', 'supplier');
     $metals = Product::lists('metal', 'metal');
     return View::make('products.list')->with('products', $products)->with('suppliers', $suppliers)->with('metals', $metals)->withInput(Input::flash());
 }
 public function updateProductsAction()
 {
     $user = Auth::user();
     $config = Config::get('providers.' . $user->provider);
     $client = new \Guzzle\Http\Client();
     $headers = $config['headers'];
     array_walk($headers, function (&$value, $key) use($user) {
         $value = str_replace('{token}', $user->access_token, $value);
     });
     $request = $client->get(str_replace('{blog_id}', $user->blog_id, $config['mediaUri']));
     $request->setHeaders($headers);
     $request->getHeaders()->toArray();
     $response = $request->send();
     $images = $response->json()['media'];
     $products = [];
     foreach ($images as $image) {
         if (!($product = Product::where('image_id', '=', $image['id'])->first())) {
             $product = new Product();
             $product->image_id = $image['id'];
             $product->image = $image['link'];
             $user->products()->save($product);
             $products[] = $product;
         }
     }
     return Redirect::route('products');
 }
Example #8
0
 public static function getSearch($input = array())
 {
     $result = Product::where(function ($query) use($input) {
         if (!empty($input['category_id'])) {
             $query = $query->where('category_id', $input['category_id']);
         }
         if (!empty($input['type_id'])) {
             $query = $query->where('type_id', $input['type_id']);
         }
         if (!empty($input['price_id'])) {
             $query = $query->where('price_id', $input['price_id']);
         }
         if (!empty($input['time_id'])) {
             $inputDate = getTime($input['time_id']);
             $query = $query->where('start_time', '>=', $inputDate);
         }
         if (!empty($input['city_id'])) {
             $query = $query->where('city_id', $input['city_id']);
         }
         if (!empty($input['city'])) {
             $query = $query->where('city', $input['city']);
         }
         if (!empty($input['name'])) {
             $query = $query->where('name', 'like', '%' . $input['name'] . '%');
         }
         //lat long
         $query = $query->where('status', ACTIVE);
     })->select(listFieldProduct())->get();
     foreach ($result as $key => $value) {
         $value->avatar = url(PRODUCT_UPLOAD . '/' . $value->user_id . '/' . Product::find($value->id)->avatar);
         $value->block = Common::checkBlackList(Input::get('user_id'), $value->user_id);
     }
     return $result;
 }
Example #9
0
 function search()
 {
     $viewMode = $this->uri->segment(2, "") == "" ? "ma-tran" : $this->uri->segment(2);
     $orderBy = $this->uri->segment(3, "") == "" ? "moi-nhat" : $this->uri->segment(3);
     $page = $this->uri->segment(4, "") == "" ? "trang-1" : $this->uri->segment(4);
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $searchKey = $this->input->post('searchKey');
         $this->session->set_userdata('searchKey', $searchKey);
     }
     $searchKey = $this->session->userdata('searchkey');
     $limit = $viewMode == "ma-tran" ? 15 : 10;
     $offset = ($this->getPageNumber($page) - 1) * $limit;
     $product = new Product();
     if (trim($searchKey) != "") {
         $product->like('name', $searchKey);
     }
     $product->where('active', 1);
     $product->order_by($this->getOrderBy($orderBy), $this->getOrderDirection($orderBy));
     $product->get_paged_iterated();
     $dis['product'] = $product;
     $dis['pageUrl'] = "tim-kiem";
     $config['base_url'] = site_url($url . "/" . $viewMode . "/" . $orderBy . "/trang-");
     $config['total_rows'] = $product->paged->total_rows;
     $config['per_page'] = $limit;
     $config['use_page_numbers'] = TRUE;
     $config['uri_segment'] = 4;
     $config['num_links'] = 3;
     $config['full_tag_open'] = '<span class="pagin">';
     $config['full_tag_close'] = "</span>";
     $config['first_link'] = FALSE;
     $config['first_tag_open'] = '';
     $config['first_tag_close'] = '';
     $config['last_link'] = FALSE;
     $config['last_tag_open'] = '';
     $config['last_tag_close'] = '';
     $config['next_link'] = '<img src="' . base_url() . 'images/pagination_next.png" />';
     $config['next_tag_open'] = '';
     $config['next_tag_close'] = '';
     $config['prev_link'] = '<img src="' . base_url() . 'images/pagination_pre.png" /';
     $config['prev_tag_open'] = '';
     $config['prev_tag_close'] = '';
     $config['num_tag_open'] = '';
     $config['num_tag_close'] = '';
     $config['cur_tag_open'] = '<span class="active">';
     $config['cur_tag_close'] = '</span>';
     $this->pagination->initialize($config);
     if ($viewMode == 'ma-tran') {
         $dis['view'] = 'product/product_grid';
     } else {
         $dis['view'] = 'product/product_list';
     }
     $productSaleOff = new product();
     $productSaleOff->where('active', 1);
     $productSaleOff->where('isSale', 1);
     $productSaleOff->order_by('id', 'desc');
     $productSaleOff->get_iterated(15);
     $dis['productSaleOff'] = $productSaleOff;
     $dis['base_url'] = base_url();
     $this->viewfront($dis);
 }
Example #10
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $products = Product::where('id', '>', 0)->paginate(2);
     //this pagination . get 2 rows from database at once
     return View::make('product.index')->with('products', $products);
     //go to product/index.blade.php with two rows of database
 }
 public function getProducts($id)
 {
     $category = Category::find($id);
     $network = Network::where('category_id', '=', $id)->get();
     $product = Product::where('category_id', '=', $id)->paginate(9);
     $phone = Product::where('category_id', '=', $id)->get();
     return View::make('products.index')->with('category', $category)->with('network', $network)->with('product', $product)->with('phone', $phone);
 }
Example #12
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $product = Product::where('id', $id)->first();
     if ($product->user_id == Session::get('current_user')) {
         return Redirect::to('product/' . $product->id . '/edit')->with('product', $product);
     } else {
         return View::make('frontend/products/show')->with('product', $product);
     }
 }
Example #13
0
 public static function searchField($field, $value, $products_d = null)
 {
     if ($products_d) {
         return $products_d->where($field, 'LIKE', "%{$value}%");
     } else {
         $products_d = Product::where($field, 'LIKE', "%{$value}%");
         return $products_d;
     }
 }
 public function detailFavorite($userFavoriteId)
 {
     $input = Input::all();
     $sessionId = Common::checkSessionLogin($input);
     $listProducts = Product::where('user_id', $userFavoriteId)->get();
     foreach ($listProducts as $key => $value) {
         $value->avatar = url(PRODUCT_UPLOAD . '/' . $value->user_id . '/' . Product::find($value->id)->avatar);
     }
     return Common::returnData(200, SUCCESS, $input['user_id'], $sessionId, $listProducts);
 }
 public static function getAllProducts()
 {
     if (Session::has('merchant')) {
         $merchant = Session::get('merchant');
         $product_list = Product::where('merchant_id', $merchant['merchant_id'])->get();
     } else {
         $product_list = Product::All();
     }
     return $product_list;
 }
Example #16
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update()
 {
     $input = Input::all();
     $product = Product::where('id', '=', $input['editProductId']);
     $update = $product->update(array('product_name' => $input['editProName'], 'bike_cc' => $input['editProcc'], 'model' => $input['editProModel']));
     if ($update) {
         return json_encode(array('error' => 0, 'success' => 1));
     } else {
         return json_encode(array('error' => 1, 'success' => 0));
     }
 }
 public function edit($id)
 {
     if (!empty(Product::where('id', '=', $id)->first())) {
         // le produit existe
         $product = Product::find($id);
         $product->price = Input::get('price');
         $product->stock = Input::get('stock');
         $product->save();
     }
     return Redirect::to('/admin');
 }
Example #18
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     // $user = User::findOrFail($id);
     $ued = Sentry::getUser()->id;
     $user = $this->user->find($id);
     //$products =  DB::table('products')->where('user_id',$ued)->get();
     $products = Product::where('user_id', $ued)->paginate(10);
     //$picture = DB::table('pictures')->where('user_id',$ued)->find(1);
     $image = Picture::where('user_id', $ued)->orderBy('id', 'desc')->get()->take(1);
     // $images = $user->pictures->find(1);
     return View::make('protected.standardUser.edit')->withUser($user)->with('products', $products)->with('image', $image);
 }
Example #19
0
 public function getAddBag($id)
 {
     $bag = new Bag();
     $bag->user_id = Auth::user()->id;
     $bag->product_id = $id;
     $bag->quantity = 1;
     $bag->save();
     $product = Product::where('id', '=', $id)->first();
     // Flash and redirect.
     Session::flash('alert', $product->name . ' was added to your bag.');
     return Redirect::to('/collection/' . $product->slug);
 }
Example #20
0
 public function getServicios()
 {
     $servicios = Product::where('account_id', Auth::user()->account_id)->select('public_id', 'product_key', 'notes', 'cost', 'is_product', 'category_id')->where('is_product', 0)->orderBy('product_key', 'ASC')->get();
     foreach ($servicios as $key => $service) {
         $producOrService = $service->is_product ? 'producto' : 'servicio';
         $category_name = Category::where('account_id', Auth::user()->account_id)->select('name')->where('id', $service->category_id)->first();
         // $service->product_service = $producOrService;
         $service->category_name = $category_name->name;
         $service->accion = "<a class='btn btn-primary btn-xs' data-task='view' href='productos/{$service->public_id}'  style='text-decoration:none;color:white;'><i class='glyphicon glyphicon-eye-open'></i></a> <a class='btn btn-warning btn-xs' href='productos/{$service->public_id}/edit' style='text-decoration:none;color:white;'><i class='glyphicon glyphicon-edit'></i></a>";
     }
     $serviceJson = ['data' => $servicios];
     return Response::json($serviceJson);
 }
 public function success()
 {
     if (Input::get("token") && Input::get("PayerID")) {
         $token = Input::get('token');
         $update = Order::where('token', '=', $token)->update(array("status" => 1));
         $order = Order::where('token', '=', $token)->first();
         $items = Orderitem::where('order_id', '=', $order->id)->get();
         foreach ($items as $item) {
             $qt = $item->item_qt;
             Product::where('id', '=', $item->item_id)->decrement('stock', $qt);
         }
         return Redirect::to('product/all')->with('message', 'Votre commande a été passé !');
     }
 }
Example #22
0
 public function GetFirstImageUrl($product_id)
 {
     $query = Product::where('id', '=', $product_id)->first();
     $main_image_url = $query->main_image_url;
     if ($main_image_url != '') {
         return $main_image_url;
     } else {
         $query = static::where('product_id', '=', $product_id)->first();
         if (!is_object($query)) {
             return 'front/images/no-image.jpg';
         }
         return $query->url;
     }
 }
Example #23
0
 public static function getProduct($input = array())
 {
     $result = Product::where(function ($query) use($input) {
         if (!empty($input['user_id'])) {
             $query = $query->where('user_id', $input['user_id']);
         }
         if (!empty($input['category_id'])) {
             $query = $query->where('category_id', $input['category_id']);
         }
         if (!empty($input['type_id'])) {
             $query = $query->where('type_id', $input['type_id']);
         }
         if (!empty($input['price_id'])) {
             $query = $query->where('price_id', $input['price_id']);
         }
         if (!empty($input['city_id'])) {
             $query = $query->where('city_id', $input['city_id']);
         }
         if (!empty($input['city'])) {
             $query = $query->where('city', $input['city']);
         }
         if (!empty($input['status'])) {
             $query = $query->where('status', $input['status']);
         }
         if (!empty($input['name'])) {
             $query = $query->where('name', 'like', '%' . $input['name'] . '%');
         }
         if (!empty($input['time_id'])) {
             $inputDate = getTime($input['time_id']);
             $query = $query->where('start_time', '>=', $inputDate);
         }
         if (!empty($input['start_date'])) {
             $query = $query->where('start_time', '>=', $input['start_date']);
         }
         if (!empty($input['end_date'])) {
             $query = $query->where('start_time', '<=', $input['end_date']);
         }
         //lat long
         if (isset($input['ids'])) {
             $query = $query->whereIn('id', $input['ids']);
         }
     })->select(listFieldProduct())->orderBy('position', 'asc')->get();
     foreach ($result as $key => $value) {
         $value->avatar = url(PRODUCT_UPLOAD . '/' . $value->user_id . '/' . Product::find($value->id)->avatar);
         $value->block = Common::checkBlackList(Input::get('user_id'), $value->user_id);
         $value->favorite = CommonFavorite::checkFavoriteLike('User', $value->user_id, TYPE_FAVORITE_LIKE, Input::get('user_id'));
     }
     return $result;
 }
Example #24
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function getIndex()
 {
     if (Session::get('user_level') < Config::get('cms.shopManager')) {
         return Redirect::to(_l(URL::action('AdminHomeController@getIndex')));
     }
     $this->setLayout();
     if (Input::get('q')) {
         $products = Product::where(function ($query) {
             $query->where('title', 'LIKE', '%' . Input::get('q') . '%')->orwhere('long_content', 'LIKE', '%' . Input::get('q') . '%')->orwhere('short_content', 'LIKE', '%' . Input::get('q') . '%');
         })->orderBy('created_at', 'desc')->paginate(20);
     } else {
         $products = News::orderBy('created_at', 'desc')->paginate(20);
     }
     View::share('title', __(Lang::get('shop.products')));
     View::share('products', $products);
     $this->layout->content = View::make('backend.shop.product.index');
 }
Example #25
0
 /**
  *
  * @param $catAlias string
  * @param $subCatAlias string
  * @return nothing
  * @author Tremor
  */
 public function category($catAlias, $subCatAlias = 0)
 {
     if ($subCatAlias) {
         $category = Category::where('alias', $subCatAlias)->first();
         $this->data['productList'] = Product::where('category_id', $category->id)->where('is_build', 0)->orderBy('sort')->get();
     } else {
         $category = Category::where('alias', $catAlias)->first();
         $subcategoryList = Category::where('main', $category->id)->get();
         $product = Product::where('category_id', $category->id)->where('is_build', 0);
         foreach ($subcategoryList as $subcategory) {
             $product = $product->orWhere('category_id', $subcategory->id);
         }
         $this->data['productList'] = $product->orderBy('sort')->get();
     }
     $this->data['selectedCategory'] = $category;
     $this->data['seo'] = $this->seo($category);
     return View::make('index')->with($this->data);
 }
Example #26
0
 public function getLike($slug)
 {
     $json_data = array('liked' => false);
     $product = Product::where('slug', '=', $slug)->first();
     $user = Auth::user();
     $like = Like::where('product_id', '=', $product->id)->where('user_id', '=', $user->id)->first();
     if (empty($like)) {
         $new_like = new Like();
         $new_like->product_id = $product->id;
         $new_like->user_id = $user->id;
         $new_like->save();
         $json_data['liked'] = true;
     }
     if (Request::ajax()) {
         return Response::json($json_data);
     }
     return Redirect::back();
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index($workshop_year = NULL)
 {
     $current_workshop_year = (int) Config::get('workshop.current_workshop_year');
     if ($workshop_year < 2008 || $workshop_year > $current_workshop_year) {
         $workshop_year = $current_workshop_year;
     }
     // If this is an AJAX request from the workshop year drop-down
     // on the product page, then refresh the display using the new
     // year passed in.
     if (Input::get('ajax') == 1) {
         return Redirect::route('products.index', array('workshop_year' => $workshop_year));
     }
     // Get products for the specified workshop year.
     $query = Product::where('workshop_year', '=', $workshop_year);
     $query->orderBy('workshop_year', 'DESC')->orderBy('id', 'ASC');
     $results = $query->remember(5)->get();
     Log::info('ProductsController@index - Count of query results: ' . $results->count(), array($results));
     ProductsController::makeIndexView($results, array('workshop_year_selected' => $workshop_year));
 }
 public function index()
 {
     $query = e(Input::get('q', ''));
     if (!$query && $query == '') {
         return Response::json(array(), 400);
     }
     $products = Product::where('published', true)->where('name', 'like', '%' . $query . '%')->orderBy('name', 'asc')->take(5)->get(array('slug', 'name', 'icon'))->toArray();
     $categories = Category::where('name', 'like', '%' . $query . '%')->has('products')->take(5)->get(array('slug', 'name'))->toArray();
     // Data normalization
     $categories = $this->appendValue($categories, url('img/icons/category-icon.png'), 'icon');
     $products = $this->appendURL($products, 'products');
     $categories = $this->appendURL($categories, 'categories');
     // Add type of data to each item of each set of results
     $products = $this->appendValue($products, 'product', 'class');
     $categories = $this->appendValue($categories, 'category', 'class');
     // Merge all data into one array
     $data = array_merge($products, $categories);
     return Response::json(array('data' => $data));
 }
 public function update()
 {
     $p_id = Input::get('p_id');
     $metal = Input::get('Metal');
     $supplier = Input::get('supplier');
     $grade_a = Input::get('grade_a');
     $grade_b = Input::get('grade_b');
     $shape = Input::get('shape');
     $size_a = Input::get('size_a');
     $size_b = Input::get('size_b');
     $size_c = Input::get('size_c');
     $thickness = Input::get('thickness');
     $volume = Input::get('volume');
     $bynumber = Input::get('bynumber');
     $perday = Input::get('perday');
     $defaultmetal = Product::where('p_id', $p_id)->first();
     DB::table('products')->where('p_id', $p_id)->update(array('metal' => $metal, 'supplier' => $supplier, 'grade_a' => $grade_a, 'grade_b' => $grade_b, 'shape' => $shape, 'size_a' => $size_a, 'size_b' => $size_b, 'size_c' => $size_c, 'thickness' => $thickness, 'volume' => $volume, 'bynumber' => $bynumber, 'perday' => $perday));
     return Redirect::to('/list');
 }
Example #30
0
 public static function updatePrice($sku = null, $price = null)
 {
     if (!is_null($sku)) {
         $product = Product::where('sku', $sku)->find_one();
         if ($product) {
             if ($product->price != $price) {
                 $product->price = $price;
                 if ($product->status == 0) {
                     $product->status = 1;
                 }
                 $product->save();
                 //self::$debug['messages']->info($product->sku . ' : ' . $price);
             }
         } else {
             self::$debug['messages']->warning($sku);
         }
         return true;
     }
     return false;
 }