2023-06-11 12:14:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Cart;
|
|
|
|
|
|
|
|
use Modules\Support\Money;
|
|
|
|
|
|
|
|
class CartShippingMethod
|
|
|
|
{
|
|
|
|
private $cart;
|
|
|
|
private $shippingMethodCondition;
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
public function __construct($cart, $shippingMethodCondition)
|
|
|
|
{
|
|
|
|
$this->cart = $cart;
|
|
|
|
$this->shippingMethodCondition = $shippingMethodCondition;
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
public function name()
|
|
|
|
{
|
|
|
|
return $this->shippingMethodCondition->getAttribute('shipping_method')->name;
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
public function label()
|
|
|
|
{
|
|
|
|
return $this->shippingMethodCondition->getAttribute('shipping_method')->label;
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
public function cost()
|
|
|
|
{
|
|
|
|
return Money::inDefaultCurrency($this->calculate());
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function calculate()
|
|
|
|
{
|
|
|
|
return $this->shippingMethodCondition->getCalculatedValue($this->cart->subTotal()->amount());
|
|
|
|
}
|
|
|
|
}
|