/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Model $objects) { $objects_for_filter = Model::all(); // dd($objects_for_filter); return view('admin.product-category.list', ['objects' => $objects->paginate(10), 'objects_for_filter' => $objects_for_filter]); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $product_categories = ProductCategory::all(); return view('productcategory.home', compact('product_categories')); }
/** * 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)); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $object = Model::find($id); if ($object) { $params = $request->only('img', 'slider_img', 'ru_slider', 'en_slider', 'ua_slider', 'product_category_id', 'unit_id', 'ru_title', 'ru_description', 'ru_file', 'ru_seo_title', 'ru_seo_keywords', 'ru_seo_description', 'en_title', 'en_description', 'en_file', 'en_seo_title', 'en_seo_keywords', 'en_seo_description', 'ua_title', 'ua_description', 'ua_file', 'ua_seo_title', 'ua_seo_keywords', 'ua_seo_description'); $filter = $object->validator($params, ['ru_title' => 'required|min:2|max:150|unique:products,ru_title,' . $id, 'en_title' => 'required|min:2|max:150|unique:products,en_title,' . $id, 'ua_title' => 'required|min:2|max:150|unique:products,ua_title,' . $id]); if ($filter->fails()) { if ($request->ajax()) { return $this->responseAnswer(true, $params, $filter->errors()); } else { $error = $filter->errors()->toArray(); $params['id'] = $id; $params['img'] = $object->img; $categories = ProductCategory::all(); $units = Unit::all(); $options = $object->options(); return view('admin.product.edit', ['input' => $params, 'error' => $error, 'categories' => $categories, 'units' => $units, 'options' => $options]); } } if ($request->hasFile('img')) { $params['img'] = $this->upload('img'); if ($object->img && file_exists(public_path() . DS . 'uploads' . DS . 'product' . DS . $object->img)) { unlink(public_path() . DS . 'uploads' . DS . 'product' . DS . $object->img); } } else { unset($params['img']); } if ($request->hasFile('slider_img')) { $params['slider_img'] = $this->upload('slider_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); } } else { unset($params['slider_img']); } if ($request->hasFile('ru_file')) { $params['ru_file'] = $this->uploadPdf('ru_file'); 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); } } else { unset($params['ru_file']); } if ($request->hasFile('en_file')) { $params['en_file'] = $this->uploadPdf('en_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); } } else { unset($params['en_file']); } if ($request->hasFile('ua_file')) { $params['ua_file'] = $this->uploadPdf('ua_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); } } else { unset($params['ua_file']); } $params['on_top'] = $request->has('on_top'); $params['alias'] = $this->makeAlias($params['ru_title']); $object->fill($params); $object->save(); if ($request->ajax()) { return $this->responseAnswer(false, $object); } else { $categories = ProductCategory::all(); return redirect('admin/product/' . $object->id . '/edit'); } } if ($request->ajax()) { return $this->responseAnswer(true, $params, null, trans('product.bad_product')); } else { return redirect('admin/products'); } }
/** * 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')); }
/** * 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); }