Feat: Shipping functionalities redesign, elta courier integration, commenting out acs since no integration can happen, flow updates
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Shipping\Carriers\Manual;
|
||||
|
||||
use Lunar\Models\Order;
|
||||
use Lunar\Shipping\Models\ShippingMethod;
|
||||
use Modules\Core\Shipping\Contracts\CarrierFulfillmentInterface;
|
||||
use Modules\Core\Shipping\DTOs\ShipmentRequest;
|
||||
use Modules\Core\Shipping\Models\Shipment;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Shipments of a manual carrier (ManualRateDriver): recorded here only,
|
||||
* with no carrier API. The carrier's name and tracking URL template are
|
||||
* copied from the shipping method into the shipment's meta, so links keep
|
||||
* working if the method is edited later. Tracking updates are added by
|
||||
* staff from the order page.
|
||||
*/
|
||||
class ManualFulfillmentService implements CarrierFulfillmentInterface
|
||||
{
|
||||
public function createShipment(Order $order, ShipmentRequest $request): Shipment
|
||||
{
|
||||
$code = $order->shippingAddress?->shipping_option;
|
||||
$method = $code ? ShippingMethod::where('code', $code)->first() : null;
|
||||
|
||||
return Shipment::create([
|
||||
'order_id' => $order->id,
|
||||
'carrier' => 'manual',
|
||||
'source' => Shipment::SOURCE_MANUAL,
|
||||
'tracking_reference' => filled($request->trackingReference) ? trim($request->trackingReference) : null,
|
||||
'meta' => [
|
||||
'carrier_name' => $method?->data['carrier_name'] ?? null,
|
||||
'tracking_url' => $method?->data['tracking_url'] ?? null,
|
||||
'package_count' => $request->packageCount,
|
||||
'weight' => $request->weight,
|
||||
'cod_amount' => $request->paymentMode === 'cod'
|
||||
? (float) ($request->amountToCollect ?? $order->total->decimal)
|
||||
: null,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function printLabel(Shipment $shipment): string
|
||||
{
|
||||
throw new RuntimeException('Manual carriers have no printable label.');
|
||||
}
|
||||
|
||||
public function cancelShipment(Shipment $shipment): void
|
||||
{
|
||||
$shipment->update(['cancelled_at' => now()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Shipping\Carriers\Manual;
|
||||
|
||||
use Lunar\DataTypes\ShippingOption;
|
||||
use Lunar\Shipping\DataTransferObjects\ShippingOptionRequest;
|
||||
use Lunar\Shipping\Interfaces\ShippingRateInterface;
|
||||
use Lunar\Shipping\Models\ShippingMethod;
|
||||
use Lunar\Shipping\Models\ShippingRate;
|
||||
use Modules\Core\Shipping\Concerns\ExcludesRestrictedProducts;
|
||||
use Modules\Core\Shipping\Concerns\ResolvesFixedPricing;
|
||||
use Modules\Core\Shipping\Contracts\DeclaresFulfillmentType;
|
||||
use Modules\Core\Shipping\Contracts\SupportsCashCollection;
|
||||
|
||||
/**
|
||||
* A carrier we have no integration with (e.g. Geniki), added by the
|
||||
* merchant as a shipping method with this driver. The method's `data`
|
||||
* holds the carrier's details, set in the admin
|
||||
* (ShippingMethodResourceExtension):
|
||||
*
|
||||
* - carrier_name: shown to staff and customers on its shipments;
|
||||
* - tracking_url: optional link template, `{number}` = the voucher number;
|
||||
* - collects_cash: whether its courier takes cash on delivery.
|
||||
*
|
||||
* Priced like Store Pickup / Box Now (charge_by + price breaks); its
|
||||
* shipments are created and tracked by hand (ManualFulfillmentService).
|
||||
*/
|
||||
class ManualRateDriver implements ShippingRateInterface, DeclaresFulfillmentType, SupportsCashCollection
|
||||
{
|
||||
use ResolvesFixedPricing;
|
||||
use ExcludesRestrictedProducts;
|
||||
|
||||
public ShippingRate $shippingRate;
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'Manual carrier';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'A carrier without an integration — shipments are entered and tracked by hand.';
|
||||
}
|
||||
|
||||
public function fulfillmentType(): string
|
||||
{
|
||||
return 'carrier';
|
||||
}
|
||||
|
||||
public function collectsCash(ShippingMethod $method): bool
|
||||
{
|
||||
return (bool) ($method->data['collects_cash'] ?? false);
|
||||
}
|
||||
|
||||
public function resolve(ShippingOptionRequest $shippingOptionRequest): ?ShippingOption
|
||||
{
|
||||
if ($this->cartHasExcludedProducts($shippingOptionRequest->shippingRate, $shippingOptionRequest->cart)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->resolveFixedPrice(
|
||||
$shippingOptionRequest->shippingRate,
|
||||
$shippingOptionRequest->shippingRate->shippingMethod,
|
||||
$shippingOptionRequest->cart,
|
||||
);
|
||||
}
|
||||
|
||||
public function on(ShippingRate $shippingRate): self
|
||||
{
|
||||
$this->shippingRate = $shippingRate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user