73 lines
1.4 KiB
PHP
73 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Ecommerce\Product\Order\Concerns;
|
|
|
|
use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
|
|
|
|
trait HasStatus
|
|
{
|
|
/**
|
|
* Return the correct order status formatted.
|
|
*/
|
|
public function formatted_status(): string
|
|
{
|
|
return OrderStatus::formattedStatusFor($this->status);
|
|
}
|
|
|
|
/**
|
|
* Can order be cancelled?
|
|
*/
|
|
public function canBeCancelled(): bool
|
|
{
|
|
return $this->isPending();
|
|
}
|
|
|
|
/**
|
|
* Check if order is pending
|
|
*/
|
|
public function isPending(): bool
|
|
{
|
|
return $this->status === OrderStatus::PENDING;
|
|
}
|
|
|
|
/**
|
|
* Check if order is registered
|
|
*/
|
|
public function isRegistered(): bool
|
|
{
|
|
return $this->status === OrderStatus::REGISTER;
|
|
}
|
|
|
|
/**
|
|
* Check if order is paid
|
|
*/
|
|
public function isPaid(): bool
|
|
{
|
|
return $this->status === OrderStatus::PAID;
|
|
}
|
|
|
|
/**
|
|
* Check if order is completed
|
|
*/
|
|
public function isCompleted(): bool
|
|
{
|
|
return $this->status === OrderStatus::COMPLETED;
|
|
}
|
|
|
|
/**
|
|
* Check if order is completed
|
|
*/
|
|
public function isCancelled(): bool
|
|
{
|
|
return $this->status === OrderStatus::CANCELLED;
|
|
}
|
|
|
|
/**
|
|
* Mark order as paid
|
|
*/
|
|
public function markAsPaid(): void
|
|
{
|
|
$this->update(['status' => OrderStatus::PAID]);
|
|
}
|
|
}
|