0
A
回答
0
//尝试用下面的代码进行帮助器覆盖。
步骤1:
app/code/YourCompany/YourModule/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Helper\Data" type="YourCompany\YourModule\Helper\Catalog\Data" />
</config>
步骤:2
Let’s rewrite getProduct() function of class Magento\Catalog\Helper\Data. We will just log some message on var/log/debug.log for this test.
<?php
namespace YourCompany\YourModule\Helper\Catalog;
class Data extends \Magento\Catalog\Helper\Data
{
/**
* Retrieve current Product object
*
* @return \Magento\Catalog\Model\Product|null
*/
public function getProduct()
{
// logging to test override
$logger = \Magento\Framework\App\ObjectManager::getInstance()->get('\Psr\Log\LoggerInterface');
$logger->debug('Helper Override Test');
return $this->_coreRegistry->registry('current_product');
}
}
?>
相关问题
- 1. 覆盖/扩展Magento核心JavaScript文件
- 2. Magento 2 - 覆盖基本视图文件
- 3. Firefox扩展覆盖注入JavaScript文件?
- 4. 如何覆盖Magento 2中的jquery.validate
- 5. 如何覆盖magento中的admin js文件2
- 6. 文本覆盖文本并可扩展。
- 7. Magento - 覆盖Adminhtml块
- 8. 如何扩展/覆盖symfony2 form_row函数
- 9. 定制magento扩展帮助
- 10. 如何创建Magento 2扩展?
- 11. 如何在magento 2上传扩展名
- 12. 覆盖扩展方法
- 13. (覆盖||扩展)JavaScript方法
- 14. 覆盖无需扩展类
- 15. 扩展方法覆盖
- 16. 从扩展Flexform覆盖TCEFORM
- 17. Opera扩展中的覆盖
- 18. Chrome扩展覆盖css
- 19. 覆盖和扩展原型
- 20. Playframework扩展/覆盖点
- 21. 扩展SKAction以覆盖timingMode
- 22. Magento - 覆盖“OnepageController.php”
- 23. 如何覆盖Magento控制器?
- 24. 扩展器覆盖Silverlight中的控件
- 25. 在控件扩展中,覆盖或addHandler?
- 26. Magento扩展的config.xml文件
- 27. 从内联助手调用扩展助手 - 如何?
- 28. MVC助手扩展问题
- 29. 如何覆盖gwt中扩展小部件的事件?
- 30. 如何覆盖magento 2中的页脚版权文本?