Feature: Order Updates, Events, Order Flows, Shipment And COD support

This commit is contained in:
2026-09-14 00:03:06 +03:00
parent 78bbd8390a
commit 44c6b7defd
73 changed files with 2854 additions and 464 deletions
+27 -10
View File
@@ -65,24 +65,34 @@ class ShippingServiceProvider extends ServiceProvider
__DIR__ . '/../../config/shippingCarriers/boxnow.php' => config_path('shippingCarriers/boxnow.php'),
], 'core-config');
// Signed-URL auth only, same model as Lunar's own vendor
// lunar.pdf.download route — see Modules\Core\Shipping\Http\
// Controllers\DownloadShipmentLabelController's own docblock.
$this->loadRoutesFrom(__DIR__ . '/../Shipping/routes/web.php');
Order::resolveRelationUsing('shipments', function ($order) {
return $order->hasMany(Shipment::class);
});
// ShippingMethod.data['fulfillment_type'] — see
// ShippingMethodResourceExtension::fulfillmentTypeSelect() for
// where it's set. Defaults to 'carrier' (false here) for any row
// saved before this field existed.
ShippingMethod::macro('isStorePickup', function () {
/** @var ShippingMethod $this */
return ($this->data['fulfillment_type'] ?? 'carrier') === 'store_pickup';
});
// Order has no direct ShippingMethod relation — shippingAddress.
// shipping_option is only ever a code string (see
// Modules\Core\Shipping\Extensions\OrderViewExtension::
// resolveCarrier() for the same lookup pattern already used to
// resolve a carrier driver from it).
//
// Reads ShippingMethod.data['fulfillment_type'] directly rather
// than through a ShippingMethod::macro('isStorePickup', ...) —
// Lunar\Base\Traits\HasModelExtending::__callStatic() (used by
// Lunar\Shipping\Models\ShippingMethod via Lunar\Base\BaseModel)
// intercepts EVERY unmatched static call, including macro()
// itself, and dispatches it as (new static)->macro(...) instead
// of forwarding to Macroable — so a macro registered this way
// silently never gets stored, and hasMacro() always returns
// false. (Lunar\Models\Order is unaffected because it declares
// its own macro() method directly, bypassing __callStatic
// entirely — that's why Order::macro('isStorePickupOrder', ...)
// below still works.) Defaults to 'carrier' (false) for any row
// saved before this field existed.
Order::macro('isStorePickupOrder', function () {
/** @var Order $this */
$code = $this->shippingAddress?->shipping_option;
@@ -91,7 +101,14 @@ class ShippingServiceProvider extends ServiceProvider
return false;
}
return ShippingMethod::where('code', $code)->first()?->isStorePickup() ?? false;
// ->value('data') is deliberately avoided here — on Postgres,
// ->value()/->pluck() on a JSON column silently return the
// wrong result (works fine in ->where(), not in a column
// projection); loading the model and reading its cast
// attribute avoids that entirely.
$method = ShippingMethod::where('code', $code)->first();
return ($method?->data['fulfillment_type'] ?? 'carrier') === 'store_pickup';
});
foreach ([CartLineAdded::class, CartLineUpdated::class, CartLineRemoved::class, CartCleared::class, ShippingAddressSet::class] as $event) {