Example #1
0
 /**
  *
  */
 public function loadFeed()
 {
     $xml = $this->reader->load($this->feedUrl);
     $content = $xml->getContent();
     $this->content = $xml->getContent();
     foreach ($content as $product) {
         $item = Product::where('externalUrl', '=', $product->productUrl)->first();
         if (!$item) {
             $item = new Product();
         }
         if (strlen($product->brand) > 1) {
             $brand = Brand::where('name', '=', $product->brand)->first();
             if (!$brand) {
                 $brand = new Brand();
                 $brand->name = $product->brand;
                 $brand->save();
             }
             if ($brand->id) {
                 $item->brand = $brand->id;
             }
         }
         $item->name = $product->name;
         $item->description = $product->description;
         $item->price = $product->price;
         $item->regularPrice = $product->regularPrice;
         $item->shippingPrice = $product->shippingPrice;
         $item->externalUrl = $product->productUrl;
         $item->imageUrl = $product->graphicUrl;
         $item->save();
     }
 }
Example #2
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit(Request $request, $id)
 {
     $brand = Brand::where('id', $id)->first();
     if ($brand && ($request->user()->id == $brand->user_id || $request->user()->is_admin())) {
         return view('brands.edit')->with('brand', $brand);
     }
     return redirect('/brand/index')->withErrors('You have not sufficient permissions');
 }
Example #3
0
 public function getBrands(Request $request)
 {
     if ($request->input('q')) {
         $search_query = $request->input('q');
         $brands = Brand::where('name', 'like', '%' . $search_query . '%')->get();
     } else {
         $brands = Brand::all();
     }
     return response()->json($brands);
 }
 public function search()
 {
     $brands_mobile = Brand::where('brand_type', 'LIKE', '%phone%')->get();
     $brands_desktop = Brand::where('brand_type', 'LIKE', '%desktop%')->get();
     $brands_laptop = Brand::where('brand_type', 'LIKE', '%laptop%')->get();
     $brands_camera = Brand::where('brand_type', 'LIKE', '%camera%')->get();
     $brands_tv = Brand::where('brand_type', 'LIKE', '%tv%')->get();
     //Search
     $keyword = Input::get('keyword');
     $products = Product::where('product_name', 'LIKE', '%' . $keyword . '%')->paginate();
     return view('webcontent/products', compact('products', 'brands_mobile', 'brands_desktop', 'brands_laptop', 'brands_camera', 'brands_tv'));
 }
 public function index()
 {
     $types = Type::all();
     //Select * from Type
     $brands_mobile = Brand::where('brand_type', 'LIKE', '%phone%')->get();
     $brands_desktop = Brand::where('brand_type', 'LIKE', '%desktop%')->get();
     $brands_laptop = Brand::where('brand_type', 'LIKE', '%laptop%')->get();
     $brands_camera = Brand::where('brand_type', 'LIKE', '%camera%')->get();
     $brands_tv = Brand::where('brand_type', 'LIKE', '%tv%')->get();
     //Sản phẩm mới
     $new_product = Product::orderBy('created_at', 'desc')->take(4)->get();
     //Sản phẩm nổi bật
     $feature_products = Product::where('is_feature', '=', 1)->take(4)->get();
     //Big sales
     $sale_products = Product::orderBy('sale_price', 'desc')->take(4)->get();
     return view('index', compact('types', 'new_product', 'feature_products', 'sale_products', 'brands_mobile', 'brands_desktop', 'brands_laptop', 'brands_camera', 'brands_tv'));
 }
