重构配送方式

This commit is contained in:
Edward Yang 2022-12-01 17:08:08 +08:00
parent 126755cf89
commit a6322880d0
5 changed files with 40 additions and 18 deletions

View File

@ -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'));

View File

@ -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;

View File

@ -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,

View File

@ -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 = [

View File

@ -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;
}