diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 81cacd9..20e93da 100755 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -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 ----------------------------------------------------------------------------------------------------------------------- diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 7c4b84a..de73f45 100755 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -37,6 +37,7 @@ class HomeController extends Controller if(!Auth::check()){ return redirect('login'); } + $data = [ 'user' => Auth::user(), 'now' => Carbon::now(), @@ -49,12 +50,12 @@ class HomeController extends Controller $data = Request::get('data'); $target = Request::get('target'); - $response = ""; if($data === "data_protection"){ $data = [ 'modal' => true, - 'user_shop' => Util::getUserShop(), + 'user_shop' => true, + 'isMivitaShop' => false, ]; $response = view('legal.data_protect_de', $data)->render(); } @@ -133,6 +134,7 @@ class HomeController extends Controller $data = [ 'modal' => false, 'user_shop' => Util::getUserShop(), + 'isMivitaShop' => Util::isMivitaShop(), ]; return view('legal.data_protected', $data); } diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 6979237..0e7ab15 100755 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -48,7 +48,6 @@ class ProductController extends Controller }else{ $model = Product::findOrFail($id); } - $country_for_prices = Country::where('own_eur', '=', true)->orWhere('currency', '=', true)->get(); $data = [ 'product' => $model, @@ -59,7 +58,6 @@ class ProductController extends Controller public function store() { - $data = Request::all(); $rules = array( diff --git a/app/Http/Controllers/Web/SiteController.php b/app/Http/Controllers/Web/SiteController.php index 0b9a2f1..4aaa89f 100755 --- a/app/Http/Controllers/Web/SiteController.php +++ b/app/Http/Controllers/Web/SiteController.php @@ -7,6 +7,7 @@ use App\Http\Controllers\Controller; use App\Models\Category; use App\Models\IqSite; use App\Models\Product; +use App\Models\ProductCategory; use App\Services\Util; class SiteController extends Controller @@ -41,7 +42,6 @@ class SiteController extends Controller } public function site($site, $subsite = false, $product_slug = false) { - $subsite = trim($subsite, '/'); $product_slug = trim($product_slug, '/'); if($product_slug){ @@ -71,13 +71,18 @@ class SiteController extends Controller $headline_image = $category->iq_image; } + + + $product_categories = ProductCategory::where('category_id', $category->id)->whereHas('product', function ($query) use ($category) { + $query->where('active', true)->where('show_at', '<=', 1); + })->orderBy('pos', 'DESC')->get(); + $data = [ 'user_shop' => Util::getUserShop(), 'subsite' => $subsite, - 'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(), - 'products' => Product::whereHas('categories', function ($query) use ($category) { - $query->where('category_id', '=', $category->id); - })->where('active', true)->where('show_at', '<=', 1)->orderBy('pos', 'DESC')->get(), + 'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(), + 'products' => false, + 'product_categories' => $product_categories, 'p_count' => Product::where('active', true)->where('show_at', '<=', 1)->count(), 'headline' => $category->getLang('headline'), 'headline_image' => $headline_image, @@ -89,8 +94,9 @@ class SiteController extends Controller $data = [ 'user_shop' => Util::getUserShop(), 'subsite' => 'alle-produkte', - 'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(), - 'products' => Product::where('active', true)->where('show_at', '<=', 1)->orderBy('pos', 'ASC')->get(), + 'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(), + 'products' => Product::where('active', true)->where('show_at', '<=', 1)->orderBy('pos', 'DESC')->get(), + 'product_categories' => false, 'p_count' => Product::where('active', true)->where('show_at', '<=', 1)->count(), 'headline' => 'Produktwelt', 'headline_image' => false, diff --git a/app/Http/Middleware/Subdomain.php b/app/Http/Middleware/Subdomain.php index e2ce1e1..9a0f163 100755 --- a/app/Http/Middleware/Subdomain.php +++ b/app/Http/Middleware/Subdomain.php @@ -36,7 +36,6 @@ class Subdomain } \Session::put('user_shop', $user_shop); \Session::put('user_shop_domain', config('app.protocol').$user_shop->slug.".".config('app.domain').config('app.tld_care')); - Config::set('app.url', $user_shop->slug.".".config('app.domain').config('app.tld_care')); return $next($request); } diff --git a/app/Models/Category.php b/app/Models/Category.php index 8f8415d..3db2cf1 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -79,7 +79,7 @@ class Category extends Model public function product_categories() { - return $this->hasMany('App\Models\ProductCategory', 'category_id', 'id'); + return $this->hasMany('App\Models\ProductCategory', 'category_id', 'id')->orderBy('pos', 'DESC'); } diff --git a/app/Models/Product.php b/app/Models/Product.php index 035b1c0..aefbad9 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -220,7 +220,7 @@ class Product extends Model } public function categories(){ - return $this->hasMany('App\Models\ProductCategory', 'product_id', 'id'); + return $this->hasMany('App\Models\ProductCategory', 'product_id', 'id')->orderBy('pos', 'DESC'); } public function images(){ diff --git a/app/Models/ProductCategory.php b/app/Models/ProductCategory.php index edeebeb..6e67744 100644 --- a/app/Models/ProductCategory.php +++ b/app/Models/ProductCategory.php @@ -29,7 +29,7 @@ class ProductCategory extends Model protected $table = 'product_categories'; protected $fillable = [ - 'product_id', 'category_id', + 'product_id', 'category_id', 'pos' ]; public function product() diff --git a/app/Services/HTMLHelper.php b/app/Services/HTMLHelper.php index 09602fe..3883a32 100644 --- a/app/Services/HTMLHelper.php +++ b/app/Services/HTMLHelper.php @@ -135,7 +135,7 @@ class HTMLHelper } public static function getCategoriesOptions($ids = array(), $all = true){ - $values = Category::where('active', 1)->get(); + $values = Category::where('active', 1)->orderBy('pos', 'DESC')->get(); $ret = ""; if($all){ $ret .= '\n'; diff --git a/app/Services/Util.php b/app/Services/Util.php index 9a6d48d..0094d7f 100644 --- a/app/Services/Util.php +++ b/app/Services/Util.php @@ -228,6 +228,12 @@ class Util } return url($uri); } + + public static function isMivitaShop(){ + return \Config::get('app.url') === config('app.domain').config('app.tld_shop'); + } + + public static function sanitize($string, $force_lowercase = true, $anal = false, $substr = false) { $strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]", diff --git a/database/migrations/2018_10_21_164005_create_product_categories_table.php b/database/migrations/2018_10_21_164005_create_product_categories_table.php index 439cc6a..05e0e8b 100644 --- a/database/migrations/2018_10_21_164005_create_product_categories_table.php +++ b/database/migrations/2018_10_21_164005_create_product_categories_table.php @@ -16,6 +16,7 @@ class CreateProductCategoriesTable extends Migration Schema::create('product_categories', function (Blueprint $table) { $table->increments('id'); + $table->unsignedTinyInteger('pos')->nullable()->default(0); $table->unsignedInteger('product_id')->index(); $table->unsignedInteger('category_id')->index(); diff --git a/resources/views/admin/category/edit.blade.php b/resources/views/admin/category/edit.blade.php index 7288499..13b5780 100755 --- a/resources/views/admin/category/edit.blade.php +++ b/resources/views/admin/category/edit.blade.php @@ -23,6 +23,8 @@ {!! Form::open(['url' => route('admin_product_category_store'), 'class' => 'form-horizontal', 'id'=>'']) !!} + +