如果配送插件关闭或卸载,则重新计算运费

This commit is contained in:
Edward Yang 2022-12-07 16:53:45 +08:00
parent 9f67ec43f0
commit bb346ab584
2 changed files with 13 additions and 4 deletions

View File

@ -24,7 +24,7 @@ class CartRepo
* 创建购物车
*
* @param $customer
* @return Builder|Model|object|null
* @return Cart
*/
public static function createCart($customer)
{

View File

@ -20,7 +20,7 @@ class ShippingService
/**
* @param CheckoutService $checkout
* @return array|null
* @throws \Exception
* @throws \Exception|\Throwable
*/
public static function getTotal(CheckoutService $checkout): ?array
{
@ -31,9 +31,18 @@ class ShippingService
}
$methodArray = explode('.', $shippingMethod);
$pluginCode = Str::studly($methodArray[0]);
$className = "Plugin\\{$pluginCode}\\Bootstrap";
$shippingPluginCode = $methodArray[0];
$pluginCode = Str::studly($shippingPluginCode);
$plugin = app('plugin')->getPlugin($shippingPluginCode);
if (empty($plugin) || !$plugin->getInstalled() || !$plugin->getEnabled()) {
$cart = $checkout->cart;
$cart->shipping_method_code = '';
$cart->saveOrFail();
return [];
}
$className = "Plugin\\{$pluginCode}\\Bootstrap";
if (!method_exists($className, 'getShippingFee')) {
throw new \Exception("请在插件 {$className} 实现方法: public function getShippingFee(CheckoutService \$checkout)");
}