diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 182a407d2..eb1643f79 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -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; } diff --git a/packages/Webkul/Shipping/src/Carriers/AbstractShipping.php b/packages/Webkul/Shipping/src/Carriers/AbstractShipping.php index 8394be99b..13b0bcb3c 100755 --- a/packages/Webkul/Shipping/src/Carriers/AbstractShipping.php +++ b/packages/Webkul/Shipping/src/Carriers/AbstractShipping.php @@ -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 + * @param string $field * @return mixed */ public function getConfigData($field) diff --git a/packages/Webkul/Shipping/src/Carriers/FlatRate.php b/packages/Webkul/Shipping/src/Carriers/FlatRate.php index 5d342aa03..aa36b1692 100755 --- a/packages/Webkul/Shipping/src/Carriers/FlatRate.php +++ b/packages/Webkul/Shipping/src/Carriers/FlatRate.php @@ -14,11 +14,13 @@ use Webkul\Checkout\Facades\Cart; class FlatRate extends AbstractShipping { /** - * Payment method code + * Shipping method code * * @var string */ - protected $code = 'flatrate'; + 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'); diff --git a/packages/Webkul/Shipping/src/Carriers/Free.php b/packages/Webkul/Shipping/src/Carriers/Free.php index a90b053bb..c33f0db5b 100755 --- a/packages/Webkul/Shipping/src/Carriers/Free.php +++ b/packages/Webkul/Shipping/src/Carriers/Free.php @@ -13,11 +13,13 @@ use Webkul\Shipping\Facades\Shipping; class Free extends AbstractShipping { /** - * Payment method code + * Shipping method code * * @var string */ - protected $code = 'free'; + protected $code = 'free'; + + protected $method = 'free_free'; /** * Returns rate for flatrate diff --git a/packages/Webkul/Shipping/src/Shipping.php b/packages/Webkul/Shipping/src/Shipping.php index 3d1dc7151..aaac7e124 100755 --- a/packages/Webkul/Shipping/src/Shipping.php +++ b/packages/Webkul/Shipping/src/Shipping.php @@ -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() ];