1
0
Fork 0

customize thumbnail size

fixed some error
fixed file template
main
A1Gard 1 year ago
parent 8a7124b916
commit 11bcfe5d5a

@ -57,9 +57,10 @@ PUSHER_APP_KEY=
PUSHER_APP_SECRET= PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1 PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
ZARINPAL_MERCHANT='12000000-0220-0000-0220-220000000001' ZARINPAL_MERCHANT='12000000-0220-0000-0220-220000000001'
PAY_GATWAY=zarinpal PAY_GATWAY=zarinpal
THUMBNAIL_SIZE=600x600

@ -347,7 +347,7 @@ function getProductByCat($id, $order = 'id', $orderMethod = 'desc', $limit = 10)
if ($cat == null){ if ($cat == null){
return []; return [];
} }
return $cat->products()->where('active',1) return $cat->active_products()->where('active',1)
->orderBy($order, $orderMethod)->limit($limit)->get(); ->orderBy($order, $orderMethod)->limit($limit)->get();
} }
function getProductByCatQ($id, $order = 'id', $limit = 10) function getProductByCatQ($id, $order = 'id', $limit = 10)

@ -57,16 +57,18 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media;
*/ */
class Cat extends Model implements HasMedia class Cat extends Model implements HasMedia
{ {
use HasFactory,SoftDeletes, InteractsWithMedia; use HasFactory, SoftDeletes, InteractsWithMedia;
public function registerMediaConversions(Media $media = null): void public function registerMediaConversions(Media $media = null): void
{ {
$size = explode('x', config('app.thumbnail_size'));
$this->addMediaConversion('cat-thumb') $this->addMediaConversion('cat-thumb')
->width(600) ->width($size[0])
->height(600) ->height($size[1])
->crop(Manipulations::CROP_CENTER, 600, 600) ->crop(Manipulations::CROP_CENTER, $size[0], $size[1])
->optimize() ->optimize()
->sharpen(10); ->sharpen(10);
@ -75,7 +77,8 @@ class Cat extends Model implements HasMedia
} }
} }
public function thumbUrl() { public function thumbUrl()
{
if ($this->getMedia()->count() > 0) { if ($this->getMedia()->count() > 0) {
return $this->getMedia()->first()->getUrl('cat-thumb'); return $this->getMedia()->first()->getUrl('cat-thumb');
} else { } else {
@ -84,7 +87,8 @@ class Cat extends Model implements HasMedia
} }
} }
public function imgurl() { public function imgurl()
{
if ($this->getMedia()->count() > 0) { if ($this->getMedia()->count() > 0) {
return $this->getMedia()->last()->getUrl(); return $this->getMedia()->last()->getUrl();
} else { } else {
@ -92,11 +96,14 @@ class Cat extends Model implements HasMedia
} }
} }
public function products(){ public function products()
return$this->belongsToMany(Product::class); {
return $this->belongsToMany(Product::class);
} }
public function active_products(){
return$this->belongsToMany(Product::class)->where(''); public function active_products()
{
return $this->belongsToMany(Product::class)->where('active', 1);
} }
public function backUrl() public function backUrl()
@ -109,19 +116,23 @@ class Cat extends Model implements HasMedia
} }
// //
public function parent() { public function parent()
{
return $this->belongsTo(Cat::class, 'parent_id'); return $this->belongsTo(Cat::class, 'parent_id');
} }
public function children() { public function children()
{
return $this->hasMany(Cat::class, 'parent_id'); return $this->hasMany(Cat::class, 'parent_id');
} }
public function getRouteKeyName() { public function getRouteKeyName()
{
return 'slug'; return 'slug';
} }
public function props(){ public function props()
{
return $this->belongsToMany(Prop::class); return $this->belongsToMany(Prop::class);
} }
} }

@ -167,16 +167,19 @@ class Product extends Model implements HasMedia
public function registerMediaConversions(Media $media = null): void public function registerMediaConversions(Media $media = null): void
{ {
$size = explode('x', config('app.thumbnail_size'));
$this->addMediaConversion('product-image') $this->addMediaConversion('product-image')
->width(1200) ->width(1200)
// ->height(600) // ->height(600)
// ->crop(Manipulations::CROP_CENTER, 1200, 600) // ->crop(Manipulations::CROP_CENTER, 1200, 600)
->optimize() ->optimize()
->sharpen(10); ->sharpen(10);
$this->addMediaConversion('product-thumb') $this->addMediaConversion('product-thumb')
->width(600) ->width($size[0])
->height(600) ->height($size[1])
->crop(Manipulations::CROP_CENTER, 600, 600) ->crop(Manipulations::CROP_CENTER, $size[0], $size[1])
->optimize() ->optimize()
->sharpen(10); ->sharpen(10);
} }

@ -56,6 +56,8 @@ use Xmen\StarterKit\Models\StarterKit;
* @property-read int|null $products_count * @property-read int|null $products_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Access> $accesses * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Access> $accesses
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Product> $products * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Product> $products
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Access> $accesses
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Product> $products
* @mixin \Eloquent * @mixin \Eloquent
*/ */
class User extends Authenticatable class User extends Authenticatable

@ -58,14 +58,15 @@ return [
'asset_url' => env('ASSET_URL'), 'asset_url' => env('ASSET_URL'),
'currency_type' => env('CURRENCY_TYPE'), 'currency_type' => env('CURRENCY_TYPE','$'),
'invoice_prefix' => env('INVOICE_PREFIX'), 'invoice_prefix' => env('INVOICE_PREFIX','xshop-000'),
'sms_signup' => env('SIGNUP_SMS',false), 'sms_signup' => env('SIGNUP_SMS',false),
'sms_url' => env('SMS_URL'), 'sms_url' => env('SMS_URL'),
'sms_user' => env('SMS_USER'), 'sms_user' => env('SMS_USER'),
'sms_pass' => env('SMS_PASS'), 'sms_pass' => env('SMS_PASS'),
'sms_number' => env('SMS_NUMBER'), 'sms_number' => env('SMS_NUMBER'),
'pay_gate' => env('PAY_GATWAY'), 'pay_gate' => env('PAY_GATWAY','zarinpal'),
'thumbnail_size' => env('THUMBNAIL_SIZE','600x600'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

@ -3,11 +3,11 @@
{ {
"@context": "http://schema.org", "@context": "http://schema.org",
"@type": "WebSite", "@type": "WebSite",
"url": "https://shop.ir/", "url": "{{config('app.url')}}",
"name": "{{\SEOMeta::getTitle()}}", "name": "{{\SEOMeta::getTitle()}}",
"author": { "author": {
"@type": "Person", "@type": "Person",
"name": "gold" "name": "{{config('app.name')}}",
}, },
"description": "{{\SEOMeta::getTitle()}}" "description": "{{\SEOMeta::getTitle()}}"
} }

Loading…
Cancel
Save