diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 73042aa0e..0c0736029 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -446,6 +446,10 @@ class Cart return false; } + if (! array_key_exists($shippingMethodCode, Shipping::getShippingMethods())) { + return false; + } + $cart->shipping_method = $shippingMethodCode; $cart->save(); diff --git a/packages/Webkul/Shipping/src/Carriers/AbstractShipping.php b/packages/Webkul/Shipping/src/Carriers/AbstractShipping.php index 1639ba39c..1886f6409 100755 --- a/packages/Webkul/Shipping/src/Carriers/AbstractShipping.php +++ b/packages/Webkul/Shipping/src/Carriers/AbstractShipping.php @@ -4,10 +4,24 @@ namespace Webkul\Shipping\Carriers; abstract class AbstractShipping { + /** + * Shipping method carrier code + * + * @var string + */ + protected $code; + + /** + * Shipping method code + * + * @var string + */ + protected $method; + abstract public function calculate(); /** - * Checks if payment method is available + * Checks if shipping method is available * * @return array */ @@ -17,7 +31,7 @@ abstract class AbstractShipping } /** - * Returns payment method code + * Returns shipping method code * * @return array */ @@ -30,8 +44,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 */ @@ -41,7 +64,7 @@ abstract class AbstractShipping } /** - * Returns payment method decription + * Returns shipping method description * * @return array */ @@ -51,10 +74,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..4e2a5e20e 100755 --- a/packages/Webkul/Shipping/src/Carriers/FlatRate.php +++ b/packages/Webkul/Shipping/src/Carriers/FlatRate.php @@ -14,11 +14,18 @@ use Webkul\Checkout\Facades\Cart; class FlatRate extends AbstractShipping { /** - * Payment method code + * Shipping method carrier code * * @var string */ - protected $code = 'flatrate'; + protected $code = 'flatrate'; + + /** + * Shipping method code + * + * @var string + */ + protected $method = 'flatrate_flatrate'; /** * Returns rate for flatrate @@ -37,7 +44,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..7704d5bf6 100755 --- a/packages/Webkul/Shipping/src/Carriers/Free.php +++ b/packages/Webkul/Shipping/src/Carriers/Free.php @@ -13,11 +13,18 @@ use Webkul\Shipping\Facades\Shipping; class Free extends AbstractShipping { /** - * Payment method code + * Shipping method carrier code * * @var string */ - protected $code = 'free'; + protected $code = 'free'; + + /** + * Shipping method code + * + * @var string + */ + 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() ];