Cookiebot / Pixel / Kategorien erweitern

This commit is contained in:
Kevin Adametz 2021-04-29 16:36:58 +02:00
parent 36872100c6
commit 7d1ee844eb
28 changed files with 464 additions and 246 deletions

View file

@ -5,7 +5,7 @@ namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\IqImage;
use App\Models\ProductCategory;
use\Request;
use Request;
class CategoryController extends Controller
@ -21,7 +21,7 @@ class CategoryController extends Controller
{
$data = [
'values' => Category::all(),
'values' => Category::orderBy('pos', 'DESC')->get(),
];
return view('admin.category.index', $data);
}
@ -46,59 +46,93 @@ class CategoryController extends Controller
{
$data = Request::all();
$data['active'] = isset($data['active']) ? true : false;
$data['parent_id'] = isset($data['parent_id']) ? $data['parent_id'] : null;
if($data['id'] == "new"){
$model = Category::create($data);
}else{
$model = Category::find($data['id']);
$model->fill($data)->save();
if($data['action'] === 'save-product_category'){
if($data['id'] === 'new'){
$ProductCategory = ProductCategory::create([
'pos' => $data['pos'],
'product_id' => $data['product_id'],
'category_id' => $data['category_id'],
]);
\Session()->flash('alert-save', '1');
return redirect(route('admin_product_category_edit', [$ProductCategory->category_id]));
}else{
$ProductCategory = ProductCategory::findOrFail($data['id']);
if($ProductCategory->category_id != $data['category_id']){
abort(404);
}
$ProductCategory->pos = $data['pos'];
$ProductCategory->product_id = $data['product_id'];
$ProductCategory->save();
\Session()->flash('alert-save', '1');
return redirect(route('admin_product_category_edit', [$ProductCategory->category_id]));
}
}
$trans = [];
if(!empty($data['trans_name'])){
foreach ($data['trans_name'] as $lang => $value){
if($value && $value != null){
$trans[$lang] = $value;
if($data['action'] === 'save-form'){
$data['active'] = isset($data['active']) ? true : false;
$data['parent_id'] = isset($data['parent_id']) ? $data['parent_id'] : null;
if($data['id'] == "new"){
$model = Category::create($data);
}else{
$model = Category::find($data['id']);
$model->fill($data)->save();
}
$trans = [];
if(!empty($data['trans_name'])){
foreach ($data['trans_name'] as $lang => $value){
if($value && $value != null){
$trans[$lang] = $value;
}
}
}
}
$model->trans_name = $trans;
$model->save();
$trans = [];
if(!empty($data['trans_headline'])){
foreach ($data['trans_headline'] as $lang => $value){
if($value && $value != null){
$trans[$lang] = $value;
$model->trans_name = $trans;
$model->save();
$trans = [];
if(!empty($data['trans_headline'])){
foreach ($data['trans_headline'] as $lang => $value){
if($value && $value != null){
$trans[$lang] = $value;
}
}
}
$model->trans_headline = $trans;
$model->save();
\Session()->flash('alert-save', '1');
return redirect(route('admin_product_categories'));
}
$model->trans_headline = $trans;
$model->save();
\Session()->flash('alert-save', '1');
return redirect(route('admin_product_categories'));
}
public function delete($id){
public function delete($do, $id){
if(ProductCategory::where('category_id', $id)->count()){
\Session()->flash('alert-error', 'Eintrag wird als Produkt-Kategorie verwendet');
if($do === 'product_category'){
$model = ProductCategory::findOrFail($id);
$category = $model->category;
$model->delete();
\Session()->flash('alert-success', 'Eintrag gelöscht');
return redirect(route('admin_product_category_edit', [$category->id]));
}
if($do === 'category'){
if(ProductCategory::where('category_id', $id)->count()){
\Session()->flash('alert-error', 'Eintrag hat noch Produkte, erst löschen');
return redirect(route('admin_product_categories'));
}
if(Category::where('parent_id', $id)->count()){
\Session()->flash('alert-error', 'Eintrag wird als Haup-Kategorie verwendet');
return redirect(route('admin_product_categories'));
}
$model = Category::findOrFail($id);
$model->delete();
\Session()->flash('alert-success', 'Eintrag gelöscht');
return redirect(route('admin_product_categories'));
}
if(Category::where('parent_id', $id)->count()){
\Session()->flash('alert-error', 'Eintrag wird als Haup-Kategorie verwendet');
return redirect(route('admin_product_categories'));
}
$model = Category::findOrFail($id);
$model->delete();
\Session()->flash('alert-success', 'Eintrag gelöscht');
return redirect(route('admin_product_categories'));
}
// Upload FILE -----------------------------------------------------------------------------------------------------------------------