public function getProductsByCategoryKey($categoryKey = '', $limit = 0)
 {
     $productCategory = ProductCategory::where('key', $categoryKey)->first();
     if (isset($productCategory) && !is_null($productCategory)) {
         if ($limit == 0) {
             return $productCategory->products()->where('is_publish', 1)->orderBy('priority')->orderBy('created_at', 'desc')->get();
         } else {
             return $productCategory->products()->where('is_publish', 1)->orderBy('priority')->orderBy('created_at', 'desc')->take($limit)->get();
         }
     }
     return [];
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $product = Product::find($id);
     if (!$product) {
         $product = Product::where('alias', $id)->first();
     }
     if ($product) {
         $unit = Unit::find($product->unit_id);
         $category = ProductCategory::find($product->product_category_id);
         return view('product', ['categories' => $this->categories, 'selectedCategory' => $category, 'product' => $product, 'unit' => $unit, 'title' => LANG . '_title', 'description' => LANG . '_description', 'tech_description' => LANG . '_tech_description', 'text' => LANG . '_text', 'color' => LANG . '_color', 'unit_title' => LANG . '_unit', 'file' => LANG . '_file', 'seo_title' => LANG . '_seo_title', 'seo_description' => LANG . '_seo_description', 'seo_keywords' => LANG . '_seo_keywords']);
     }
     return redirect('catalog');
 }
