diff --git a/beike/Repositories/CartRepo.php b/beike/Repositories/CartRepo.php index c409de43..55cbe048 100644 --- a/beike/Repositories/CartRepo.php +++ b/beike/Repositories/CartRepo.php @@ -24,7 +24,7 @@ class CartRepo * 创建购物车 * * @param $customer - * @return Builder|Model|object|null + * @return Cart */ public static function createCart($customer) { diff --git a/beike/Shop/Services/TotalServices/ShippingService.php b/beike/Shop/Services/TotalServices/ShippingService.php index 427448c6..3347987e 100644 --- a/beike/Shop/Services/TotalServices/ShippingService.php +++ b/beike/Shop/Services/TotalServices/ShippingService.php @@ -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)"); }