1

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?

enter image description here

1

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";
    }               
}
0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.