Beispiel #3
0
 public function query()
 {
     $input = Input::all();
     $response = array();
     $response['product'] = Product::where('name', 'like', $input['query'] . '%')->orderBy('name')->first();
     $response['supplier'] = Supplier::find($response['product']->supplier_id);
     $response['category'] = ProductCategory::find($response['product']->product_category_id);
     $response['boxes'] = Box::where('product_id', $response['product']->id)->get();
     $response['stocks'] = array();
     foreach ($response['boxes'] as $box) {
         $stock = Box::countStock($box->id);
         array_push($response['stocks'], $stock);
     }
     return $response;
 }
 public function __construct(Request $request)
 {
     $segments = $request->segments();
     $locales = LaravelLocalization::getSupportedLanguagesKeys();
     $non_locale_route = '';
     $lang = App::getLocale();
     foreach ($segments as $segment) {
         if (!in_array($segment, $locales)) {
             $non_locale_route .= '/' . $segment;
         }
     }
     DEFINED('NON_LOCALE_ROUTE') or DEFINE('NON_LOCALE_ROUTE', trim($non_locale_route, '/'));
     DEFINED('LANG') or DEFINE('LANG', $lang);
     $categories[1] = ProductCategory::getByBrand(5);
     $categories[2] = ProductCategory::getByBrand(6);
     $categories[3] = ProductCategory::getByBrand(7);
     $this->categories = $categories;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $object = Model::find($id);
     if ($object) {
         if ($object->img && file_exists(public_path() . DS . 'uploads' . DS . 'product-category' . DS . $object->img)) {
             unlink(public_path() . DS . 'uploads' . DS . 'product-category' . DS . $object->img);
         }
         if ($object->desc_img && file_exists(public_path() . DS . 'uploads' . DS . 'product-category' . DS . $object->desc_img)) {
             unlink(public_path() . DS . 'uploads' . DS . 'product-category' . DS . $object->desc_img);
         }
         $object->delete();
     }
     return redirect('admin/product-categories');
 }
 public function fetchAllActive()
 {
     return ProductCategory::where(['is_active' => '1'])->orderBy('name', 'asc')->get();
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     ProductCategory::findOrFail($id)->delete();
     return Redirect::action('ProductCategoryController@index');
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $filepath = 'data_upload/product_upload/' . $this->product_upload->id . '/' . $this->product_upload->filename;
     $contents = Storage::get($filepath);
     $modelnames = ['Product', 'ProductCategory', 'ProductCollection', 'ProductVariant', 'ProductColor', 'ProductMaterial'];
     $checked = array();
     $ok = false;
     foreach ($modelnames as $modelname) {
         $checked[$modelname] = [];
     }
     $success = 0;
     $message = '';
     $lines = explode("\n", $contents);
     //debug('Lines: '.count($lines));
     $first_line_ok = true;
     $products_saved = 0;
     if (count($lines) < 2) {
         $message = trans('data_upload.line_count_too_low');
     } else {
         foreach ($lines as $n => $line) {
             $line = trim(utf8_encode($line));
             $fields = explode(';', $line);
             if ($n == 0) {
                 if (count($fields) != config('data_upload.products.count_fields')) {
                     $message = trans('data_upload.column_count_not_matching');
                     $first_line_ok = false;
                 }
             } else {
                 if ($first_line_ok) {
                     if (count($fields) == config('data_upload.products.count_fields')) {
                         $ok = true;
                         $german_product_category = TextHelp::unQuote($fields[5]);
                         $english_product_category = TextHelp::unQuote($fields[6]);
                         $slug = trim(strtolower(str_slug($english_product_category)));
                         if (strlen($slug) > 2) {
                             $german_slug = strtolower(str_slug($german_product_category));
                             $product_category_id = 0;
                             $dontsave_cat = false;
                             if (array_key_exists($slug, $checked['ProductCategory'])) {
                                 $product_category_id = $checked['ProductCategory'][$slug];
                                 $dontsave_cat = true;
                             } else {
                                 $product_category_translation = ProductCategoryTranslation::where('slug', $slug)->first();
                                 if ($product_category_translation) {
                                     $product_category_id = $product_category_translation->product_category_id;
                                 }
                             }
                             if (!$product_category_id) {
                                 $product_category = ProductCategory::create();
                                 $product_category_id = $product_category->id;
                             } else {
                                 $product_category = ProductCategory::find($product_category_id);
                             }
                             if (!$dontsave_cat) {
                                 $product_category->translateOrNew('de')->slug = $german_slug;
                                 $product_category->translateOrNew('de')->name = $german_product_category;
                                 $product_category->translateOrNew('en')->slug = $slug;
                                 $product_category->translateOrNew('en')->name = $english_product_category;
                                 $product_category->save();
                             }
                             if (!array_key_exists($slug, $checked['ProductCategory'])) {
                                 $checked['ProductCategory'][$slug] = $product_category_id;
                             }
                             $product_collection_name = TextHelp::unQuote($fields[1]);
                             $slug = strtolower(str_slug($product_collection_name));
                             $german_text = TextHelp::unQuote($fields[7]);
                             $english_text = TextHelp::unQuote($fields[8]);
                             $german_short_text = TextHelp::unQuote($fields[9]);
                             $english_short_text = TextHelp::unQuote($fields[10]);
                             $product_collection_id = 0;
                             $dontsave_col = false;
                             if (array_key_exists($slug . '_' . $product_category_id, $checked['ProductCollection'])) {
                                 $product_collection_id = $checked['ProductCollection'][$slug . '_' . $product_category_id];
                                 $dontsave_col = true;
                             } else {
                                 $product_collection = ProductCollection::whereSlug($slug)->first();
                                 if ($product_collection) {
                                     $product_collection_id = $product_collection->id;
                                 }
                             }
                             if (!$product_collection_id) {
                                 $product_collection = ProductCollection::create(['product_category_id' => $product_category_id]);
                                 $product_collection_id = $product_collection->id;
                             } else {
                                 $product_collection = ProductCollection::find($product_collection_id);
                             }
                             if (!$dontsave_col) {
                                 $product_collection->slug = $slug;
                                 $product_collection->translateOrNew('de')->name = $product_collection_name;
                                 $product_collection->translateOrNew('de')->description = $german_text;
                                 $product_collection->translateOrNew('de')->teaser_text = $german_short_text;
                                 $product_collection->translateOrNew('en')->name = $product_collection_name;
                                 $product_collection->translateOrNew('en')->description = $english_text;
                                 $product_collection->translateOrNew('en')->teaser_text = $english_short_text;
                                 $product_collection->save();
                             }
                             if (!array_key_exists($slug . '_' . $product_category_id, $checked['ProductCollection'])) {
                                 $checked['ProductCollection'][$slug . '_' . $product_category_id] = $product_collection_id;
                             }
                             $product_collection_images = ProductCollectionImage::whereProductCollectionSlug($slug)->get();
                             if ($product_collection_images) {
                                 foreach ($product_collection_images as $product_collection_image) {
                                     $product_collection_image->product_collection_id = $product_collection_id;
                                     $product_collection_image->save();
                                 }
                             }
                             $product_variant_name = TextHelp::unQuote($fields[2]);
                             $slug = strtolower(str_slug($product_variant_name));
                             $dimensions = TextHelp::cleanFilemakerImport(TextHelp::unQuote($fields[13]));
                             $german_text = TextHelp::cleanFilemakerImport(TextHelp::unQuote($fields[11]));
                             $english_text = TextHelp::cleanFilemakerImport(TextHelp::unQuote($fields[12]));
                             $german_features = TextHelp::cleanFilemakerImport(TextHelp::unQuote($fields[14]));
                             $english_features = TextHelp::cleanFilemakerImport(TextHelp::unQuote($fields[15]));
                             $design_number = TextHelp::unQuote($fields[19]);
                             if ($design_number) {
                                 //$design_number = substr($design_number, 0, strlen($design_number)-1);
                                 //$design_number = trim($design_number);
                             }
                             $product_variant_id = 0;
                             $dontsave_var = false;
                             if (array_key_exists($slug . '_' . $product_collection_id, $checked['ProductVariant'])) {
                                 $product_variant_id = $checked['ProductVariant'][$slug . '_' . $product_collection_id];
                                 $dontsave_var = true;
                             } else {
                                 $product_variant = ProductVariant::whereSlug($slug)->first();
                                 if ($product_variant) {
                                     $product_variant_id = $product_variant->id;
                                 }
                             }
                             if (!$product_variant_id) {
                                 $product_variant = ProductVariant::create(['product_collection_id' => $product_collection_id]);
                                 $product_variant_id = $product_variant->id;
                             } else {
                                 $product_variant = ProductVariant::find($product_variant_id);
                             }
                             if (!$dontsave_var) {
                                 $product_variant->design_number = $design_number;
                                 $product_variant->dimensions = $dimensions;
                                 $product_variant->slug = $slug;
                                 $product_variant->translateOrNew('de')->name = $product_variant_name;
                                 $product_variant->translateOrNew('de')->description = $german_text;
                                 $product_variant->translateOrNew('de')->features = $german_features;
                                 $product_variant->translateOrNew('en')->name = $product_variant_name;
                                 $product_variant->translateOrNew('en')->description = $english_text;
                                 $product_variant->translateOrNew('en')->features = $english_features;
                                 $product_variant->save();
                             }
                             if (!array_key_exists($slug . '_' . $product_collection_id, $checked['ProductVariant'])) {
                                 $checked['ProductVariant'][$slug . '_' . $product_collection_id] = $product_variant_id;
                             }
                             $product_variant_images = ProductVariantImage::whereProductVariantSlug($slug)->get();
                             if ($product_variant_images) {
                                 foreach ($product_variant_images as $product_variant_image) {
                                     $product_variant_image->product_variant_id = $product_variant_id;
                                     $product_variant_image->save();
                                 }
                             }
                             $product_color_name = TextHelp::unQuote($fields[3]);
                             $slug = strtolower(str_slug($product_color_name));
                             $product_color_id = 0;
                             $dontsave_color = false;
                             if ($slug) {
                                 if (array_key_exists($slug, $checked['ProductColor'])) {
                                     $product_color_id = $checked['ProductColor'][$slug];
                                     $dontsave_color = true;
                                 } else {
                                     $product_color = ProductColor::where('slug', $slug)->first();
                                     if ($product_color) {
                                         $product_color_id = $product_color->id;
                                     }
                                 }
                                 if (!$product_color_id) {
                                     $product_color = ProductColor::create(['slug' => $slug]);
                                     $product_color_id = $product_color->id;
                                 } else {
                                     $product_color = ProductColor::find($product_color_id);
                                 }
                                 if (!$dontsave_color) {
                                     $product_color->slug = $slug;
                                     $product_color->translateOrNew('en')->name = $product_color_name;
                                     $product_color->translateOrNew('de')->name = $product_color_name;
                                     $product_color->save();
                                 }
                                 if (!array_key_exists($slug, $checked['ProductColor'])) {
                                     $checked['ProductColor'][$slug] = $product_color_id;
                                 }
                             }
                             $english_name = TextHelp::unQuote($fields[17]);
                             $german_name = TextHelp::unQuote($fields[16]);
                             $slug = strtolower(str_slug($english_name));
                             $product_material_id = 0;
                             $dontsave_mat = false;
                             if ($slug) {
                                 if (array_key_exists($slug, $checked['ProductMaterial'])) {
                                     $product_material_id = $checked['ProductMaterial'][$slug];
                                     $dontsave_mat = true;
                                 } else {
                                     $product_material_translation = ProductMaterialTranslation::where('name', $english_name)->first();
                                     if ($product_material_translation) {
                                         $product_material_id = $product_material_translation->product_material_id;
                                     }
                                 }
                                 if (!$product_material_id) {
                                     $product_material = ProductMaterial::create();
                                     $product_material_id = $product_material->id;
                                 } else {
                                     $product_material = ProductMaterial::find($product_material_id);
                                 }
                                 if (!$dontsave_mat) {
                                     $product_material->translateOrNew('en')->name = $english_name;
                                     $product_material->translateOrNew('de')->name = $german_name;
                                     $product_material->save();
                                 }
                                 if (!array_key_exists($slug, $checked['ProductMaterial'])) {
                                     $checked['ProductMaterial'][$slug] = $product_material_id;
                                 }
                             }
                             $product_number = strtolower(str_slug(TextHelp::unQuote($fields[0])));
                             $price_brut = floatval(str_replace(',', '.', TextHelp::unQuote($fields[4])));
                             $merchant_price = floatval(str_replace(',', '.', TextHelp::unQuote($fields[21])));
                             $merchant_percentage = floatval(str_replace(',', '.', TextHelp::unQuote($fields[22])));
                             $available = intval(TextHelp::unQuote($fields[18]));
                             $slug = $product_number;
                             $product_id = 0;
                             if (array_key_exists($slug, $checked['Product'])) {
                                 $product_id = $checked['Product'][$slug];
                             } else {
                                 $product = Product::where('product_number', $product_number)->first();
                                 if ($product) {
                                     $product_id = $product->id;
                                 }
                             }
                             if (!$product_id) {
                                 $product = Product::create(['product_variant_id' => $product_variant_id, 'product_color_id' => $product_color_id, 'product_material_id' => $product_material_id, 'product_number' => $product_number]);
                                 $product_id = $product->id;
                             } else {
                                 $product = Product::find($product_id);
                             }
                             $product->product_variant_id = $product_variant_id;
                             $product->product_color_id = $product_color_id;
                             $product->product_material_id = $product_material_id;
                             $product->product_number = $product_number;
                             $product->price_brut = $price_brut * 100;
                             $product->merchant_price = $merchant_price * 100;
                             $product->merchant_percentage = $merchant_percentage;
                             $product->available = $available;
                             $product->save();
                             $product_images = ProductImage::whereProductNumber($product_number)->get();
                             if ($product_images) {
                                 foreach ($product_images as $product_image) {
                                     $product_image->product_id = $product_id;
                                     $product_image->save();
                                 }
                             }
                             $product_top_images = ProductTopImage::whereProductNumber($product_number)->get();
                             if ($product_top_images) {
                                 foreach ($product_top_images as $product_top_image) {
                                     $product_top_image->product_id = $product_id;
                                     $product_top_image->save();
                                 }
                             }
                             $success = 1;
                             $products_saved++;
                             if (!array_key_exists($slug, $checked['Product'])) {
                                 $checked['Product'][$slug] = $product_id;
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($success) {
         $product_categories = ProductCategory::all();
         foreach ($product_categories as $product_category) {
             foreach ($product_category->product_collections as $product_collection) {
                 foreach ($product_collection->product_variants as $product_variant) {
                     foreach ($product_variant->products as $product) {
                         $slug = strtolower(str_slug($product->product_number));
                         if (!array_key_exists($slug, $checked['Product'])) {
                             $product->delete();
                         }
                     }
                     if (!array_key_exists($product_variant->translateOrNew('en')->slug . '_' . $product_collection->id, $checked['ProductVariant'])) {
                         //$product_variant->delete();
                     }
                 }
                 if (!array_key_exists($product_collection->translateOrNew('en')->slug . '_' . $product_category->id, $checked['ProductCollection'])) {
                     //$product_collection->delete();
                 }
             }
             if (!array_key_exists($product_category->translateOrNew('en')->slug, $checked['ProductCategory'])) {
                 //$product_category->delete();
             }
         }
     }
     if ($message) {
         $message .= ' ';
     }
     $message .= $products_saved . ' products saved.';
     $this->product_upload->success = $success;
     $this->product_upload->message = $message;
     $this->product_upload->save();
     $this->dispatch(new PrepareProductCsv($this->product_upload));
     $this->dispatch(new SendProductUploadNotification($this->product_upload));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $object = Model::find($id);
     if ($object) {
         if ($object->img && file_exists(public_path() . DS . 'uploads' . DS . 'product' . DS . $object->img)) {
             unlink(public_path() . DS . 'uploads' . DS . 'product' . DS . $object->img);
         }
         if ($object->slider_img && file_exists(public_path() . DS . 'uploads' . DS . 'product' . DS . $object->slider_img)) {
             unlink(public_path() . DS . 'uploads' . DS . 'product' . DS . $object->slider_img);
         }
         if ($object->ru_file && file_exists(public_path() . DS . 'uploads' . DS . 'product' . DS . 'pdfs' . DS . $object->ru_file)) {
             unlink(public_path() . DS . 'uploads' . DS . 'product' . DS . 'pdfs' . DS . $object->ru_file);
         }
         if ($object->en_file && file_exists(public_path() . DS . 'uploads' . DS . 'product' . DS . 'pdfs' . DS . $object->en_file)) {
             unlink(public_path() . DS . 'uploads' . DS . 'product' . DS . 'pdfs' . DS . $object->en_file);
         }
         if ($object->ua_file && file_exists(public_path() . DS . 'uploads' . DS . 'product' . DS . 'pdfs' . DS . $object->ua_file)) {
             unlink(public_path() . DS . 'uploads' . DS . 'product' . DS . 'pdfs' . DS . $object->ua_file);
         }
         $object->delete();
         $category = ProductCategory::find($id);
         $category->count = DB::table('products')->where('product_category_id', '=', $id)->where('deleted_at', '=', NULL)->count();
         $category->save();
         if ($request->ajax()) {
             return $this->responseAnswer(false, null, null, trans('product.delProduct'));
         } else {
             return redirect()->back();
         }
     }
     if ($request->ajax()) {
         return $this->responseAnswer(false, null, null, trans('product.bad_product'));
     } else {
         return redirect()->back();
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $categories = \App\ProductCategory::all();
     $product = \App\Product::where('id', $id)->with('inventories', 'prices')->first();
     return view('productmanager.show', compact('product', 'categories'));
 }
Beispiel #11
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show(Product $product)
 {
     $product_categories = ProductCategory::all();
     $suppliers = Supplier::all();
     $id = $product->id;
     $previous = Product::where('id', '<', $id)->max('id');
     $next = Product::where('id', '>', $id)->min('id');
     return view('product.show', compact(['product', 'next', 'previous']))->with('product_categories', $product_categories)->with('suppliers', $suppliers);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     DB::transaction(function () use($id) {
         $user = Auth::user();
         $productCategory = ProductCategory::findOrFail($id);
         $productCategory->updated_by = $user->name;
         $productCategory->deleted_by = $user->name;
         $productCategory->key = $productCategory->key . '-' . microtime(true);
         $productCategory->save();
         // soft delete
         $productCategory->delete();
     });
 }