Feature: Shipping Carrier Additions, Creating a voucher without an order, verifying order details before creating voucher, ELTA Courier voucher print updates
This commit is contained in:
@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Lunar\Models\Order;
|
||||
use Lunar\Shipping\Facades\Shipping;
|
||||
use Modules\Core\Shipping\DTOs\VoucherRecipient;
|
||||
|
||||
class Shipment extends Model
|
||||
{
|
||||
@@ -51,6 +52,38 @@ class Shipment extends Model
|
||||
return $this->shipmentInfo()->latest('occurred_at')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Who the voucher goes to, as saved when it was created
|
||||
* (meta.recipient). Vouchers created before that was saved fall back to
|
||||
* their order's shipping address; an extra parcel of a multi-parcel
|
||||
* send falls back to its main voucher's.
|
||||
*/
|
||||
public function recipient(): ?VoucherRecipient
|
||||
{
|
||||
if (filled($this->meta['recipient'] ?? null)) {
|
||||
return VoucherRecipient::fromArray((array) $this->meta['recipient']);
|
||||
}
|
||||
|
||||
if ($address = $this->order?->shippingAddress) {
|
||||
return VoucherRecipient::fromAddress($address);
|
||||
}
|
||||
|
||||
$masterId = $this->meta['master_shipment_id'] ?? null;
|
||||
|
||||
return $masterId ? self::find($masterId)?->recipient() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The reference we sent the carrier with this voucher (saved since
|
||||
* 0.29.2); older vouchers were sent their order's reference.
|
||||
*/
|
||||
public function reference(): ?string
|
||||
{
|
||||
return filled($this->meta['reference'] ?? null)
|
||||
? (string) $this->meta['reference']
|
||||
: $this->order?->reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* The carrier's display name: a manual carrier's own name (snapshotted
|
||||
* from its shipping method), otherwise the shipping driver's name().
|
||||
@@ -135,6 +168,11 @@ class Shipment extends Model
|
||||
*/
|
||||
public function parcelDescription(): ?string
|
||||
{
|
||||
// Box Now: every box is its own voucher (no main voucher).
|
||||
if (($this->meta['boxes'] ?? 0) > 1) {
|
||||
return "Box {$this->meta['box']} of {$this->meta['boxes']}";
|
||||
}
|
||||
|
||||
$piece = $this->meta['piece'] ?? null;
|
||||
$pieces = $this->meta['pieces'] ?? null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user