Example #6
0
 /**
  * Save brand
  * 
  * @return \Illuminate\Http\JsonResponse
  */
 public function save()
 {
     $input = \Input::except('_token');
     $input['active'] = empty($input['active']) ? 0 : 1;
     // Validate
     $validator = \Validator::make($input, ['name' => 'required|max:255']);
     // When fails
     if ($validator->fails()) {
         return response()->json(['errors' => $validator->messages()]);
     }
     // Save changes
     $brand = Brand::findOrNew($input['id']);
     // Uncheck other brands default value
     if ($input['active']) {
         \DB::table('brands')->update(['active' => 0]);
     }
     $brand->fill($input);
     $brand->save();
     // Process logo image
     if ($picture = \Request::file('file-0')) {
         $filename = 'picture.' . $picture->getClientOriginalExtension();
         $picture->move(public_path($brand->getStoragePath()), $filename);
         $brand->logo = $filename;
         $brand->save();
     }
     // At least 1 brand must be active
     if (\DB::table('brands')->where('active', 1)->count() == 0) {
         $first = \DB::table('brands')->first();
         \DB::table('brands')->where('id', $first->id)->update(['active' => 1]);
     }
     try {
         // Save active css
         $active = Brand::where('active', 1)->first();
         file_put_contents($active->getCssPath(), $active->css);
         // Response
         return response()->json(['success' => 'Brand saved', 'redirect' => url('/admin/brands/list')]);
     } catch (\Exception $e) {
         // Response
         return response()->json(['success' => false, 'errors' => ['css' => ['Failed saving css']]]);
     }
 }
 public function search()
 {
     $number_of_items = Cart::content();
     $brands_mobile = Brand::where('brand_type', 'LIKE', '%phone%')->get();
     $brands_desktop = Brand::where('brand_type', 'LIKE', '%desktop%')->get();
     $brands_laptop = Brand::where('brand_type', 'LIKE', '%laptop%')->get();
     $brands_camera = Brand::where('brand_type', 'LIKE', '%camera%')->get();
     $brands_tv = Brand::where('brand_type', 'LIKE', '%tv%')->get();
     //Search
     $keyword = Input::get('keyword');
     // Nhận keyword về
     $products = Product::where('product_name', 'LIKE', '%' . $keyword . '%')->paginate();
     // Lấy những sản phẩm có tên như keyword
     $products->setPath('');
     return view('webcontent/search', compact('products', 'brands_mobile', 'brands_desktop', 'brands_laptop', 'brands_camera', 'brands_tv', 'number_of_items', 'keyword'));
 }
 public function __construct(ProductDetail $productdetail, Product $product, Brand $brand)
 {
     $this->product = $product->where('company_id', Auth::user()->company_id)->where('account_year_id', session('account'));
     $this->brand = $brand->where('company_id', Auth::user()->company_id)->where('account_year_id', session('account'));
     $this->productdetail = $productdetail->where('company_id', Auth::user()->company_id)->where('account_year_id', session('account'));
 }
Example #9
0
 public function update($id)
 {
     $input = Input::all();
     $rules = array('image' => 'image');
     $niceNames = array('image' => 'brand image');
     $validator = Validator::make($input, $rules);
     $validator->setAttributeNames($niceNames);
     if ($validator->fails()) {
         return Response::json(['success' => false, 'errors' => $validator->getMessageBag()->toArray()]);
     } else {
         $Brand = Brand::find($id);
         if (Input::has('show')) {
             $Brand->show = Input::get('show');
         }
         if (Input::has('ordering')) {
             $Brand->ordering = Input::get('ordering');
         }
         if (Input::has('status')) {
             $Brand->status = Input::get('status');
         }
         if (Input::has('title')) {
             $Brand->title = Input::get('title');
         }
         if (Input::hasfile('image')) {
             $file = Input::file('image');
             $destinationPath = 'uploads/brands/';
             $filename = $file->getClientOriginalName();
             Input::file('image')->move($destinationPath, $filename);
             $ext = substr($filename, strrpos($filename, "."));
             $newFileName = basename($filename, $ext) . "_" . $Brand->id . "_" . date("Ymdhis") . $ext;
             rename($destinationPath . $filename, $destinationPath . $newFileName);
             Brand::where('id', $Brand->id)->update(['image_path' => $destinationPath . $newFileName]);
         }
         $Brand->save();
         if (Input::hasfile('image')) {
             return Response::json(['success' => true, 'message' => 'Brand has been updated!', 'file' => asset($destinationPath . $newFileName)]);
         } else {
             return Response::json(['success' => true, 'message' => 'Brand has been updated!']);
         }
     }
 }
Example #10
0
 public function __construct(Brand $brand)
 {
     $this->brand = $brand->where('company_id', Auth::user()->company_id)->where('account_year_id', session('account'));
 }
Example #11
0
 public function getBrands(Request $request)
 {
     $query = $request->all()['q'];
     $brands = Brand::where('name', 'LIKE', '%' . $query . '%')->get();
     $brands->transform(function ($item, $key) {
         return ['id' => $item->id, 'name' => $item->name];
     });
     return $brands;
 }
Example #12
0
 /**
  * Load map layout
  * 
  * @param Map $map
  */
 public function getMap(Map $map)
 {
     $data = ['user' => \Auth::user(), 'brand' => Brand::where('active', 1)->first(), 'map' => $map];
     return view('map', $data);
 }