Optimize plugin manager

This commit is contained in:
Edward Yang 2023-03-08 15:50:52 +08:00
parent b023ee7a1c
commit 873954614a
3 changed files with 19 additions and 4 deletions

View File

@ -136,6 +136,23 @@ class Manager
return $plugin;
}
/**
* Check plugin is active, include existed, installed and enabled
*
* @param $code
* @return bool
* @throws \Exception
*/
public function checkActive($code): bool
{
$plugin = $this->getPlugin($code);
if (empty($plugin) || ! $plugin->getInstalled() || ! $plugin->getEnabled()) {
return false;
}
return true;
}
/**
* 获取插件目录以及配置
*

View File

@ -32,8 +32,7 @@ class HomeController extends Controller
$paths = explode('::', $viewPath);
if (count($paths) == 2) {
$pluginCode = $paths[0];
$plugin = app('plugin')->getPlugin($pluginCode);
if (! $plugin || ! $plugin->getEnabled()) {
if (! app('plugin')->checkActive($pluginCode)) {
continue;
}
}

View File

@ -33,8 +33,7 @@ class ShippingService
$shippingPluginCode = self::parseShippingPluginCode($shippingMethod);
$pluginCode = Str::studly($shippingPluginCode);
$plugin = app('plugin')->getPlugin($shippingPluginCode);
if (empty($plugin) || ! $plugin->getInstalled() || ! $plugin->getEnabled()) {
if (! app('plugin')->checkActive($shippingPluginCode)) {
$cart = $checkout->cart;
$cart->shipping_method_code = '';
$cart->saveOrFail();