add method to shipping method attributes and better approach for checking if shipping method is available
This commit is contained in:
parent
44cb03e30c
commit
154808b181
|
|
@ -446,16 +446,7 @@ class Cart
|
|||
return false;
|
||||
}
|
||||
|
||||
$shippingMethods = Shipping::collectRates()['shippingMethods'];
|
||||
$isMethodAvailable = false;
|
||||
foreach ($shippingMethods as $shippingMethod) {
|
||||
foreach ($shippingMethod['rates'] as $rate)
|
||||
if ($rate->method == $shippingMethodCode) {
|
||||
$isMethodAvailable = true;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
if (!$isMethodAvailable) {
|
||||
if (!array_key_exists($shippingMethodCode, Shipping::getShippingMethods())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,15 @@
|
|||
|
||||
namespace Webkul\Shipping\Carriers;
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
abstract class AbstractShipping
|
||||
{
|
||||
protected $code;
|
||||
protected $method;
|
||||
|
||||
abstract public function calculate();
|
||||
|
||||
/**
|
||||
* Checks if payment method is available
|
||||
* Checks if shipping method is available
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -19,7 +20,7 @@ abstract class AbstractShipping
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns payment method code
|
||||
* Returns shipping method code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -32,8 +33,17 @@ abstract class AbstractShipping
|
|||
return $this->code;
|
||||
}
|
||||
|
||||
public function getMethod()
|
||||
{
|
||||
if (empty($this->method)) {
|
||||
// throw exception
|
||||
}
|
||||
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns payment method title
|
||||
* Returns shipping method title
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -43,7 +53,7 @@ abstract class AbstractShipping
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns payment method decription
|
||||
* Returns shipping method description
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -53,10 +63,9 @@ abstract class AbstractShipping
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve information from payment configuration
|
||||
* Retrieve information from shipping configuration
|
||||
*
|
||||
* @param string $field
|
||||
* @param int|string|null $channelId
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfigData($field)
|
||||
|
|
|
|||
|
|
@ -14,12 +14,14 @@ use Webkul\Checkout\Facades\Cart;
|
|||
class FlatRate extends AbstractShipping
|
||||
{
|
||||
/**
|
||||
* Payment method code
|
||||
* Shipping method code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $code = 'flatrate';
|
||||
|
||||
protected $method = 'flatrate_flatrate';
|
||||
|
||||
/**
|
||||
* Returns rate for flatrate
|
||||
*
|
||||
|
|
@ -37,7 +39,7 @@ class FlatRate extends AbstractShipping
|
|||
|
||||
$object->carrier = 'flatrate';
|
||||
$object->carrier_title = $this->getConfigData('title');
|
||||
$object->method = 'flatrate_flatrate';
|
||||
$object->method = $this->method;
|
||||
$object->method_title = $this->getConfigData('title');
|
||||
$object->method_description = $this->getConfigData('description');
|
||||
$object->is_calculate_tax = $this->getConfigData('is_calculate_tax');
|
||||
|
|
|
|||
|
|
@ -13,12 +13,14 @@ use Webkul\Shipping\Facades\Shipping;
|
|||
class Free extends AbstractShipping
|
||||
{
|
||||
/**
|
||||
* Payment method code
|
||||
* Shipping method code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $code = 'free';
|
||||
|
||||
protected $method = 'free_free';
|
||||
|
||||
/**
|
||||
* Returns rate for flatrate
|
||||
*
|
||||
|
|
|
|||
|
|
@ -130,8 +130,9 @@ class Shipping
|
|||
continue;
|
||||
}
|
||||
|
||||
$methods[] = [
|
||||
'method' => $object->getCode(),
|
||||
$methods[$object->getMethod()] = [
|
||||
'code' => $object->getCode(),
|
||||
'method' => $object->getMethod(),
|
||||
'method_title' => $object->getTitle(),
|
||||
'description' => $object->getDescription()
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue