diff --git a/beike/Plugin/Manager.php b/beike/Plugin/Manager.php index 14511247..08ea964b 100644 --- a/beike/Plugin/Manager.php +++ b/beike/Plugin/Manager.php @@ -48,6 +48,7 @@ class Manager $status = $plugin->getStatus(); $plugin->setDirname($dirname); $plugin->setName(Arr::get($package, 'name')); + $plugin->setDescription(Arr::get($package, 'description')); $plugin->setInstalled(true); $plugin->setEnabled($status); $plugin->setVersion(Arr::get($package, 'version')); diff --git a/beike/Plugin/Plugin.php b/beike/Plugin/Plugin.php index 7cb7c23c..9b992a60 100644 --- a/beike/Plugin/Plugin.php +++ b/beike/Plugin/Plugin.php @@ -22,6 +22,7 @@ class Plugin implements Arrayable, \ArrayAccess { protected $path; protected $name; + protected $description; protected $packageInfo; protected $dirName; protected $installed; @@ -64,6 +65,13 @@ class Plugin implements Arrayable, \ArrayAccess return $this; } + public function setDescription(string $description): Plugin + { + $this->description = $description; + return $this; + } + + public function setInstalled(bool $installed): Plugin { $this->installed = $installed; @@ -127,6 +135,16 @@ class Plugin implements Arrayable, \ArrayAccess } + public function getName(): string + { + return $this->name; + } + + public function getDescription(): string + { + return $this->description; + } + public function getDirname(): string { return $this->dirName; diff --git a/beike/Services/ShippingMethodService.php b/beike/Services/ShippingMethodService.php index 932f05be..6db6eb7e 100644 --- a/beike/Services/ShippingMethodService.php +++ b/beike/Services/ShippingMethodService.php @@ -13,17 +13,18 @@ namespace Beike\Services; use Illuminate\Support\Str; use Beike\Repositories\PluginRepo; +use Beike\Shop\Services\CheckoutService; class ShippingMethodService { /** * 获取配送方式, 二维数组, 一个配送插件对应多个配送方式 * - * @param $currentCart + * @param CheckoutService $checkout * @return array * @throws \Exception */ - public static function getShippingMethods($currentCart): array + public static function getShippingMethods(CheckoutService $checkout): array { $shippingPlugins = PluginRepo::getShippingMethods(); @@ -37,7 +38,7 @@ class ShippingMethodService if (!method_exists($className, 'getQuotes')) { throw new \Exception("请在插件 {$className} 实现方法: public function getQuotes(\$currentCart)"); } - $quotes = (new $className)->getQuotes($currentCart, $shippingPlugin); + $quotes = (new $className)->getQuotes($checkout, $plugin); if ($quotes) { $shippingMethods[] = [ 'code' => $pluginCode, diff --git a/beike/Shop/Services/CheckoutService.php b/beike/Shop/Services/CheckoutService.php index c00f583c..9434a5dd 100644 --- a/beike/Shop/Services/CheckoutService.php +++ b/beike/Shop/Services/CheckoutService.php @@ -27,9 +27,9 @@ use Beike\Shop\Http\Resources\Checkout\PaymentMethodItem; class CheckoutService { - private $customer; - private $cart; - private $selectedProducts; + public $customer; + public $cart; + public $selectedProducts; /** @@ -167,13 +167,13 @@ class CheckoutService $customer = $this->customer; $currentCart = $this->cart; - $addresses = AddressRepo::listByCustomer($customer); - $shipments = ShippingMethodService::getShippingMethods($currentCart); - $payments = PaymentMethodItem::collection(PluginRepo::getPaymentMethods())->jsonSerialize(); - $cartList = CartService::list($customer, true); $carts = CartService::reloadData($cartList); + $addresses = AddressRepo::listByCustomer($customer); + $shipments = ShippingMethodService::getShippingMethods($this); + $payments = PaymentMethodItem::collection(PluginRepo::getPaymentMethods())->jsonSerialize(); + $totalService = (new TotalService($currentCart, $cartList)); $data = [ diff --git a/plugins/FlatShipping/Bootstrap.php b/plugins/FlatShipping/Bootstrap.php index c360a69c..7bd3ae9e 100644 --- a/plugins/FlatShipping/Bootstrap.php +++ b/plugins/FlatShipping/Bootstrap.php @@ -11,26 +11,28 @@ namespace Plugin\FlatShipping; +use Beike\Plugin\Plugin; +use Beike\Shop\Services\CheckoutService; + class Bootstrap { /** * 获取固定运费方式 * - * @param $currentCart - * @param $shippingPlugin + * @param CheckoutService $checkout + * @param Plugin $plugin * @return array * @throws \Exception */ - public function getQuotes($currentCart, $shippingPlugin): array + public function getQuotes(CheckoutService $checkout, Plugin $plugin): array { - $code = 'flat_shipping'; - $pluginSetting = $shippingPlugin->plugin; + $code = $plugin->code; $quotes[] = [ 'type' => 'shipping', 'code' => "{$code}.0", - 'name' => $pluginSetting->name, - 'description' => $pluginSetting->description, - 'icon' => plugin_resize($code, $pluginSetting->icon), + 'name' => $plugin->getName(), + 'description' => $plugin->getDescription(), + 'icon' => plugin_resize($code, $plugin->icon), ]; return $quotes; }