Example #1
0
 public static function boot()
 {
     parent::boot();
     Product::deleting(function ($product) {
         File::delete($product->image);
     });
 }
 public function updateCatalogOrderItems()
 {
     $data = Input::get('data');
     foreach ($data as $dataItem) {
         $productLine = null;
         if ($dataItem['type'] == 'Priola\\ProductLine') {
             $itemToSave = ProductLine::findOrFail($dataItem['id']);
         } else {
             $itemToSave = Product::findOrFail($dataItem['id']);
         }
         $itemToSave->catalog_order = $dataItem['order'];
         $itemToSave->save();
     }
     return response("ok");
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $productList = Product::lists('title', 'id');
     return View('admin.masterClasses.edit', ['productList' => $productList, 'masterClass' => MasterClass::find($id)]);
 }
 public function import(Request $request)
 {
     $filePath = Session::pull('dataTransferResult.FilesPath');
     $createdProductCategories = [];
     $createdProductLines = [];
     Excel::selectSheets('Категории')->load($filePath . '/products.xlsx', function ($reader) use($filePath, $createdProductCategories, $createdProductLines) {
         foreach ($reader->toArray() as $row) {
             if ($row['nomer'] == null) {
                 continue;
             }
             $productCategory = ProductCategory::findOrNew($row['nomer']);
             if ($row['nomer'] > ProductCategory::max('id')) {
                 $imagePattern = '/img/product-category-' . $row['nomer'];
                 $findResults = File::glob($filePath . $imagePattern . '*');
                 $imageOriginalPath = $findResults[0];
                 $imageExt = File::extension($imageOriginalPath);
                 $imagePath = $filePath . $imagePattern . '.' . $imageExt;
                 $newImagePath = 'img/uploads/' . str_random(32) . '.' . $imageExt;
                 File::move($imagePath, public_path() . '/' . $newImagePath);
                 $productCategory->id = $row['nomer'];
                 $productCategory->title = $row['nazvanie'];
                 $productCategory->image = $newImagePath;
                 $createdProductCategories[$row['nomer']] = $productCategory;
                 $productCategory->save();
             }
         }
         Excel::selectSheets('Линейки продукции')->load($filePath . '/products.xlsx', function ($reader) use($filePath, $createdProductCategories, $createdProductLines) {
             foreach ($reader->toArray() as $row) {
                 if ($row['nomer'] == null) {
                     continue;
                 }
                 if ($row['nomer'] > ProductLine::max('id')) {
                     $imagePattern = '/img/product-line-' . $row['nomer'];
                     $findResults = File::glob($filePath . $imagePattern . '*');
                     $imageOriginalPath = $findResults[0];
                     $imageExt = File::extension($imageOriginalPath);
                     $imagePath = $filePath . $imagePattern . '.' . $imageExt;
                     $newImagePath = 'img/uploads/' . str_random(32) . '.' . $imageExt;
                     File::move($imagePath, public_path() . '/' . $newImagePath);
                     $createdProductLines[$row['nomer']] = ProductLine::create(['id' => $row['nomer'], 'product_category_id' => $row['kategoriya'], 'title' => $row['nazvanie'], 'image' => $newImagePath]);
                 }
             }
             Excel::selectSheets('Продукция')->load($filePath . '/products.xlsx', function ($reader) use($filePath, $createdProductCategories, $createdProductLines) {
                 foreach ($reader->toArray() as $row) {
                     if ($row['nomer'] == null) {
                         continue;
                     }
                     $imagePattern = '/img/product-' . $row['nomer'];
                     $findResults = File::glob($filePath . $imagePattern . '*');
                     $imageOriginalPath = $findResults[0];
                     $imageExt = File::extension($imageOriginalPath);
                     $imagePath = $filePath . $imagePattern . '.' . $imageExt;
                     $newImagePath = 'img/uploads/' . str_random(32) . '.' . $imageExt;
                     File::move($imagePath, public_path() . '/' . $newImagePath);
                     $productCategoryId = $row['kategoriya'] == null ? null : $row['kategoriya'];
                     $productLineId = $row['lineyka_produktsii'] == null ? null : $row['lineyka_produktsii'];
                     $product = new Product(['title' => $row['nazvanie'], 'image' => $newImagePath, 'rating' => $row['reyting']]);
                     if ($productCategoryId != null) {
                         if (array_key_exists(intval($row['kategoriya']), $createdProductCategories)) {
                             $product->productCategory()->associate($createdProductCategories[$row['kategoriya']]);
                         } else {
                             $product->productCategory()->associate(ProductCategory::find($productCategoryId));
                         }
                     }
                     if ($productLineId != null) {
                         if (array_key_exists(intval($row['lineyka_produktsii']), $createdProductLines)) {
                             $product->productLine()->associate($createdProductLines[$row['lineyka_produktsii']]);
                         } else {
                             $product->productLine()->associate(ProductLine::find([$row['lineyka_produktsii']]));
                         }
                     }
                     $product->save();
                     $imagePattern = '/img/product-' . $row['nomer'] . '-color-';
                     $findResults = File::glob($filePath . $imagePattern . '*');
                     foreach ($findResults as $findResult) {
                         $newImagePath = 'img/uploads/' . str_random(32) . '.' . $imageExt;
                         $colorCode = substr($findResult, strpos($findResult, 'color') + 6, strpos($findResult, '.') - strpos($findResult, 'color') - 6);
                         File::move($findResult, public_path() . '/' . $newImagePath);
                         $productColor = new ProductColor(['image' => $newImagePath]);
                         $colorNumber = substr($findResult, strpos($findResult, 'color') + 6, strpos($findResult, '.') - strpos($findResult, 'color') - 6);
                         $imagePattern = '/img/product-' . $row['nomer'] . '-image-' . $colorNumber;
                         $findProductColorImageResults = File::glob($filePath . $imagePattern . '*');
                         $productImagePath = '';
                         if (count($findProductColorImageResults) != 0) {
                             $imageOriginalPath = $findProductColorImageResults[0];
                             $productImagePath = 'img/uploads/' . str_random(32) . '.' . $imageExt;
                             File::move($imageOriginalPath, public_path() . '/' . $productImagePath);
                         }
                         $productColor->product_image = $productImagePath;
                         $productColor->product_id = $product->id;
                         $productColor->code = $colorCode;
                         $product->productColors()->save($productColor);
                     }
                 }
                 File::cleanDirectory(public_path() . '/resources/uploads/');
             });
         });
     });
     return redirect()->route('admin.dataTransfer.index');
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $productList = Product::lists('title', 'id');
     $reviewTagList = ReviewTag::lists('text', 'text');
     return View('admin.productReviews.edit', ['productList' => $productList, 'reviewTagList' => $reviewTagList, 'productReview' => ProductReview::find($id)]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function mainProductGallery()
 {
     return View('admin.productGalleries.main', ['productGallery' => ProductGallery::whereNull('product_category_id')->whereNull('product_line_id')->whereNull('product_id')->first(), 'productList' => Product::lists('title', 'id')]);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Product::destroy($id);
     return redirect('/admin/products');
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $reviewTagList = ReviewTag::lists('text', 'text');
     return View('admin.reviews.edit', ['productList' => Product::all()->lists('title', 'id'), 'productLineList' => ProductLine::all()->lists('title', 'id'), 'regionTechnologyList' => RegionTechnology::all()->lists('username', 'id'), 'reviewTagList' => $reviewTagList, 'productReview' => Review::find($id)]);
 }
 public function search()
 {
     $searchResults = new \Illuminate\Database\Eloquent\Collection();
     $string = Input::get('string');
     $productCategories = ProductCategory::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get();
     foreach ($productCategories as $productCategory) {
         $body = strip_tags($productCategory->description);
         if (strlen($body) > 100) {
             $body = substr($body, 0, 100);
         }
         $searchResult = new SearchResult(['title' => $productCategory->title, 'body' => $body, 'link' => '/catalog/' . $productCategory->id]);
         $searchResults->push($searchResult);
     }
     $productLines = ProductLine::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get();
     foreach ($productLines as $productLine) {
         $body = strip_tags($productLine->description);
         if (strlen($body) > 100) {
             $body = substr($body, 0, 100);
         }
         $searchResult = new SearchResult(['title' => $productLine->title, 'body' => $body, 'link' => '/productLine/' . $productLine->id]);
         $searchResults->push($searchResult);
     }
     $products = Product::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get();
     foreach ($products as $product) {
         $body = strip_tags($product->description);
         if (strlen($body) > 100) {
             $body = substr($body, 0, 100);
         }
         $searchResult = new SearchResult(['title' => $product->title, 'body' => $body, 'link' => '/product/' . $product->id]);
         $searchResults->push($searchResult);
     }
     $masterClasses = MasterClass::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get();
     foreach ($masterClasses as $masterClass) {
         $body = strip_tags($masterClass->description);
         if (strlen($body) > 100) {
             $body = substr($body, 0, 100);
         }
         $searchResult = new SearchResult(['title' => $masterClass->title, 'body' => $body, 'link' => '/master-class/' . $masterClass->id]);
         $searchResults->push($searchResult);
     }
     $events = Event::where('title', 'like', '%' . $string . '%')->orWhere('body', 'like', '%' . $string . '%')->get();
     foreach ($events as $event) {
         $body = strip_tags($event->description);
         if (strlen($body) > 100) {
             $body = substr($body, 0, 100);
         }
         $searchResult = new SearchResult(['title' => $event->title, 'body' => $body, 'link' => '/events/' . $event->id]);
         $searchResults->push($searchResult);
     }
     $novelties = Novelty::where('title', 'like', '%' . $string . '%')->orWhere('body', 'like', '%' . $string . '%')->get();
     foreach ($novelties as $novelty) {
         $body = strip_tags($novelty->description);
         if (strlen($body) > 100) {
             $body = mb_substr($body, 0, 100);
         }
         $searchResult = new SearchResult(['title' => $novelty->title, 'body' => $body, 'link' => '/novelties/' . $novelty->id]);
         $searchResults->push($searchResult);
     }
     $reviews = Review::where('body', 'like', '%' . $string . '%')->get()->load('regionTechnology');
     foreach ($reviews as $review) {
         $body = strip_tags($review->body);
         if (strlen($body) > 100) {
             $body = mb_substr($body, 0, 100);
         }
         $searchResult = new SearchResult(['title' => RegionTechnology::where('id', $review->region_technology_id)->first()->username, 'body' => $body, 'link' => '/reviews/' . $review->id]);
         $searchResults->push($searchResult);
     }
     $competitions = Competition::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get();
     foreach ($competitions as $competition) {
         $body = strip_tags($competition->description);
         if (strlen($body) > 100) {
             $body = substr($body, 0, 100);
         }
         $searchResult = new SearchResult(['title' => $competition->title, 'body' => $body, 'link' => '/competitions/' . $competition->id]);
         $searchResults->push($searchResult);
     }
     $courses = Course::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get();
     foreach ($courses as $course) {
         $body = strip_tags($course->description);
         if (strlen($body) > 100) {
             $body = substr($body, 0, 100);
         }
         $searchResult = new SearchResult(['title' => $course->title, 'body' => $body, 'link' => '/courses/' . $course->id]);
         $searchResults->push($searchResult);
     }
     $massMediaNews = MassMediaNews::where('title', 'like', '%' . $string . '%')->orWhere('body', 'like', '%' . $string . '%')->get();
     foreach ($massMediaNews as $massMediaNewItem) {
         $body = strip_tags($massMediaNewItem->body);
         if (strlen($body) > 100) {
             $body = substr($body, 0, 100);
         }
         $searchResult = new SearchResult(['title' => $massMediaNewItem->title, 'body' => $body, 'link' => '/mass-media-news/' . $massMediaNewItem->id]);
         $searchResults->push($searchResult);
     }
     $regionWorkshops = RegionWorkshop::where('title', 'like', '%' . $string . '%')->orWhere('description', 'like', '%' . $string . '%')->get();
     foreach ($regionWorkshops as $regionWorkshop) {
         $body = strip_tags($regionWorkshop->description);
         if (strlen($body) > 100) {
             $body = substr($body, 0, 100);
         }
         $searchResult = new SearchResult(['title' => $regionWorkshop->title, 'body' => $body, 'link' => '/regions/workshops/' . $regionWorkshop->id]);
         $searchResults->push($searchResult);
     }
     return view('home.searchResults', ['string' => $string, 'searchResults' => $searchResults]);
 }