function productDetailFront(Request $request, $slug, $id) { $product = Product::with(['subcategory', 'files', 'providers.user'])->find($id); $questions = $this->reloadQuestions($id); $featuresTranslate = $this->setFeaturesTranslate($product); $offer = false; return view('front.productDetail', compact('questions', 'product', 'featuresTranslate', 'offer')); /* Versión anterior al cambio de productos con muchos proveedores*/ $product = Product::find($id); if ($product->isActive && $product->isValidate || $request->ajax()) { $offer = ($offerModel = $product->offers()->first()) ? Carbon::now()->between(new Carbon($offerModel->offer_on), new Carbon($offerModel->offer_off)) ? $offerModel->offer_price : null : null; //$description = $offerModel->offer_description; $questions = $this->reloadQuestions($id); $featuresTranslate = $this->setFeaturesTranslate($product); return view('front.productDetail', compact('questions', 'product', 'featuresTranslate', 'offer', 'description')); } return redirect()->route('home'); }
function showUser($id) { $user = User::find($id); $products = Product::where('user_id', $id)->get(); $provider = Provider::where('user_id', $id)->first(); return view('back.user', compact('user', 'products', 'provider')); }
function searchBar(Request $request) { $value = $request->value; return ['products' => Product::has('providers')->with(['files'])->where("name", "like", "%{$value}%")->where("active", 1)->limit(10)->get()]; }
echo '<table> <thead> <tr> <th>Nombre</th> <th>Descripcion</th> <th>Precio</th> </tr> </thead> <tbody> '; foreach ($products as $product) { echo "<tr>\n <td>\n {$product->name}\n </td>\n <td>\n {$product->description}\n </td>\n <td>\n {$product->price}\n </td>\n </tr>"; } echo '</tbody></table>'; Product::reindex(); $product = Product::search($request->name); dd($product); return redirect()->route('elasticIndex', compact('product')); }]); Route::get('t', ['as' => 'elasticSearcht', 'uses' => function (Request $request) { if (function_exists('apache_request_headers')) { $headers = apache_request_headers(); } else { $headers = $_SERVER; } //Get the forwarded IP if it exists if (array_key_exists('X-Forwarded-For', $headers) && filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { $the_ip = $headers['X-Forwarded-For']; } elseif (array_key_exists('HTTP_X_FORWARDED_FOR', $headers) && filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { $the_ip = $headers['HTTP_X_FORWARDED_FOR']; } else {
function viewProduct($id) { $product = Product::findOrFail($id); $productAdmin = new \Agrosellers\Http\Controllers\ProductController(); $featuresTranslate = $productAdmin->setFeaturesTranslate($product); return view('back.productDetail', compact('product', 'featuresTranslate')); }
/** * @param $name Name subcategories * @return \Illuminate\Database\Eloquent\Collection|static[] */ function index($name) { if (!$name) { return Product::whereHas('providers', function ($query) { $query->where('isActive', 1); })->with(['subcategory', 'files'])->whereRaw('active = 1 ')->get(); } return Product::where('active', 1)->whereHas('providers', function ($query) { $query->where('isActive', 1); })->with(['files', 'subcategory' => function ($sql) use($name) { $sql->where('slug', $name); }])->whereHas('subcategory', function ($sql) use($name) { $sql->where('slug', $name); })->get(); /* Esto es temoporal focus group */ if (empty($request->get('subcategory'))) { return ProductProvider::all(); return ProductProvider::with(['offers', 'product'])->where('id', '>', 0)->get(); } return ProductProvider::all(); $sqlAdd = $request->get('subcategory') ? ' subcategory_id = ' . $request->get('subcategory') : ''; return ProductProvider::with(['offers', 'product'])->whereRaw($sqlAdd)->get(); /* Esto es temoporal focus group */ $sqlAdd = $request->get('subcategory') ? ' and subcategory_id = ' . $request->get('subcategory') : ''; $products = Product::whereRaw('isValidate = 1 and isActive = 1' . $sqlAdd)->with(['offers', 'productFiles', 'subcategory'])->get(); $lat = '-75.58121155000003'; $lng = '6.244207994244943'; $position = $request->get('position')['coords']; if ($position) { $lat = $position['longitude']; $lng = $position['latitude']; } foreach ($products as $product) { $product->location2 = explode(';', $product->location); $product->distance = $this->distance($lat, $lng, $product->location2); } $sorted = $products->sortBy(function ($p, $key) { $m[-1][-1] = -1; $m[-1][0] = 0; $m[-1][1] = 1; $m[0][-1] = 0; $m[0][0] = 0; $m[0][1] = 1; $m[1][-1] = 0; $m[1][0] = 0; $m[1][1] = 1; return $m[$this->distancePriority($p['distance'])][$this->farms($p['farms'])]; }); /*$sorted = $products->sortBy(function ($p, $key) { return $this->distancePriority($p['distance']); });*/ /* foreach($sorted as $p){ echo 'Producto: ';print_r($p->id);echo '<br>'; echo "     nombre: ";print_r($p->name);echo '<br>'; echo "     cordenadas: ";print_r($p->location);echo '<br>'; echo "     cordenadas 2: ";print_r($p->location2);echo '<br>'; echo "     distancia: ";print_r($p->distance );echo '<br>'; } dd();*/ return $sorted->slice(1, 36); }