-
Notifications
You must be signed in to change notification settings - Fork 462
Expand file tree
/
Copy pathCartLine.php
More file actions
152 lines (131 loc) · 3.27 KB
/
CartLine.php
File metadata and controls
152 lines (131 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace Lunar\Models;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Lunar\Base\BaseModel;
use Lunar\Base\Traits\CachesProperties;
use Lunar\Base\Traits\HasMacros;
use Lunar\Base\Traits\LogsActivity;
use Lunar\Base\ValueObjects\Cart\TaxBreakdown;
use Lunar\Database\Factories\CartLineFactory;
use Lunar\DataTypes\Price;
/**
* @property int $id
* @property int $cart_id
* @property string $purchasable_type
* @property int $purchasable_id
* @property int $quantity
* @property ?array $meta
* @property ?\Illuminate\Support\Carbon $created_at
* @property ?\Illuminate\Support\Carbon $updated_at
*/
class CartLine extends BaseModel implements Contracts\CartLine
{
use CachesProperties;
use HasFactory;
use HasMacros;
use LogsActivity;
/**
* Array of cachable class properties.
*
* @var array
*/
public $cachableProperties = [
'unitPrice',
'unitPriceInclTax',
'subTotal',
'discountTotal',
'taxAmount',
'total',
'promotionDescription',
'taxBreakdown',
];
/**
* The cart line unit price.
*/
public ?Price $unitPrice = null;
/**
* The cart line unit price.
*/
public ?Price $unitPriceInclTax = null;
/**
* The cart line sub total.
*/
public ?Price $subTotal = null;
/**
* The discounted sub total
*/
public ?Price $subTotalDiscounted = null;
/**
* The discount total.
*/
public ?Price $discountTotal = null;
/**
* The cart line tax amount.
*/
public ?Price $taxAmount = null;
/**
* The cart line total.
*/
public ?Price $total = null;
/**
* The promotion description.
*/
public string $promotionDescription = '';
/**
* All the tax breakdowns for the cart line.
*/
public TaxBreakdown $taxBreakdown;
/**
* Return a new factory instance for the model.
*/
protected static function newFactory()
{
return CartLineFactory::new();
}
/**
* Define which attributes should be
* protected from mass assignment.
*
* @var array
*/
protected $guarded = [];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'quantity' => 'integer',
'meta' => AsArrayObject::class,
];
public function cart(): BelongsTo
{
return $this->belongsTo(Cart::modelClass());
}
public function taxClass(): HasOneThrough
{
return $this->hasOneThrough(
TaxClass::modelClass(),
$this->purchasable_type,
'tax_class_id',
'id'
);
}
public function discounts(): BelongsToMany
{
$prefix = config('lunar.database.table_prefix');
return $this->belongsToMany(
Discount::modelClass(),
"{$prefix}cart_line_discount"
);
}
public function purchasable(): MorphTo
{
return $this->morphTo();
}
}