diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 3a3c82e..5ee91fb 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -872,12 +872,12 @@ function getGroupPostsBySetting($key, $limit = 10, $order = 'id', $dir = "DESC") } /** - * get group's posts by setting key + * get category's products by setting key * @param $key * @param integer $limit * @param string $order * @param string $dir - * @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C + * @return \App\Models\Category[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C */ function getCategoryProductBySetting($key, $limit = 10, $order = 'id', $dir = "DESC") { @@ -885,6 +885,24 @@ function getCategoryProductBySetting($key, $limit = 10, $order = 'id', $dir = "D ->products()->where('status', 1)->orderBy($order, $dir)->limit($limit)->get(); } +/** + * get products by setting key + * @param $key + * @param integer $limit + * @return \App\Models\Product[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C + */ +function getProductsQueryBySetting($key, $limit = 10) +{ + $data = explode(',', getSetting($key) ?? '1,id,DESC'); + if ($data[0] == 0) { + $q = Product::where('status', 1); + }else{ + $q = Category::where('id', $data[0])->first() + ->products()->where('status', 1); + } + return $q->orderBy($data[1], $data[2])->limit($limit)->get(); +} + /** * get group's posts by setting key * @param $key diff --git a/app/Http/Controllers/Admin/SettingController.php b/app/Http/Controllers/Admin/SettingController.php index 44799e2..fac96e3 100644 --- a/app/Http/Controllers/Admin/SettingController.php +++ b/app/Http/Controllers/Admin/SettingController.php @@ -22,11 +22,13 @@ class SettingController extends Controller // $settings = Setting::where('active', true) ->orderBy('section')->get(); //ESH// just active setting`s show - $cats = Category::all(['id','name']); - $menus = Menu::all(['id','name']); - $groups = Group::all(['id','name']); + $cats = Category::all(['id', 'name'])->toArray(); + $menus = Menu::all(['id', 'name']); + $groups = Group::all(['id', 'name'])->toArray(); + $catz = array_merge([['id' => 0, 'name' => __('All')]], $cats); + $groupz = array_merge([['id' => 0, 'name' => __('All')]], $groups); return view('admin.commons.setting', - compact('settings', 'cats','groups','menus')); + compact('settings', 'cats', 'groups', 'menus', 'catz', 'groupz')); } /** @@ -50,7 +52,7 @@ class SettingController extends Controller $set->type = $request->type; $set->size = $request->size; $set->save(); - logAdmin(__METHOD__,__CLASS__,$set->id); + logAdmin(__METHOD__, __CLASS__, $set->id); return redirect()->back()->with(['message' => __('Setting added to website')]); } @@ -78,14 +80,21 @@ class SettingController extends Controller $all = $request->all(); foreach ($all as $key => $val) { $set = Setting::where('key', $key)->first(); - if ($set != null && !$request->hasFile($key)) { + if ($set == null) { + continue; + } + if ($set->type == 'PRODUCT_QUERY' || $set->type == 'POST_QUERY') { + $set->value = implode(',', $val); + $set->raw = implode(',', $val); + $set->save(); + } elseif ($set != null && !$request->hasFile($key)) { - $set->value = validateSettingRequest($set,$val); - $set->raw = validateSettingRequest($set,$val); + $set->value = validateSettingRequest($set, $val); + $set->raw = validateSettingRequest($set, $val); // need to test if (config('app.xlang.active') && config('app.xlang.main') != 'en' && ( - $set->type != 'TEXT' && $set->type != 'EDITOR' && $set->type != 'LONGTEXT')){ - $set->setTranslation('value','en' , $val); + $set->type != 'TEXT' && $set->type != 'EDITOR' && $set->type != 'LONGTEXT')) { + $set->setTranslation('value', 'en', $val); } $set->save(); } @@ -94,30 +103,30 @@ class SettingController extends Controller if (isset($files['file'])) { $format = getSetting('optimize'); foreach ($files['file'] as $index => $file) { - if ( ($file->guessExtension() == 'jpg' || $file->guessExtension() == 'png') && ($index != 'site_image') ) { + if (($file->guessExtension() == 'jpg' || $file->guessExtension() == 'png') && ($index != 'site_image')) { $i = Image::load($file->getRealPath()) ->optimize() ->format($format); - $file->move(public_path('upload/images/'), str_replace('_','.',$index) );//store('/images/'.,['disk' => 'public']); - $optimizedFile = public_path('upload/images/optimized-'). str_replace('_','.',$index); - $optimizedFile = str_replace(['jpg','png','gif'],'webp',$optimizedFile); + $file->move(public_path('upload/images/'), str_replace('_', '.', $index));//store('/images/'.,['disk' => 'public']); + $optimizedFile = public_path('upload/images/optimized-') . str_replace('_', '.', $index); + $optimizedFile = str_replace(['jpg', 'png', 'gif'], 'webp', $optimizedFile); $i->save($optimizedFile); - }else - if ($file->guessExtension() == 'mp4' || $file->guessExtension() == 'mp3'){ - $file->move(public_path('upload/media/'), str_replace('_','.',$index) );//store('/images/'.,['disk' => 'public']); - }else{ + } else + if ($file->guessExtension() == 'mp4' || $file->guessExtension() == 'mp3') { + $file->move(public_path('upload/media/'), str_replace('_', '.', $index));//store('/images/'.,['disk' => 'public']); + } else { - $file->move(public_path('upload/file/'), str_replace('_','.',$index) );//store('/images/'.,['disk' => 'public']); - } + $file->move(public_path('upload/file/'), str_replace('_', '.', $index));//store('/images/'.,['disk' => 'public']); + } } } - if ($request->has('build')){ + if ($request->has('build')) { Artisan::call('build'); } - logAdmin(__METHOD__,__CLASS__,null); + logAdmin(__METHOD__, __CLASS__, null); return redirect()->back()->with(['message' => __('Setting of website updated')]); } @@ -129,8 +138,9 @@ class SettingController extends Controller // } - public function cacheClear(){ - $f = Setting::where('key','cache_number')->first(); + public function cacheClear() + { + $f = Setting::where('key', 'cache_number')->first(); $f->value += 1; $f->save(); Artisan::call('cache:clear'); @@ -140,13 +150,16 @@ class SettingController extends Controller return redirect()->back()->with(['message' => __('Cache cleared')]); } - public function liveEdit($slug){ - $settings = Setting::where('active', true)->where('key','LIKE',$slug.'%') + public function liveEdit($slug) + { + $settings = Setting::where('active', true)->where('key', 'LIKE', $slug . '%') ->orderBy('section')->get(); - $cats = Category::all(['id','name']); - $menus = Menu::all(['id','name']); - $groups = Group::all(['id','name']); + $cats = Category::all(['id', 'name'])->toArray(); + $catz = array_merge([['id' => 0, 'name' => __('All')]], $cats); + $menus = Menu::all(['id', 'name']); + $groups = Group::all(['id', 'name'])->toArray(); + $groupz = array_merge([['id' => 0, 'name' => __('All')]], $groups); return view('admin.commons.live', - compact('settings', 'cats','groups','menus')); + compact('settings', 'cats', 'groups', 'menus', 'catz', 'groupz')); } } diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 3185b13..4b849ec 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -14,7 +14,7 @@ class Setting extends Model public static $settingTypes = ['TEXT', 'NUMBER', 'LONGTEXT', 'CODE', 'EDITOR', 'CATEGORY', 'GROUP', 'CHECKBOX', 'FILE', 'COLOR', 'SELECT', 'MENU', 'LOCATION', - 'ICON','DATE','DATETIME','TIME']; + 'ICON','DATE','DATETIME','TIME','PRODUCT_QUERY','POST_QUERY']; public function getData() { diff --git a/resources/lang/fa.json b/resources/lang/fa.json index 2ee31f9..517f1d1 100644 --- a/resources/lang/fa.json +++ b/resources/lang/fa.json @@ -87,6 +87,7 @@ "As you wished restored successfully": "همانطور که شما مایل بودید بازیافت شد", "As you wished sort saved": "همانطور که شما مایل بودید مرتب شدند", "As you wished updated successfully": "همانطور که شما مایل بودید به روز شد", + "Ascending": "صعودی", "Assets build failed": "دارایی‌ها ساخته نشده‌اند", "Assets build successfully": "دارایی‌ها با موفقیت ساخته شدن", "Attaching": "پیوست کردن", @@ -173,6 +174,7 @@ "Default admin email is :E1 (developer) or :E2 (admin) and default password is: :P": "در نگارش آزمایشی رایانامه توسعه دهنده :E1 است و رایانامه مدیر عادی :E2 و گذرواژه هر دو :P است", "DefaultFooter": "فوتر پیش‌فرض", "DefaultHeader": "هدر پیش‌فرض", + "Descending": "نزولی", "Description": "توضیحات", "Description Table": "جدول توضیحات", "Description Text": "نوشته توضیحات", @@ -369,6 +371,7 @@ "Please, Login or complete information to pay": "لطفا وارد شوید یا اطلاعات خود را تکمیل کنید تا اجازه پرداخت داشته باشید", "Poor": "ضعیف", "Post": "نوشته", + "Post RSS Feed": " RSS Feed نوشته", "Post Text": "متن نوشته", "Post code": "کد پستی", "Post reply": "پاسخ نوشته", @@ -381,6 +384,7 @@ "Price": "مبلغ", "Print": "چاپ", "Product": "محصول", + "Product RSS Feed": " RSS Feed محصولات", "Product added to compare": "محصول به فهرست مقایسه افزوده شد", "Product added to favorites": "محصول به علاقه‌مندی شما افزوده شد", "Product grid": "کاشی محصول", @@ -443,6 +447,7 @@ "Searchable": "قابل جستجو", "Section": "بخش", "Sections": "بخش‌ها", + "Sell": "فروش", "Send": "ارسال", "Send Answer": "ارسال پاسخ", "Send Answer and close": "ارسال پاسخ و بستن", @@ -481,7 +486,7 @@ "States": "استان‌ها", "States list": "فهرست استان‌ها", "Status": "وضعیت", - "Stock quantity": "موجود انبار", + "Stock quantity": "موجودی انبار", "Sub categories": "زیر دسته", "Sub groups": "زیر سرفصل", "Subject": "عنوان", @@ -534,6 +539,7 @@ "Unavailable": "ناموجود", "Unit": "واحد", "Unknown bulk action : :ACTION": "کار دسته جمعی تعریف نشده :ACTION", + "Update": "به روز شدن", "Upload file": "به روز کردن پرونده", "Upload images": "بارگزاری تصاویر", "Upload new images": "بارگزاری تصاویر جدید", diff --git a/resources/views/components/setting-field.blade.php b/resources/views/components/setting-field.blade.php index b3cc59e..6b6386e 100644 --- a/resources/views/components/setting-field.blade.php +++ b/resources/views/components/setting-field.blade.php @@ -13,7 +13,7 @@ @switch($setting->type) @case('LONGTEXT') - @break @@ -31,23 +31,29 @@ @break @case('DATE') getLocale() == 'fa') xshow="pdate" @else xshow="date" @endif xtitle="{{$setting->title}}" @if(app()->getLocale() != 'fa') def-tab="1" @endif - :xvalue="{{$setting->value}}" + xid="{{$setting->key}}" xname="{{$setting->key}}" @if(app()->getLocale() == 'fa') xshow="pdate" + @else xshow="date" @endif xtitle="{{$setting->title}}" @if(app()->getLocale() != 'fa') def-tab="1" + @endif + :xvalue="{{$setting->value}}" > @break @case('DATETIME') getLocale() == 'fa') xshow="pdatetime" @else xshow="datetime" @endif xtitle="{{$setting->title}}" @if(app()->getLocale() != 'fa') def-tab="1" @endif - :xvalue="{{$setting->value}}" + xid="{{$setting->key}}" xname="{{$setting->key}}" @if(app()->getLocale() == 'fa') xshow="pdatetime" + @else xshow="datetime" @endif xtitle="{{$setting->title}}" @if(app()->getLocale() != 'fa') def-tab="1" + @endif + :xvalue="{{$setting->value}}" :timepicker="true" > @break @case('ICON') - + @break @case('LOCATION') @php($latlng = explode(',',old($setting->key, $setting->value))) - + @break @case('EDITOR')