I want to add custom code in my catalog category view page. I don't want to override product/list.phml file .
But, Just display my custom code in catagory view page after product price.
How to add it?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI want to add custom code in my catalog category view page. I don't want to override product/list.phml file .
But, Just display my custom code in catagory view page after product price.
How to add it?
I find one way. Maybe It'll helpful for you.
Create di.xml file at /app/code/Vendor/Module/etc/frontend/di.xml
:
<type name="Magento\Catalog\Block\Product\ListProduct">
<plugin name="block-product-list" type="Vender\Module\Plugin\ProductList"/>
</type>
Create Plugin file ProductList.php at /app/code/Vendor/Module/Plugin
:
<?php
namespace Vender\Module\Plugin;
class ProductList
{
public function aroundGetProductDetailsHtml(
\Magento\Catalog\Block\Product\ListProduct $subject,
\Closure $proceed,
\Magento\Catalog\Model\Product $product
) {
echo "call";
}
}
Add the below code in calatog_category_view.xml
and replace the block name and template name with your custom block and template name
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">
<block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="category.product.addto" as="addto">
<block as="product_list_blockname"
class="<vendor>\<module>\Block\Product\<ClassName>"
name="product.list.<ClassName>"
template="<template path>"/>
</block>
</block>
</block>
</referenceContainer>
</body>
</page>