Skip to content

Commit 79d2fe7

Browse files
committed
Added PriceStatus enum
1 parent d512fce commit 79d2fe7

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/Enums/PriceStatus.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Whitecube\LaravelPrices\Enums;
4+
5+
enum PriceStatus
6+
{
7+
case SCHEDULED;
8+
case CURRENT;
9+
case EXPIRED;
10+
}

src/Models/Price.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
use Illuminate\Database\Eloquent\Model;
88
use Whitecube\Price\Price as PriceObject;
99
use Whitecube\LaravelPrices\Concerns\HasUuid;
10-
use Whitecube\LaravelPrices\Exceptions\PriceValueNotDefinedException;
10+
use Whitecube\LaravelPrices\Enums\PriceStatus;
1111

1212
class Price extends Model
1313
{
1414
use HasUuid;
1515

16-
public $timestamps = ['activated_at'];
17-
1816
protected $guarded = [];
1917

2018
protected $casts = [
21-
'amount' => 'integer'
19+
'amount' => 'integer',
20+
'activated_at' => 'datetime',
2221
];
2322

2423
public function __construct(
@@ -80,17 +79,18 @@ public function toObject(): PriceObject
8079
return PriceObject::ofMinor($this->amount, $this->currency);
8180
}
8281

83-
public function getStatusAttribute()
82+
public function getStatusAttribute(): PriceStatus
8483
{
8584
if($this->activated_at > now()) {
86-
return 'programmed';
85+
return PriceStatus::SCHEDULED;
8786
}
8887

89-
$current = $this->priceable->price()->first();
90-
if($current->id == $this->id) {
91-
return 'current';
88+
$current = $this->priceable->price()->current()->first();
89+
90+
if ($current->id == $this->id) {
91+
return PriceStatus::CURRENT;
9292
}
9393

94-
return 'passed';
94+
return PriceStatus::EXPIRED;
9595
}
9696
}

0 commit comments

Comments
 (0)