Wie außer Kraft setzen function getAllowProducts()von Magento\ConfigurableProduct\Block\Product\View\Type\Configurable.phpin magento 2.
Ich möchte die obige Funktion überschreiben, bekomme aber keine Funktionsänderungen und nichts zeigt ein Problem an. In der Protokolldatei wird kein Fehler angezeigt.
Ich werde meinen Code hier teilen,
registration.php Datei,
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Test_Configuration',
__DIR__
);
etc Ordner,
module.xml
Code ist,
<?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>
Ich habe Override Block im
di.xmlCode ist
<?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>
Ordner,
Outstock.phpDatei blockieren,
<?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();
}
}
Ich habe keine Fehleranzeige, kein Protokoll für diese Datei generiert und das Modul ist aktiviert. Inneneintrag setup_modulewerden generiert.
Jeder Vorschlag für die Überschreibungsfunktion der configurable.phpDatei.
Vielen Dank.