Files
isaacclad e709de6593
Deploy Ladill Woo Manager / deploy (push) Successful in 35s
Use WooCommerce store currency for product and order money.
Sync currency from the plugin, format product prices and totals with it, and show the store currency on product price fields instead of hard-coding GHS.
2026-07-24 15:38:07 +00:00

78 lines
2.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class WooOrder extends Model
{
public const FULFILLMENT_NEW = 'new';
public const FULFILLMENT_CONFIRMED = 'confirmed';
public const FULFILLMENT_PREPARING = 'preparing';
public const FULFILLMENT_READY = 'ready';
public const FULFILLMENT_DELIVERED = 'delivered';
public const FULFILLMENT_CANCELLED = 'cancelled';
public const FULFILLMENT_STATUSES = [
self::FULFILLMENT_NEW => 'New',
self::FULFILLMENT_CONFIRMED => 'Confirmed',
self::FULFILLMENT_PREPARING => 'Preparing',
self::FULFILLMENT_READY => 'Ready',
self::FULFILLMENT_DELIVERED => 'Delivered',
self::FULFILLMENT_CANCELLED => 'Cancelled',
];
protected $fillable = [
'woo_store_id',
'external_order_id',
'order_number',
'wc_status',
'payment_status',
'customer_name',
'customer_email',
'customer_phone',
'line_items',
'billing_address',
'shipping_address',
'currency',
'total_minor',
'fulfillment_status',
'wc_updated_at',
'metadata',
];
protected $casts = [
'line_items' => 'array',
'billing_address' => 'array',
'shipping_address' => 'array',
'metadata' => 'array',
'total_minor' => 'integer',
'wc_updated_at' => 'datetime',
];
public function store(): BelongsTo
{
return $this->belongsTo(WooStore::class, 'woo_store_id');
}
public function fulfillmentLabel(): string
{
return self::FULFILLMENT_STATUSES[$this->fulfillment_status ?? self::FULFILLMENT_NEW]
?? ucfirst((string) $this->fulfillment_status);
}
public function totalFormatted(): string
{
$minor = (int) $this->total_minor;
$currency = strtoupper(trim((string) ($this->currency ?: '')));
if ($currency === '' && ($this->relationLoaded('store') || $this->store)) {
$currency = $this->store->currency();
}
$amount = number_format($minor / 100, 2);
return $currency !== '' ? $currency.' '.$amount : $amount;
}
}