| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Models; |
| 4 |
|
| 5 |
/** |
| 6 |
* Meta Model - DB Model for Meta table |
| 7 |
* |
| 8 |
* Database Model |
| 9 |
* |
| 10 |
* |
| 11 |
* @version 1.0.0 |
| 12 |
*/ |
| 13 |
class OrderTaxRate extends Model |
| 14 |
{ |
| 15 |
protected $table = 'fct_order_tax_rate'; |
| 16 |
|
| 17 |
protected $primaryKey = 'id'; |
| 18 |
|
| 19 |
protected $guarded = ['id']; |
| 20 |
|
| 21 |
protected $fillable = [ |
| 22 |
'order_id', |
| 23 |
'tax_rate_id', |
| 24 |
'shipping_tax', |
| 25 |
'order_tax', |
| 26 |
'total_tax', |
| 27 |
'meta', |
| 28 |
'filed_at', |
| 29 |
]; |
| 30 |
|
| 31 |
public function setMetaAttribute($value) |
| 32 |
{ |
| 33 |
if ($value) { |
| 34 |
$decoded = \json_encode($value, true); |
| 35 |
if (!($decoded)) { |
| 36 |
$decoded = '[]'; |
| 37 |
} |
| 38 |
} else { |
| 39 |
$decoded = '[]'; |
| 40 |
} |
| 41 |
|
| 42 |
$this->attributes['meta'] = $decoded; |
| 43 |
} |
| 44 |
|
| 45 |
public function getMetaAttribute($value) |
| 46 |
{ |
| 47 |
if (!$value) { |
| 48 |
return []; |
| 49 |
} |
| 50 |
|
| 51 |
return \json_decode($value, true); |
| 52 |
} |
| 53 |
|
| 54 |
public function order() |
| 55 |
{ |
| 56 |
return $this->belongsTo(Order::class, 'order_id', 'id'); |
| 57 |
} |
| 58 |
|
| 59 |
public function tax_rate() |
| 60 |
{ |
| 61 |
return $this->belongsTo(TaxRate::class, 'tax_rate_id', 'id'); |
| 62 |
} |
| 63 |
|
| 64 |
public function scopeValidOrder($query) |
| 65 |
{ |
| 66 |
return $query->whereHas('order', fn ($o) => $o->whereIn('payment_status', ['paid', 'partially_paid'])); |
| 67 |
} |
| 68 |
} |
| 69 |
|