【发布时间】:2018-07-07 19:42:14
【问题描述】:
我为 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/di.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>
app/code/Myweb/RemoveParentCategoryPathPlugin/etc/module.xml 内容是
<?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>
app/code/Myweb/RemoveParentCategoryPathPlugin/registration.php 内容是
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Myweb_RemoveParentCategoryPathPlugin',
__DIR__
);
我正在努力寻找,我错过了什么。
【问题讨论】:
标签: magento2