diff --git a/beike/Repositories/PluginRepo.php b/beike/Repositories/PluginRepo.php index f1916412..5e999ddb 100644 --- a/beike/Repositories/PluginRepo.php +++ b/beike/Repositories/PluginRepo.php @@ -92,31 +92,31 @@ class PluginRepo /** * 获取所有配送方式 */ - public static function getShippingMethods(): array + public static function getShippingMethods() { $allPlugins = self::allPlugins(); return $allPlugins->where('type', 'shipping')->filter(function ($item) { $plugin = (new Manager)->getPlugin($item->code); if ($plugin) { - $item->plugin = $plugin->toArray(); + $item->plugin = $plugin; } return $plugin && $plugin->getEnabled(); - })->toArray(); + }); } /** * 获取所有支付方式 */ - public static function getPaymentMethods(): array + public static function getPaymentMethods() { $allPlugins = self::allPlugins(); return $allPlugins->where('type', 'payment')->filter(function ($item) { $plugin = (new Manager)->getPlugin($item->code); if ($plugin) { - $item->plugin = $plugin->toArray(); + $item->plugin = $plugin; } return $plugin && $plugin->getEnabled(); - })->toArray(); + }); } } diff --git a/beike/Shop/Http/Resources/Checkout/PaymentMethodItem.php b/beike/Shop/Http/Resources/Checkout/PaymentMethodItem.php new file mode 100644 index 00000000..d345be88 --- /dev/null +++ b/beike/Shop/Http/Resources/Checkout/PaymentMethodItem.php @@ -0,0 +1,27 @@ +plugin; + return [ + 'type' => $this->type, + 'code' => $this->code, + 'name' => $pluginSetting->name, + 'description' => $pluginSetting->description, + 'icon' => $pluginSetting->icon, + ]; + } +} diff --git a/beike/Shop/Http/Resources/Checkout/ShippingMethodItem.php b/beike/Shop/Http/Resources/Checkout/ShippingMethodItem.php new file mode 100644 index 00000000..03134ef3 --- /dev/null +++ b/beike/Shop/Http/Resources/Checkout/ShippingMethodItem.php @@ -0,0 +1,27 @@ +plugin; + return [ + 'type' => $this->type, + 'code' => $this->code, + 'name' => $pluginSetting->name, + 'description' => $pluginSetting->description, + 'icon' => $pluginSetting->icon, + ]; + } +} diff --git a/beike/Shop/Services/CheckoutService.php b/beike/Shop/Services/CheckoutService.php index 1899ae9c..739820e5 100644 --- a/beike/Shop/Services/CheckoutService.php +++ b/beike/Shop/Services/CheckoutService.php @@ -15,6 +15,8 @@ use Beike\Repositories\AddressRepo; use Beike\Repositories\PluginRepo; use Beike\Repositories\SettingRepo; use Beike\Repositories\CountryRepo; +use Beike\Shop\Http\Resources\Checkout\PaymentMethodItem; +use Beike\Shop\Http\Resources\Checkout\ShippingMethodItem; class CheckoutService { @@ -23,8 +25,8 @@ class CheckoutService $customer = current_customer(); $addresses = AddressRepo::listByCustomer(current_customer()); - $shipments = PluginRepo::getShippingMethods(); - $payments = PluginRepo::getPaymentMethods(); + $shipments = ShippingMethodItem::collection(PluginRepo::getShippingMethods())->jsonSerialize(); + $payments = PaymentMethodItem::collection(PluginRepo::getPaymentMethods())->jsonSerialize(); $cartList = CartService::list($customer, true); $carts = CartService::reloadData($cartList);