FleetCart/Modules/Shipping/Providers/ShippingServiceProvider.php

63 lines
1.5 KiB
PHP
Raw Normal View History

2023-06-11 12:14:03 +00:00
<?php
namespace Modules\Shipping\Providers;
use Modules\Shipping\Method;
use Illuminate\Support\ServiceProvider;
use Modules\Shipping\Facades\ShippingMethod;
class ShippingServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
2023-12-03 14:07:47 +00:00
public function boot(): void
2023-06-11 12:14:03 +00:00
{
2023-12-03 14:07:47 +00:00
if (!config('app.installed')) {
2023-06-11 12:14:03 +00:00
return;
}
$this->registerFreeShipping();
$this->registerLocalPickup();
$this->registerFlatRate();
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
private function registerFreeShipping()
{
2023-12-03 14:07:47 +00:00
if (!setting('free_shipping_enabled')) {
2023-06-11 12:14:03 +00:00
return;
}
ShippingMethod::register('free_shipping', function () {
return new Method('free_shipping', setting('free_shipping_label'), 0);
});
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
private function registerLocalPickup()
{
2023-12-03 14:07:47 +00:00
if (!setting('local_pickup_enabled')) {
2023-06-11 12:14:03 +00:00
return;
}
ShippingMethod::register('local_pickup', function () {
return new Method('local_pickup', setting('local_pickup_label'), setting('local_pickup_cost'));
});
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
private function registerFlatRate()
{
2023-12-03 14:07:47 +00:00
if (!setting('flat_rate_enabled')) {
2023-06-11 12:14:03 +00:00
return;
}
ShippingMethod::register('flat_rate', function () {
return new Method('flat_rate', setting('flat_rate_label'), setting('flat_rate_cost'));
});
}
}