diff --git a/beike/Services/ShippingMethodService.php b/beike/Services/ShippingMethodService.php index e57fccf2..932f05be 100644 --- a/beike/Services/ShippingMethodService.php +++ b/beike/Services/ShippingMethodService.php @@ -29,6 +29,7 @@ class ShippingMethodService $shippingMethods = []; foreach ($shippingPlugins as $shippingPlugin) { + $plugin = $shippingPlugin->plugin; $pluginCode = $shippingPlugin->code; $pluginName = Str::studly($pluginCode); $className = "Plugin\\{$pluginName}\\Bootstrap"; @@ -38,7 +39,11 @@ class ShippingMethodService } $quotes = (new $className)->getQuotes($currentCart, $shippingPlugin); if ($quotes) { - $shippingMethods[$pluginCode] = $quotes; + $shippingMethods[] = [ + 'code' => $pluginCode, + 'name' => $plugin->name, + 'quotes' => $quotes + ]; } } return $shippingMethods; diff --git a/beike/Shop/Services/CheckoutService.php b/beike/Shop/Services/CheckoutService.php index 71db93ca..c00f583c 100644 --- a/beike/Shop/Services/CheckoutService.php +++ b/beike/Shop/Services/CheckoutService.php @@ -55,6 +55,7 @@ class CheckoutService * * @param $requestData ['shipping_address_id'=>1, 'payment_address_id'=>2, 'shipping_method'=>'code', 'payment_method'=>'code'] * @return array + * @throws \Exception */ public function update($requestData): array { diff --git a/beike/Shop/Services/TotalServices/ShippingService.php b/beike/Shop/Services/TotalServices/ShippingService.php index 9ecff530..09b166fc 100644 --- a/beike/Shop/Services/TotalServices/ShippingService.php +++ b/beike/Shop/Services/TotalServices/ShippingService.php @@ -24,11 +24,12 @@ class ShippingService return null; } - $pluginCode = Str::studly($shippingMethod); + $methodArray = explode('.', $shippingMethod); + $pluginCode = Str::studly($methodArray[0]); $className = "Plugin\\{$pluginCode}\\Bootstrap"; if (!method_exists($className, 'getShippingFee')) { - throw new \Exception("请在插件 {$className} 实现方法 getShippingFee"); + throw new \Exception("请在插件 {$className} 实现方法: public function getShippingFee(\$totalService)"); } $amount = (float)(new $className)->getShippingFee($totalService); $totalData = [ diff --git a/plugins/FlatShipping/Bootstrap.php b/plugins/FlatShipping/Bootstrap.php index fe243745..c360a69c 100644 --- a/plugins/FlatShipping/Bootstrap.php +++ b/plugins/FlatShipping/Bootstrap.php @@ -11,8 +11,6 @@ namespace Plugin\FlatShipping; -use Beike\Shop\Http\Resources\Checkout\ShippingMethodItem; - class Bootstrap { /** @@ -21,10 +19,19 @@ class Bootstrap * @param $currentCart * @param $shippingPlugin * @return array + * @throws \Exception */ public function getQuotes($currentCart, $shippingPlugin): array { - $quotes['flat_shipping.0'] = (new ShippingMethodItem($shippingPlugin))->jsonSerialize(); + $code = 'flat_shipping'; + $pluginSetting = $shippingPlugin->plugin; + $quotes[] = [ + 'type' => 'shipping', + 'code' => "{$code}.0", + 'name' => $pluginSetting->name, + 'description' => $pluginSetting->description, + 'icon' => plugin_resize($code, $pluginSetting->icon), + ]; return $quotes; } diff --git a/themes/default/checkout.blade.php b/themes/default/checkout.blade.php index f9b35de1..d389f22c 100644 --- a/themes/default/checkout.blade.php +++ b/themes/default/checkout.blade.php @@ -128,18 +128,20 @@
{{ __('shop/checkout.delivery_method') }}
-
-
-
- - -
-
-
@{{ shipping.name }}
-
+
+
+
+
+ + +
+
+
@{{ shipping.name }}
+
+