62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace Modules\Core\Shipping\Carriers\BoxNow;
|
||
|
|
|
||
|
|
use Lunar\DataTypes\ShippingOption;
|
||
|
|
use Lunar\Facades\Pricing;
|
||
|
|
use Lunar\Shipping\DataTransferObjects\ShippingOptionRequest;
|
||
|
|
use Lunar\Shipping\Interfaces\ShippingRateInterface;
|
||
|
|
use Lunar\Shipping\Models\ShippingRate;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Box Now has no pricing API, so this always resolves the admin-configured
|
||
|
|
* price/price-breaks on the ShippingRate — the same mechanism the built-in
|
||
|
|
* flat-rate driver uses. Unlike AcsRateDriver, this does not implement
|
||
|
|
* SupportsLivePricing: there is nothing to toggle between.
|
||
|
|
*/
|
||
|
|
class BoxNowRateDriver implements ShippingRateInterface
|
||
|
|
{
|
||
|
|
public ShippingRate $shippingRate;
|
||
|
|
|
||
|
|
public function name(): string
|
||
|
|
{
|
||
|
|
return 'Box Now Locker Delivery';
|
||
|
|
}
|
||
|
|
|
||
|
|
public function description(): string
|
||
|
|
{
|
||
|
|
return 'Deliver to a Box Now parcel locker.';
|
||
|
|
}
|
||
|
|
|
||
|
|
public function resolve(ShippingOptionRequest $shippingOptionRequest): ?ShippingOption
|
||
|
|
{
|
||
|
|
$shippingRate = $shippingOptionRequest->shippingRate;
|
||
|
|
$shippingMethod = $shippingRate->shippingMethod;
|
||
|
|
$cart = $shippingOptionRequest->cart;
|
||
|
|
|
||
|
|
$subTotal = $cart->lines->sum('subTotal.value');
|
||
|
|
|
||
|
|
$pricing = Pricing::for($shippingRate)->qty($subTotal)->get();
|
||
|
|
|
||
|
|
if (! $pricing->matched) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
return new ShippingOption(
|
||
|
|
name: $shippingMethod->name ?: $this->name(),
|
||
|
|
description: $shippingMethod->description ?: $this->description(),
|
||
|
|
identifier: $shippingRate->getIdentifier(),
|
||
|
|
price: $pricing->matched->price,
|
||
|
|
taxClass: $shippingRate->getTaxClass(),
|
||
|
|
taxReference: $shippingRate->getTaxReference(),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function on(ShippingRate $shippingRate): self
|
||
|
|
{
|
||
|
|
$this->shippingRate = $shippingRate;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
}
|