Merge pull request #5306 from AmooAti/shipping-method-validation
Shipping method validation
This commit is contained in:
commit
e7da9ed9f6
|
|
@ -446,6 +446,10 @@ class Cart
|
|||
return false;
|
||||
}
|
||||
|
||||
if (! array_key_exists($shippingMethodCode, Shipping::getShippingMethods())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cart->shipping_method = $shippingMethodCode;
|
||||
$cart->save();
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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