Magento 2 : Swatches not display when use plugin around
-
13-02-2021 - |
سؤال
I used around plugin to call custom phtml in category list page. It's working proper. But, In configurable product it's hide to display swatches.
I upload here my files code. Which function should I need to use in plugin to working perfectly ?
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">
<type name="Magento\Catalog\Block\Product\ListProduct">
<plugin name="custom-module-category" type="Vendor\Module\Plugin\File" sortOrder="16"/>
</type>
<virtualType name="Magento\CatalogSearch\Block\SearchResult\ListProduct">
<plugin name="custom-module-search" type="Vendor\Module\Plugin\File" sortOrder="17" />
</virtualType>
</config>
File.php :
public function aroundGetProductDetailsHtml(
\Magento\Catalog\Block\Product\ListProduct $subject,
\Closure $proceed,
\Magento\Catalog\Model\Product $product
) {
$data = $this->_productDocFactory->create()->load($product->getId(), 'product_id');
if(count($data->getData())){
return $this->layout->createBlock('Vendor\Module\Block\File')->setProduct($data_id)->setTemplate('Vendor_Module::file.phtml')->toHtml();
} else {
return '';
}
}
المحلول
You didn't anything in else condition. So, it was display blank. Use this below code :
public function aroundGetProductDetailsHtml(
\Magento\Catalog\Block\Product\ListProduct $subject,
\Closure $proceed,
\Magento\Catalog\Model\Product $product
) {
$data = $this->_producyFactory->create()->load($product->getId(), 'product_id');
if (count($data->getData())) {
return $this->layout->createBlock('Vendor\Module\Block\File')->setProduct($data)->setTemplate('Vendor_Module::file.phtml')->toHtml();
} else {
$result = $proceed($product);
return $result;
}
}
لا تنتمي إلى magento.stackexchange