找不到Magento2插件类路径

找不到Magento2插件类路径,magento2,Magento2,我已经为Magento2创建了一个插件来删除父类别路径,但出现如下错误: Fatal error: Uncaught Error: Class 'Myweb\RemoveParentCategoryPathPlugin\Plugin\Category' not found in /public_html/app/code/Myweb/RemoveParentCategoryPathPlugin/Plugin/RemoveParentCategoryPathPlugin.php:8 St

我已经为Magento2创建了一个插件来删除父类别路径,但出现如下错误:

  Fatal error: Uncaught Error: Class 
'Myweb\RemoveParentCategoryPathPlugin\Plugin\Category' not found in 

/public_html/app/code/Myweb/RemoveParentCategoryPathPlugin/Plugin/RemoveParentCategoryPathPlugin.php:8 Stack trace: #0 

/public_html/vendor/magento/framework/Interception/Interceptor.php(135):

 Myweb\RemoveParentCategoryPathPlugin\Plugin\RemoveParentCategoryPathPlugin->aroundGetUrlPath(Object(Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator\Interceptor),
 Object(Closure), Object(MGS\Mpanel\Model\Category\Interceptor)) #1 

/public_html/vendor/magento/framework/Interception/Interceptor.php(153): 

Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator\Interceptor->Magento\Framework\Interception\{closure}

(Object(MGS\Mpanel\Model\Category\Interceptor)) #2 

/public_html/generated/code/Magento/CatalogUrlRewrite/Model/CategoryUrlPathGenerator/Interceptor.php(26): 

Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator\Interceptor->___cal in /public_html/app/code/Myweb/RemoveParentCategoryPathPlugin/Plugin/RemoveParentCategoryPathPlugin.php on line 8
我的插件模块文件如下:

app/code/Myweb/RemoveParentCategoryPathPlugin/Plugin/RemoveParentCategoryPathPlugin.php

<?php
namespace Myweb\RemoveParentCategoryPathPlugin\Plugin;

class RemoveParentCategoryPathPlugin
{
    public function aroundGetUrlPath($subject, $proceed, $category)
    {
        if (in_array($category->getParentId(), [Category::ROOT_CATEGORY_ID, Category::TREE_ROOT_ID])) {
            return '';
        }
        $path = $category->getUrlPath();
        if ($path !== null && !$category->dataHasChangedFor('url_key') && !$category->dataHasChangedFor('parent_id')) {
            return $path;
        }
        $path = $category->getUrlKey();
        if ($path === false) {
            return $category->getUrlPath();
        }
        return $path;
    }
}
app/code/Myweb/RemoveParentCategoryPathPlugin/etc/module.xml
内容如下

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator">
        <plugin name="Myweb_RemoveParentCategoryPathPlugin" type="Myweb\RemoveParentCategoryPathPlugin\Plugin\RemoveParentCategoryPathPlugin" />
    </type>
</config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Myweb_RemoveParentCategoryPathPlugin" setup_version="1.0.5" />
</config>
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Myweb_RemoveParentCategoryPathPlugin',
__DIR__
);

我正在努力寻找我遗漏的内容。

在您的插件类RemoveParentCategoryPathPlugin中,缺少Category类。
在文件中添加此行“use Magento\Catalog\Model\Category”。

在插件类RemoveParentCategoryPathPlugin中,缺少类别类。 在文件中添加此行“use Magento\Catalog\Model\Category”