Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
18 / 21
62.50% covered (warning)
62.50%
5 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
Order
85.71% covered (warning)
85.71%
18 / 21
62.50% covered (warning)
62.50%
5 / 8
8.19
0.00% covered (danger)
0.00%
0 / 1
 casts
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
 tenant
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 store
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 integration
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 influencer
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 coupon
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 items
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 commission
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Models;
4
5use App\Enums\OrderStatus;
6use Illuminate\Database\Eloquent\Factories\HasFactory;
7use Illuminate\Database\Eloquent\Model;
8use Illuminate\Database\Eloquent\Relations\BelongsTo;
9use Illuminate\Database\Eloquent\Relations\HasMany;
10use Illuminate\Database\Eloquent\Relations\HasOne;
11
12class Order extends Model
13{
14    use HasFactory;
15
16    protected $fillable = [
17        'tenant_id', 'store_id', 'store_integration_id', 'influencer_id', 'coupon_id', 'external_id',
18        'order_number', 'status', 'coupon_code_original', 'coupon_code_normalized', 'products_amount',
19        'discount_amount', 'shipping_amount', 'paid_products_amount', 'total_amount',
20        'commission_base_amount', 'paid_at', 'cancelled_at', 'refunded_at', 'placed_at', 'metadata',
21    ];
22
23    protected function casts(): array
24    {
25        return [
26            'status' => OrderStatus::class,
27            'products_amount' => 'decimal:2',
28            'discount_amount' => 'decimal:2',
29            'shipping_amount' => 'decimal:2',
30            'paid_products_amount' => 'decimal:2',
31            'total_amount' => 'decimal:2',
32            'commission_base_amount' => 'decimal:2',
33            'paid_at' => 'datetime',
34            'cancelled_at' => 'datetime',
35            'refunded_at' => 'datetime',
36            'placed_at' => 'datetime',
37            'metadata' => 'array',
38        ];
39    }
40
41    public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); }
42    public function store(): BelongsTo { return $this->belongsTo(Store::class); }
43    public function integration(): BelongsTo { return $this->belongsTo(StoreIntegration::class, 'store_integration_id'); }
44    public function influencer(): BelongsTo { return $this->belongsTo(Influencer::class); }
45    public function coupon(): BelongsTo { return $this->belongsTo(InfluencerCoupon::class, 'coupon_id'); }
46    public function items(): HasMany { return $this->hasMany(OrderItem::class); }
47    public function commission(): HasOne { return $this->hasOne(Commission::class); }
48}