FleetCart/Modules/Shipping/Method.php

40 lines
798 B
PHP
Raw Normal View History

2023-06-11 12:14:03 +00:00
<?php
namespace Modules\Shipping;
use Modules\Support\Money;
use Modules\Cart\Facades\Cart;
class Method
{
public $name;
public $label;
public $cost;
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
public function __construct($name, $label, $cost)
{
$this->name = $name;
$this->label = $label;
$this->cost = Money::inDefaultCurrency($cost);
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
public function available()
{
if ($this->name !== 'free_shipping') {
return true;
}
return $this->freeShippingMethodIsAvailable();
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
private function freeShippingMethodIsAvailable()
{
$minimumAmount = Money::inDefaultCurrency(setting('free_shipping_min_amount'));
return Cart::subTotal()->greaterThanOrEqual($minimumAmount);
}
}