4
Magento 2:覆盖块文件Magento \ ConfigurableProduct \ Block \ Product \ View \ Type \ Configurable.php
如何重写function getAllowProducts()从Magento\ConfigurableProduct\Block\Product\View\Type\Configurable.php在Magento 2。 我想覆盖上面的功能,但不更改功能,没有任何显示任何问题。日志文件中没有任何错误显示。 我将在这里分享我的代码, registration.php 文件, <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Test_Configuration', __DIR__ ); 等文件夹, 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="Test_Configuration" setup_version="1.0.0"/> </config> 我在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\ConfigurableProduct\Block\Product\View\Type\Configurable" type="Test\Configuration\Block\Outstock" /> </config> 阻止文件夹, Outstock.php文件, <?php namespace Test\Configuration\Block; class Outstock extends \Magento\ConfigurableProduct\Block\Product\View\Type\Configurable { public function getAllowProducts() …