Add all files
This commit is contained in:
70
Disabled/ProductPageBuilder/Models/ProductPageSettings.php
Normal file
70
Disabled/ProductPageBuilder/Models/ProductPageSettings.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Others\ProductPageBuilder\Models;
|
||||
|
||||
use App\Models\Category;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductPageSettings extends Model
|
||||
{
|
||||
protected $table = 'ext_product_page_builder';
|
||||
|
||||
protected $fillable = [
|
||||
'hero_section',
|
||||
'features',
|
||||
'pricing_tables',
|
||||
'seo',
|
||||
'category_id',
|
||||
'game_preview',
|
||||
'game_panel',
|
||||
'faqs',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'hero_section' => 'array',
|
||||
'features' => 'array',
|
||||
'pricing_tables' => 'array',
|
||||
'seo' => 'array',
|
||||
'game_preview' => 'array',
|
||||
'game_panel' => 'array',
|
||||
'faqs' => 'array',
|
||||
];
|
||||
|
||||
protected function heroSection(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn ($value) => json_decode($value, true) ?? [],
|
||||
set: fn ($value) => json_encode($value),
|
||||
);
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function getMinPriceDetailsAttribute()
|
||||
{
|
||||
if (!$this->category) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$minPrice = $this->category->products()
|
||||
->join('plans', function ($join) {
|
||||
$join->on('plans.priceable_id', '=', 'products.id')
|
||||
->where('plans.priceable_type', '=', 'App\\Models\\Product');
|
||||
})
|
||||
->join('prices', function ($join) {
|
||||
$join->on('prices.plan_id', '=', 'plans.id');
|
||||
})
|
||||
->select('prices.price', 'prices.currency_code')
|
||||
->orderBy('prices.price', 'asc')
|
||||
->first();
|
||||
|
||||
return $minPrice ? [
|
||||
'price' => $minPrice->price,
|
||||
'currency_code' => $minPrice->currency_code,
|
||||
] : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user