首页 > 解决方案 > 如何覆盖 Magento 2 的 \lib 文件夹中的 PHP 类?

问题描述

我想覆盖 lib 文件夹中的 PHP 文件。例如,我想用我自己的 PHP 类MyProject/application/Lorem/Customweb/Model/Processor覆盖MyProject/application/lib/internal/Customweb/Computop/Processor/Payolution/ Processor 。推荐的方法是使用类首选项。我创建了一个模块、一个 di.xml 和 PHP 替换文件。di.xml 找到了我自己的类,但没有找到它应该替换的类:

应用程序/app/code/Lorem/Customweb/etc/di.xml

<?xml version="1.0" encoding="utf-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Customweb\Computop\Processor\Payolution\Processor" type="Lorem\Customweb\Model\Processor" />
</config>

我多次检查拼写,所有路径都是正确的。我究竟做错了什么?

标签: phpmagento2

解决方案


推荐阅读