wip
This commit is contained in:
30
app/Models/Ecommerce/Product/Order/Concerns/HasPayments.php
Normal file
30
app/Models/Ecommerce/Product/Order/Concerns/HasPayments.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ecommerce\Product\Order\Concerns;
|
||||
|
||||
trait HasPayments
|
||||
{
|
||||
/**
|
||||
* Total price for order
|
||||
*/
|
||||
public function total(): float
|
||||
{
|
||||
return $this->items->sum('total');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return total order with shipping.
|
||||
*/
|
||||
public function fullPriceWithShipping(): string
|
||||
{
|
||||
return floatval($this->total()) + floatval($this->shippingPrice()) + floatval($this->additional_tax);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatted payment type
|
||||
*/
|
||||
public function formattedPaymentType(): string
|
||||
{
|
||||
return $this->paymentType?->name;
|
||||
}
|
||||
}
|
||||
32
app/Models/Ecommerce/Product/Order/Concerns/HasShipping.php
Normal file
32
app/Models/Ecommerce/Product/Order/Concerns/HasShipping.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ecommerce\Product\Order\Concerns;
|
||||
|
||||
use App\Models\Ecommerce\Product\Order\Shipping\OrderShipping;
|
||||
|
||||
trait HasShipping
|
||||
{
|
||||
/**
|
||||
* Shipping price
|
||||
*/
|
||||
public function shippingPrice(): int
|
||||
{
|
||||
return intval($this->shipping_price) ?: OrderShipping::priceFor($this->shipping_method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatted shipping method
|
||||
*/
|
||||
public function formattedShippingMethod(): string
|
||||
{
|
||||
return OrderShipping::formattedShippingMethod($this->shipping_method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Full address for the order
|
||||
*/
|
||||
public function fullAddress(): string
|
||||
{
|
||||
return OrderShipping::fullAddress($this->region, $this->province_id, $this->customer_address);
|
||||
}
|
||||
}
|
||||
72
app/Models/Ecommerce/Product/Order/Concerns/HasStatus.php
Normal file
72
app/Models/Ecommerce/Product/Order/Concerns/HasStatus.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user