From bb346ab5848220d9568ae038463258c47366e468 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Wed, 7 Dec 2022 16:53:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E9=85=8D=E9=80=81=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=85=B3=E9=97=AD=E6=88=96=E5=8D=B8=E8=BD=BD=EF=BC=8C?= =?UTF-8?q?=E5=88=99=E9=87=8D=E6=96=B0=E8=AE=A1=E7=AE=97=E8=BF=90=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Repositories/CartRepo.php | 2 +- .../Services/TotalServices/ShippingService.php | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) 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)"); }