2025-11-21 10:49:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Blax\Shop\Models;
|
|
|
|
|
|
2025-11-23 14:07:12 +00:00
|
|
|
use Blax\Shop\Contracts\Cartable;
|
|
|
|
|
use Blax\Shop\Contracts\Purchasable;
|
2025-11-21 10:49:41 +00:00
|
|
|
use Blax\Workkit\Traits\HasMetaTranslation;
|
|
|
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
2025-11-23 14:07:12 +00:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2025-11-21 10:49:41 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
2025-11-23 14:07:12 +00:00
|
|
|
class ProductPrice extends Model implements Cartable
|
2025-11-21 10:49:41 +00:00
|
|
|
{
|
2025-11-23 14:07:12 +00:00
|
|
|
use HasFactory, HasUuids, HasMetaTranslation;
|
2025-11-21 10:49:41 +00:00
|
|
|
|
|
|
|
|
protected $fillable = [
|
2025-11-23 14:07:12 +00:00
|
|
|
'purchasable_type',
|
|
|
|
|
'purchasable_id',
|
2025-11-21 10:49:41 +00:00
|
|
|
'stripe_price_id',
|
|
|
|
|
'name',
|
|
|
|
|
'type',
|
2025-11-23 14:07:12 +00:00
|
|
|
'currency',
|
|
|
|
|
'unit_amount',
|
|
|
|
|
'sale_unit_amount',
|
2025-11-21 10:49:41 +00:00
|
|
|
'is_default',
|
2025-11-23 14:07:12 +00:00
|
|
|
'active',
|
2025-11-21 10:49:41 +00:00
|
|
|
'billing_scheme',
|
|
|
|
|
'interval',
|
|
|
|
|
'interval_count',
|
|
|
|
|
'trial_period_days',
|
|
|
|
|
'meta',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'is_default' => 'boolean',
|
|
|
|
|
'active' => 'boolean',
|
2025-11-23 14:07:12 +00:00
|
|
|
'meta' => 'object',
|
|
|
|
|
'unit_amount' => 'float',
|
|
|
|
|
'sale_unit_amount' => 'float',
|
|
|
|
|
'interval_count' => 'integer',
|
|
|
|
|
'trial_period_days' => 'integer',
|
2025-11-21 10:49:41 +00:00
|
|
|
];
|
|
|
|
|
|
2025-11-23 14:07:12 +00:00
|
|
|
public function purchasable()
|
2025-11-21 10:49:41 +00:00
|
|
|
{
|
2025-11-23 14:07:12 +00:00
|
|
|
return $this->morphTo();
|
2025-11-21 10:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeIsActive($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('active', true);
|
|
|
|
|
}
|
2025-11-24 13:32:11 +00:00
|
|
|
|
2025-11-25 16:02:39 +00:00
|
|
|
public function getCurrentPrice($sale_price): float
|
2025-11-24 13:32:11 +00:00
|
|
|
{
|
2025-11-25 16:02:39 +00:00
|
|
|
if ($sale_price) {
|
2025-11-24 13:32:11 +00:00
|
|
|
return $this->sale_unit_amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->unit_amount;
|
|
|
|
|
}
|
2025-11-21 10:49:41 +00:00
|
|
|
}
|