This commit is contained in:
2025-09-25 03:03:31 +05:00
commit ae480cf2f6
2768 changed files with 1485826 additions and 0 deletions

View 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;
}
}

View 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);
}
}

View 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]);
}
}