sarga/packages/Webkul/Shipping/src/Carriers/FlatRate.php

68 lines
1.8 KiB
PHP
Raw Normal View History

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;
use Webkul\Shipping\Facades\Shipping;
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
*/
protected $code = 'flatrate';
2021-11-08 12:52:58 +00:00
/**
* Shipping method code
*
* @var string
*/
protected $method = 'flatrate_flatrate';
2018-09-20 10:01:51 +00:00
2018-09-26 04:21:14 +00:00
/**
* Returns rate for flatrate
*
* @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()) {
return false;
2020-02-20 06:54:38 +00:00
}
$cart = Cart::getCart();
2018-09-26 04:21:14 +00:00
$object = new CartShippingRate;
2018-09-20 10:01:51 +00:00
$object->carrier = 'flatrate';
$object->carrier_title = $this->getConfigData('title');
$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;
if ($this->getConfigData('type') == 'per_unit') {
2019-06-28 14:18:52 +00:00
foreach ($cart->items as $item) {
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;
}
}
} else {
$object->price = core()->convertPrice($this->getConfigData('default_rate'));
$object->base_price = $this->getConfigData('default_rate');
}
return $object;
2018-09-13 11:10:45 +00:00
}
}