2018-09-13 11:10:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-09-19 06:58:15 +00:00
|
|
|
namespace Webkul\Shipping\Carriers;
|
2018-09-13 11:10:45 +00:00
|
|
|
|
|
|
|
|
use Config;
|
2018-09-28 13:28:54 +00:00
|
|
|
use Webkul\Checkout\Models\CartShippingRate;
|
2018-09-21 10:17:01 +00:00
|
|
|
use Webkul\Shipping\Facades\Shipping;
|
2018-12-26 14:03:01 +00:00
|
|
|
use Webkul\Checkout\Facades\Cart;
|
2018-09-13 11:10:45 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class Rate.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class FlatRate extends AbstractShipping
|
|
|
|
|
{
|
2018-09-20 10:01:51 +00:00
|
|
|
/**
|
2021-11-08 12:52:58 +00:00
|
|
|
* Shipping method carrier code
|
2018-09-20 10:01:51 +00:00
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2021-11-08 07:45:12 +00:00
|
|
|
protected $code = 'flatrate';
|
|
|
|
|
|
2021-11-08 12:52:58 +00:00
|
|
|
/**
|
|
|
|
|
* Shipping method code
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2021-11-08 07:45:12 +00:00
|
|
|
protected $method = 'flatrate_flatrate';
|
2018-09-20 10:01:51 +00:00
|
|
|
|
2018-09-26 04:21:14 +00:00
|
|
|
/**
|
|
|
|
|
* Returns rate for flatrate
|
|
|
|
|
*
|
2020-04-17 09:09:59 +00:00
|
|
|
* @return CartShippingRate|false
|
2018-09-26 04:21:14 +00:00
|
|
|
*/
|
2018-09-13 11:10:45 +00:00
|
|
|
public function calculate()
|
|
|
|
|
{
|
2020-02-20 06:54:38 +00:00
|
|
|
if (! $this->isAvailable()) {
|
2018-09-21 10:17:01 +00:00
|
|
|
return false;
|
2020-02-20 06:54:38 +00:00
|
|
|
}
|
2018-09-21 10:17:01 +00:00
|
|
|
|
2018-12-26 14:03:01 +00:00
|
|
|
$cart = Cart::getCart();
|
|
|
|
|
|
2018-09-26 04:21:14 +00:00
|
|
|
$object = new CartShippingRate;
|
2018-09-20 10:01:51 +00:00
|
|
|
|
2018-09-21 10:17:01 +00:00
|
|
|
$object->carrier = 'flatrate';
|
|
|
|
|
$object->carrier_title = $this->getConfigData('title');
|
2021-11-08 07:45:12 +00:00
|
|
|
$object->method = $this->method;
|
2018-09-20 10:01:51 +00:00
|
|
|
$object->method_title = $this->getConfigData('title');
|
|
|
|
|
$object->method_description = $this->getConfigData('description');
|
2020-12-18 07:30:13 +00:00
|
|
|
$object->is_calculate_tax = $this->getConfigData('is_calculate_tax');
|
2019-06-28 14:18:52 +00:00
|
|
|
$object->price = 0;
|
|
|
|
|
$object->base_price = 0;
|
2018-12-26 14:03:01 +00:00
|
|
|
|
|
|
|
|
if ($this->getConfigData('type') == 'per_unit') {
|
2019-06-28 14:18:52 +00:00
|
|
|
foreach ($cart->items as $item) {
|
2019-08-20 12:27:39 +00:00
|
|
|
if ($item->product->getTypeInstance()->isStockable()) {
|
2019-06-28 14:18:52 +00:00
|
|
|
$object->price += core()->convertPrice($this->getConfigData('default_rate')) * $item->quantity;
|
|
|
|
|
$object->base_price += $this->getConfigData('default_rate') * $item->quantity;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-26 14:03:01 +00:00
|
|
|
} else {
|
|
|
|
|
$object->price = core()->convertPrice($this->getConfigData('default_rate'));
|
|
|
|
|
$object->base_price = $this->getConfigData('default_rate');
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-21 10:17:01 +00:00
|
|
|
return $object;
|
2018-09-13 11:10:45 +00:00
|
|
|
}
|
|
|
|
|
}
|