Cara mengganti function getAllowProducts()dari Magento\ConfigurableProduct\Block\Product\View\Type\Configurable.phpdi magento 2.
Saya ingin mengganti fungsi di atas tetapi tidak mendapatkan perubahan fungsi dan tidak ada yang menampilkan masalah apa pun. Tidak ada tampilan kesalahan di dalam file log.
saya akan membagikan kode saya di sini,
registration.php mengajukan,
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Test_Configuration',
__DIR__
);
folder dll,
module.xml
kode adalah,
<?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>
Saya telah menimpa blok di dalam
di.xmlkode
<?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>
Blokir folder,
Outstock.phpfile,
<?php
namespace Test\Configuration\Block;
class Outstock extends \Magento\ConfigurableProduct\Block\Product\View\Type\Configurable
{
public function getAllowProducts()
{
if (!$this->hasAllowProducts()) {
$products = [];
$skipSaleableCheck = $this->catalogProduct->getSkipSaleableCheck();
$allProducts = $this->getProduct()->getTypeInstance()->getUsedProducts($this->getProduct(), null);
foreach ($allProducts as $product) {
$products[] = $product;
}
$this->setAllowProducts($products);
}
return $this->getData('allow_products');
}
protected function _toHtml()
{
$this->setModuleName($this->extractModuleName('Magento\ConfigurableProduct\Block\Product\View\Type\Configurable'));
return parent::_toHtml();
}
}
i havent setiap tampilan kesalahan tidak menghasilkan log untuk file dan modul ini diaktifkan. setup_moduleentri dalam dihasilkan.
Setiap saran untuk mengganti fungsi configurable.phpfile.
Terima kasih.