23-01-2026
This commit is contained in:
parent
a939cd51ef
commit
a8b395e20d
248 changed files with 29342 additions and 4805 deletions
|
|
@ -4,14 +4,13 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Models\Country;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductBundle;
|
||||
use App\Models\ProductImage;
|
||||
use App\Models\ProductIngredient;
|
||||
use App\Repositories\ProductRepository;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
protected $productRepo;
|
||||
|
|
@ -20,32 +19,31 @@ class ProductController extends Controller
|
|||
{
|
||||
$this->middleware('admin');
|
||||
$this->productRepo = $productRepo;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if(Request::get('show_active_products')){
|
||||
if (Request::get('show_active_products')) {
|
||||
set_user_attr('show_active_products', Request::get('show_active_products'));
|
||||
}
|
||||
if(get_user_attr('show_active_products') === "true"){
|
||||
if (get_user_attr('show_active_products') === 'true') {
|
||||
$values = Product::where('active', true)->orderBy('pos', 'DESC')->orderBy('id', 'DESC')->get();
|
||||
}else{
|
||||
} else {
|
||||
$values = Product::orderBy('pos', 'DESC')->orderBy('id', 'DESC')->get();
|
||||
|
||||
}
|
||||
$data = [
|
||||
'values' => $values
|
||||
'values' => $values,
|
||||
];
|
||||
|
||||
return view('admin.product.index', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
if($id === "new"){
|
||||
$model = new Product();
|
||||
if ($id === 'new') {
|
||||
$model = new Product;
|
||||
$model->active = true;
|
||||
}else{
|
||||
} else {
|
||||
$model = Product::findOrFail($id);
|
||||
}
|
||||
$country_for_prices = Country::where('own_eur', '=', true)->orWhere('currency', '=', true)->get();
|
||||
|
|
@ -53,32 +51,32 @@ class ProductController extends Controller
|
|||
'product' => $model,
|
||||
'country_for_prices' => $country_for_prices,
|
||||
];
|
||||
|
||||
return view('admin.product.edit', $data);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$data = Request::all();
|
||||
$rules = array(
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
);
|
||||
];
|
||||
/*if(isset($data['number']) && $data['number'] != ""){
|
||||
$rules['number'] = 'int';
|
||||
}*/
|
||||
if(isset($data['wp_number'])){
|
||||
if($data['id'] !== "new"){
|
||||
if (isset($data['wp_number'])) {
|
||||
if ($data['id'] !== 'new') {
|
||||
$model = Product::findOrFail($data['id']);
|
||||
$rules['wp_number'] = 'unique:products,wp_number,'.$model->id;
|
||||
}else{
|
||||
} else {
|
||||
$rules['wp_number'] = 'unique:products,wp_number';
|
||||
|
||||
}
|
||||
}
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
||||
if($data['id'] === "new"){
|
||||
$model = new Product();
|
||||
}else{
|
||||
if ($data['id'] === 'new') {
|
||||
$model = new Product;
|
||||
} else {
|
||||
$model = Product::findOrFail($data['id']);
|
||||
}
|
||||
$country_for_prices = Country::where('own_eur', '=', true)->orWhere('currency', '=', true)->get();
|
||||
|
|
@ -92,55 +90,66 @@ class ProductController extends Controller
|
|||
if ($validator->fails()) {
|
||||
|
||||
return view('admin.product.edit', $data)->withErrors($validator);
|
||||
|
||||
} else {
|
||||
$product = $this->productRepo->update(Request::all());
|
||||
\Session()->flash('alert-save', true);
|
||||
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
|
||||
return redirect(route('admin_product_show'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function copy($id){
|
||||
public function copy($id)
|
||||
{
|
||||
$model = Product::findOrFail($id);
|
||||
|
||||
$product = $this->productRepo->copy($model);
|
||||
|
||||
|
||||
|
||||
\Session()->flash('alert-success', 'Eintrag kopiert');
|
||||
|
||||
return redirect(route('admin_product_show'));
|
||||
}
|
||||
|
||||
public function delete($id, $do = 'product', $did = null){
|
||||
if($do === 'product'){
|
||||
public function delete($id, $do = 'product', $did = null)
|
||||
{
|
||||
if ($do === 'product') {
|
||||
$model = Product::findOrFail($id);
|
||||
$model->delete();
|
||||
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
||||
|
||||
return redirect(route('admin_product_show'));
|
||||
}
|
||||
|
||||
if($do === 'ingredient'){
|
||||
if ($do === 'ingredient') {
|
||||
$model = Product::findOrFail($id);
|
||||
$ProductIngredient = ProductIngredient::where('ingredient_id', $did)->where('product_id', $model->id)->first();
|
||||
if($ProductIngredient){
|
||||
if ($ProductIngredient) {
|
||||
$ProductIngredient->delete();
|
||||
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
||||
|
||||
return redirect(route('admin_product_edit', [$model->id]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if ($do === 'bundle') {
|
||||
$model = Product::findOrFail($id);
|
||||
$ProductBundle = ProductBundle::where('bundle_product_id', $did)->where('product_id', $model->id)->first();
|
||||
if ($ProductBundle) {
|
||||
$ProductBundle->delete();
|
||||
\Session()->flash('alert-success', 'Bundle-Produkt entfernt');
|
||||
|
||||
return redirect(route('admin_product_edit', [$model->id]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Upload FILE -----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public function imageUpload(){
|
||||
public function imageUpload()
|
||||
{
|
||||
|
||||
$product_id = Request::get('product_id');
|
||||
$product = Product::findOrFail($product_id);
|
||||
|
|
@ -148,15 +157,15 @@ class ProductController extends Controller
|
|||
try {
|
||||
$image = \App\Services\Slim::getImages('images')[0];
|
||||
|
||||
if ( isset($image['output']['data']) )
|
||||
{
|
||||
if (isset($image['output']['data'])) {
|
||||
|
||||
// Base64 of the image
|
||||
$data = $image['output']['data'];
|
||||
$file_ex = array( 'image/jpeg' => 'jpg', 'image/png' => 'png');
|
||||
$file_ex = ['image/jpeg' => 'jpg', 'image/png' => 'png'];
|
||||
|
||||
if (!isset($file_ex[$image['output']['type']])) {
|
||||
if (! isset($file_ex[$image['output']['type']])) {
|
||||
\Session()->flash('alert-danger', 'File is not jpg or png!');
|
||||
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +173,7 @@ class ProductController extends Controller
|
|||
// Original file name
|
||||
$name = $image['output']['name'];
|
||||
$name = \App\Services\Slim::sanitizeFileName($name);
|
||||
$name = uniqid() . '_' . $name;
|
||||
$name = uniqid().'_'.$name;
|
||||
|
||||
$data = \Storage::disk('public')->put(
|
||||
'images/product/'.$product->id.'/'.$name,
|
||||
|
|
@ -177,46 +186,48 @@ class ProductController extends Controller
|
|||
'original_name' => $image['output']['name'],
|
||||
'ext' => $ext,
|
||||
'mine' => $image['output']['type'],
|
||||
'size' => $image['input']['size']
|
||||
'size' => $image['input']['size'],
|
||||
]);
|
||||
|
||||
|
||||
\Session()->flash('alert-success', __('msg.file_uploaded'));
|
||||
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
\Session()->flash('alert-danger', __('msg.file_empty'));
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
|
||||
}
|
||||
catch ( \Exception $e) {
|
||||
\Session()->flash('alert-danger', "Fehler".$e);
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
} catch (\Exception $e) {
|
||||
\Session()->flash('alert-danger', 'Fehler'.$e);
|
||||
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
}
|
||||
|
||||
public function imageDelete($image_id, $product_id){
|
||||
public function imageDelete($image_id, $product_id)
|
||||
{
|
||||
|
||||
$product = Product::findOrFail($product_id);
|
||||
$product_image = ProductImage::findOrFail($image_id);
|
||||
|
||||
if($product_image->product_id == $product->id){
|
||||
$file = 'images/product/'.$product->id.'/'.$product_image->filename;
|
||||
if ($product_image->product_id == $product->id) {
|
||||
$file = 'images/product/'.$product->id.'/'.$product_image->filename;
|
||||
\Storage::disk('public')->delete($file);
|
||||
|
||||
$product_image->delete();
|
||||
|
||||
\Session()->flash('alert-success', __('msg.file_deleted'));
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
\Session()->flash('alert-danger', __('msg.file_not_found'));
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
|
||||
public function imageAttribute($product_id, $attr, $val = false){
|
||||
public function imageAttribute($product_id, $attr, $val = false)
|
||||
{
|
||||
|
||||
if(is_numeric($val) && $val < 0){
|
||||
if (is_numeric($val) && $val < 0) {
|
||||
$val = 0;
|
||||
}
|
||||
|
||||
|
|
@ -225,9 +236,8 @@ class ProductController extends Controller
|
|||
$product_image->{$attr} = $val;
|
||||
$product_image->save();
|
||||
|
||||
\Session()->flash('alert-success', "Wert gespeichert");
|
||||
\Session()->flash('alert-success', 'Wert gespeichert');
|
||||
|
||||
return redirect()->back();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue