From 861b6fd5a0f9dfac2df98166c1e31f710cbf609b Mon Sep 17 00:00:00 2001 From: A1Gard Date: Fri, 12 Jul 2024 07:05:20 +0330 Subject: [PATCH] added some feature for theme and setting fixed some bugs optimized make part --- app/Console/Commands/makePart.php | 4 +- app/Helpers/Helper.php | 13 ++ app/Http/Controllers/Admin/AreaController.php | 4 +- .../Controllers/Admin/SettingController.php | 2 +- app/Models/Category.php | 4 + app/Models/Product.php | 125 ++++++++++++++---- app/Models/Prop.php | 12 +- database/seeders/AreaSeeder.php | 2 +- resources/js/components/AreaDesginer.vue | 11 +- resources/sass/client-custom/_general.scss | 7 + resources/sass/client-custom/_zfix.scss | 46 +++++++ .../FavProductWithMeta/screenshot.png | Bin 0 -> 94522 bytes .../parallax/ParallaxShort/screenshot.png | Bin 0 -> 468053 bytes routes/web.php | 6 +- 14 files changed, 202 insertions(+), 34 deletions(-) create mode 100644 resources/views/segments/category/FavProductWithMeta/screenshot.png create mode 100644 resources/views/segments/parallax/ParallaxShort/screenshot.png diff --git a/app/Console/Commands/makePart.php b/app/Console/Commands/makePart.php index e0fcf12..456acd6 100644 --- a/app/Console/Commands/makePart.php +++ b/app/Console/Commands/makePart.php @@ -72,12 +72,12 @@ class makePart extends Command $handler = str_replace('Handle',ucfirst($part), $handler); $scss = <<"); + file_put_contents($folderPath . '/' . $part . '.blade.php', "
"); file_put_contents($folderPath . '/' . $part . '.js', ''); file_put_contents($folderPath . '/' . $part . '.json', json_encode($detail,JSON_PRETTY_PRINT)); file_put_contents($folderPath . '/' . ucfirst($part) . '.php', $handler); diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 527a3ed..9536f35 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -3,6 +3,7 @@ use App\Helpers; use App\Models\Setting; use App\Models\Group; +use App\Models\Category; use App\Models\Area; use App\Models\Part; use Illuminate\Support\Facades\Route; @@ -776,3 +777,15 @@ function getGroupPostsBySetting($key, $limit = 10) return Group::where('id', getSetting($key) ?? 1)->first() ->posts()->where('status', 1)->limit($limit)->get(); } + +/** + * get group's posts by setting key + * @param $key + * @param $limit + * @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C + */ +function getCategoryProductBySetting($key, $limit = 10) +{ + return Category::where('id', getSetting($key) ?? 1)->first() + ->products()->where('status', 1)->limit($limit)->get(); +} diff --git a/app/Http/Controllers/Admin/AreaController.php b/app/Http/Controllers/Admin/AreaController.php index 185fb78..30d231d 100644 --- a/app/Http/Controllers/Admin/AreaController.php +++ b/app/Http/Controllers/Admin/AreaController.php @@ -71,7 +71,9 @@ class AreaController extends Controller $part->save(); } } - Part::whereIn('id', json_decode($request->input('removed')))->delete(); + foreach ( json_decode($request->input('removed')) as $id){ + Part::where('id',$id)->first()->delete(); + } \Artisan::call('client'); logAdmin(__METHOD__,__CLASS__,$area->id); diff --git a/app/Http/Controllers/Admin/SettingController.php b/app/Http/Controllers/Admin/SettingController.php index 3c5aeb5..0b89441 100644 --- a/app/Http/Controllers/Admin/SettingController.php +++ b/app/Http/Controllers/Admin/SettingController.php @@ -83,7 +83,7 @@ class SettingController extends Controller $files = $request->allFiles(); if (isset($files['file'])) { foreach ($files['file'] as $index => $file) { - if ($file->extension() == 'mp4' || $file->extension() == 'mp3'){ + 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/images/'), str_replace('_','.',$index) );//store('/images/'.,['disk' => 'public']); diff --git a/app/Models/Category.php b/app/Models/Category.php index 945fb60..c2cc6e6 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -75,4 +75,8 @@ class Category extends Model return route(''); } + public function products(){ + return $this->belongsToMany(Product::class); + } + } diff --git a/app/Models/Product.php b/app/Models/Product.php index b499aa2..8993bf7 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -24,17 +24,19 @@ class Product extends Model implements HasMedia 'qidz' => 'array' ]; - public function attachs(){ - return $this->morphMany(Attachment::class,'attachable'); + public function attachs() + { + return $this->morphMany(Attachment::class, 'attachable'); } protected $guarded = []; - public function getQzAttribute(){ + public function getQzAttribute() + { $result = []; foreach ($this->quantities as $q) { - if ($q->count > 0){ + if ($q->count > 0) { $q->data = json_decode($q->data); $result[] = $q; } @@ -42,20 +44,22 @@ class Product extends Model implements HasMedia return $result; } - public function getQidzAttribute(){ + + public function getQidzAttribute() + { return $this->quantities()->pluck('id')->toArray(); } public static $stock_status = ['IN_STOCK', 'OUT_STOCK', 'BACK_ORDER']; - public $translatable = ['name', 'excerpt', 'description','table']; + public $translatable = ['name', 'excerpt', 'description', 'table']; public function registerMediaConversions(?Media $media = null): void { $ti = imageSizeConvertValidate('product_image'); $t = imageSizeConvertValidate('product_thumb'); - $mc = $this->addMediaConversion('product-thumb') + $mc = $this->addMediaConversion('product-thumb') ->width($t[0]) ->height($t[1]) ->crop($t[0], $t[1]) @@ -73,19 +77,25 @@ class Product extends Model implements HasMedia ->nonQueued() ->format(getSetting('optimize')); - if (getSetting('watermark')){ + if (getSetting('watermark')) { $mc->watermark(public_path('upload/images/logo.png'), - AlignPosition::BottomLeft, 5, 5, Unit::Percent, - config('app.media.watermark_size'), Unit::Percent, - config('app.media.watermark_size'), Unit::Percent, Fit::Contain, - config('app.media.watermark_opacity')); + AlignPosition::BottomLeft, 5, 5, Unit::Percent, + config('app.media.watermark_size'), Unit::Percent, + config('app.media.watermark_size'), Unit::Percent, Fit::Contain, + config('app.media.watermark_opacity')); $mc2->watermark(public_path('upload/images/logo.png'), - AlignPosition::BottomLeft, 5, 5, Unit::Percent, - config('app.media.watermark_size'), Unit::Percent, - config('app.media.watermark_size'), Unit::Percent, Fit::Contain, - config('app.media.watermark_opacity')); + AlignPosition::BottomLeft, 5, 5, Unit::Percent, + config('app.media.watermark_size'), Unit::Percent, + config('app.media.watermark_size'), Unit::Percent, Fit::Contain, + config('app.media.watermark_opacity')); } + + $this->addMediaConversion('product-optimized') + ->optimize() + ->sharpen(10) + ->nonQueued() + ->format('webp'); } @@ -151,35 +161,52 @@ class Product extends Model implements HasMedia } } - public function imgUrl(){ + public function imgUrl() + { if ($this->getMedia()->count() > 0) { return $this->getMedia()[$this->image_index]->getUrl('product-image'); } else { return asset('assets/upload/logo.svg'); } } - public function orginalImageUrl(){ + + public function originalImageUrl() + { if ($this->getMedia()->count() > 0) { return $this->getMedia()[$this->image_index]->getUrl(); } else { return asset('assets/upload/logo.svg'); } } - public function imgUrl2(){ + public function originalOptimizedImageUrl() + { + if ($this->getMedia()->count() > 0) { + return $this->getMedia()[$this->image_index]->getUrl('product-optimized'); + } else { + return asset('assets/upload/logo.svg'); + } + } + + public function imgUrl2() + { if ($this->getMedia()->count() > 0 && isset($this->getMedia()[1])) { return $this->getMedia()[1]->getUrl('product-image'); } else { return asset('assets/upload/logo.svg'); } } - public function thumbUrl(){ + + public function thumbUrl() + { if ($this->getMedia()->count() > 0) { return $this->getMedia()[$this->image_index]->getUrl('product-thumb'); } else { return asset('assets/upload/logo.svg'); } } - public function thumbUrl2(){ + + public function thumbUrl2() + { if ($this->getMedia()->count() > 0 && isset($this->getMedia()[1])) { return $this->getMedia()[1]->getUrl('product-thumb'); } else { @@ -188,8 +215,60 @@ class Product extends Model implements HasMedia } - public function webUrl(){ - return '#';// WIP + public function fullMeta($limit = 99) + { + $metas = $this->getAllMeta()->toArray(); + $result = []; + $i = 0; + foreach ($metas as $key => $value) { + $result[$key] = [ + 'value' => $value, + 'data' => Prop::where('name', $key)->first(), + ]; + switch ($result[$key]['data']['type']) { + case 'color': + $result[$key]['human_value'] = "
 
"; + break; + case 'checkbox': + $result[$key]['human_value'] = $value ? '✅' : '❌'; + break; + case 'multi': + case 'select': + case 'singlemulti': + if (!is_array($value)) { + $result[$key]['human_value'] = $result[$key]['data']->datas[$value]; + } else { + $result[$key]['human_value'] = ''; + foreach ($value as $k => $v) { + $result[$key]['human_value'] = $result[$key]['data']->datas[$v].', '; + } + $result[$key]['human_value'] = trim($result[$key]['human_value'],' ,'); + } + break; + default: + if (is_array($value)) { + $result[$key]['human_value'] = implode(', ', $value); + } else { + + $result[$key]['human_value'] = $value; + } + } + + $result[$key]['human_value'] .= ' ' . $result[$key]['data']['unit']; + } + + usort($result, function ($a, $b) { + return $a['data']['sort'] - $b['data']['sort']; + }); + + $result = array_slice($result, 0, $limit); + + return $result; + } + + public function webUrl() + { + return '#';// WIP return route(''); } diff --git a/app/Models/Prop.php b/app/Models/Prop.php index 781071f..d65ea5e 100644 --- a/app/Models/Prop.php +++ b/app/Models/Prop.php @@ -16,7 +16,8 @@ class Prop extends Model protected $casts = [ 'dataz', - 'optionz' + 'optionz', + 'datas' ]; public static $prop_types = ['text', 'number', 'checkbox', 'color', 'select', 'multi', 'singlemulti']; @@ -35,6 +36,15 @@ class Prop extends Model return $result; } + public function getDatasAttribute() + { + $result = []; + foreach (json_decode($this->options) as $item) { + $result[$item->value] = $item->title; + } + + return $result; + } public function getOptionzAttribute() { diff --git a/database/seeders/AreaSeeder.php b/database/seeders/AreaSeeder.php index a4b6ac9..ed8e278 100644 --- a/database/seeders/AreaSeeder.php +++ b/database/seeders/AreaSeeder.php @@ -28,7 +28,7 @@ class AreaSeeder extends Seeder 'valid_segments' => json_encode( ["top","slider","header","footer","menu", "parallax","other","posts","products","attachments" - ,"groups","categories"] + ,"groups","categories","category","group"] ), 'max' => 10, 'icon' => 'ri-layout-top-2-line', diff --git a/resources/js/components/AreaDesginer.vue b/resources/js/components/AreaDesginer.vue index 3620bee..23d49ee 100644 --- a/resources/js/components/AreaDesginer.vue +++ b/resources/js/components/AreaDesginer.vue @@ -11,10 +11,10 @@
-
+