first upload all files
This commit is contained in:
30
Modules/Shipping/Facades/ShippingMethod.php
Normal file
30
Modules/Shipping/Facades/ShippingMethod.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Shipping\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Support\Collection available()
|
||||
* @method static \Illuminate\Support\Collection all()
|
||||
* @method static array names()
|
||||
* @method static object get(string $name)
|
||||
* @method static \Modules\Shipping\ShippingMethodManager register(string $name, callable|object $driver)
|
||||
* @method static int count()
|
||||
* @method static bool isEmpty()
|
||||
* @method static bool isNotEmpty()
|
||||
*
|
||||
* @see \Modules\Shipping\ShippingMethodManager
|
||||
*/
|
||||
class ShippingMethod extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return \Modules\Shipping\ShippingMethodManager::class;
|
||||
}
|
||||
}
|
||||
36
Modules/Shipping/Method.php
Normal file
36
Modules/Shipping/Method.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Shipping;
|
||||
|
||||
use Modules\Support\Money;
|
||||
use Modules\Cart\Facades\Cart;
|
||||
|
||||
class Method
|
||||
{
|
||||
public $name;
|
||||
public $label;
|
||||
public $cost;
|
||||
|
||||
public function __construct($name, $label, $cost)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->label = $label;
|
||||
$this->cost = Money::inDefaultCurrency($cost);
|
||||
}
|
||||
|
||||
public function available()
|
||||
{
|
||||
if ($this->name !== 'free_shipping') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->freeShippingMethodIsAvailable();
|
||||
}
|
||||
|
||||
private function freeShippingMethodIsAvailable()
|
||||
{
|
||||
$minimumAmount = Money::inDefaultCurrency(setting('free_shipping_min_amount'));
|
||||
|
||||
return Cart::subTotal()->greaterThanOrEqual($minimumAmount);
|
||||
}
|
||||
}
|
||||
59
Modules/Shipping/Providers/ShippingServiceProvider.php
Normal file
59
Modules/Shipping/Providers/ShippingServiceProvider.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if (! config('app.installed')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->registerFreeShipping();
|
||||
$this->registerLocalPickup();
|
||||
$this->registerFlatRate();
|
||||
}
|
||||
|
||||
private function registerFreeShipping()
|
||||
{
|
||||
if (! setting('free_shipping_enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShippingMethod::register('free_shipping', function () {
|
||||
return new Method('free_shipping', setting('free_shipping_label'), 0);
|
||||
});
|
||||
}
|
||||
|
||||
private function registerLocalPickup()
|
||||
{
|
||||
if (! setting('local_pickup_enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShippingMethod::register('local_pickup', function () {
|
||||
return new Method('local_pickup', setting('local_pickup_label'), setting('local_pickup_cost'));
|
||||
});
|
||||
}
|
||||
|
||||
private function registerFlatRate()
|
||||
{
|
||||
if (! setting('flat_rate_enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShippingMethod::register('flat_rate', function () {
|
||||
return new Method('flat_rate', setting('flat_rate_label'), setting('flat_rate_cost'));
|
||||
});
|
||||
}
|
||||
}
|
||||
13
Modules/Shipping/ShippingMethodManager.php
Normal file
13
Modules/Shipping/ShippingMethodManager.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Shipping;
|
||||
|
||||
use Modules\Support\Manager;
|
||||
|
||||
class ShippingMethodManager extends Manager
|
||||
{
|
||||
public function available()
|
||||
{
|
||||
return $this->all()->filter->available();
|
||||
}
|
||||
}
|
||||
27
Modules/Shipping/composer.json
Normal file
27
Modules/Shipping/composer.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "fleetcart/shipping",
|
||||
"description": "The FleetCart Shipping Module.",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Envay Soft",
|
||||
"email": "envaysoft@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.0.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\Shipping\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
9
Modules/Shipping/module.json
Normal file
9
Modules/Shipping/module.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "Shipping",
|
||||
"alias": "shipping",
|
||||
"description": "The FleetCart Shipping Module.",
|
||||
"priority": 100,
|
||||
"providers": [
|
||||
"Modules\\Shipping\\Providers\\ShippingServiceProvider"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user