Feature: Shipment Updates to handle COD

This commit is contained in:
2026-07-19 18:27:24 +03:00
parent 435a4dd290
commit 9f30a7324e
5 changed files with 184 additions and 21 deletions
+17 -2
View File
@@ -9,6 +9,7 @@ use Lunar\Admin\Support\Extending\ViewPageExtension;
use Lunar\Models\Order;
use Lunar\Shipping\Models\ShippingMethod;
use Modules\Core\Shipping\Contracts\CarrierFulfillmentInterface;
use Modules\Core\Shipping\DataTransferObjects\ShipmentRequest;
class OrderViewExtension extends ViewPageExtension
{
@@ -26,6 +27,15 @@ class OrderViewExtension extends ViewPageExtension
->icon('heroicon-o-truck')
->modalSubmitActionLabel('Create Shipment')
->form([
Forms\Components\TextInput::make('weight')
->label('Package weight (kg)')
->numeric()
->minValue(0)
->helperText('Leave blank to use the carrier\'s default.'),
Forms\Components\TextInput::make('destination_location_id')
->label('Box Now locker ID')
->helperText('Only required for Box Now shipments.')
->default(fn (Order $record) => $record->shippingAddress?->meta['box_now_locker']['locationId'] ?? null),
Forms\Components\Toggle::make('confirm')
->label('Confirm')
->helperText('This will create a real shipment with the carrier.')
@@ -39,7 +49,7 @@ class OrderViewExtension extends ViewPageExtension
},
]),
])
->action(function (Order $record, Actions\Action $action) {
->action(function (Order $record, array $data, Actions\Action $action) {
$service = $this->resolveFulfillmentService($record);
if (! $service) {
@@ -53,8 +63,13 @@ class OrderViewExtension extends ViewPageExtension
return;
}
$request = new ShipmentRequest(
weight: filled($data['weight'] ?? null) ? (float) $data['weight'] : null,
destinationLocationId: $data['destination_location_id'] ?? null,
);
try {
$service->createShipment($record);
$service->createShipment($record, $request);
} catch (\Throwable $e) {
report($e);