2

我试图覆盖

<preference for="Magento\Customer\Model\CustomerRegistry" type="Mycustom\Mymodule\Model\CustomerRegistry" />

在 etc/di.xml 下。但是运行后

php bin/magento 设置:升级

命令将收到“目录规则索引失败”错误消息。在 system.log 文件下,它将显示以下错误消息 -

创建对象时发生类型错误:Magento\Customer\Model\ResourceModel\AddressRepository,

注意:我已删除生成的文件夹并运行所有必需的命令。另外,我的magento版本是2.3。

4

2 回答 2

1

我有一个类似的问题,即对注入插件构造函数的类的偏好。

问题似乎是Magento开发者模式导致插件执行时没有生成所有DI数据,导致执行构造函数时出错,DI失败。

切换到默认模式似乎可以解决问题。

bin/magento deploy:mode:set default

无论如何,我最终更改了使用被覆盖类的类的实现,以便使用被首选项覆盖的自定义接口,并使用模块依赖项在修改后的模块依赖项(使用序列依赖项)加载我的新模块。

这不是最好的解决方案,但它有效,我可以这样做,因为这两个模块都来自我的公司,并且在 app/code 文件夹中实现。

如果可以的话,你应该使用插件而不是偏好。

于 2022-01-04T16:00:48.267 回答
0

I have had the same issue and after hours of searching I saw some of the classes can not be overridden. You can see more details about this issue here:

https://github.com/magento/magento2/issues/2674

I used magento "around" plugin instead of <preference/>.

于 2020-10-08T08:01:32.783 回答