The first thing you want to do is create a class which extends ListProduct
.
In your custom module's Vendor/Module/Block/Product/ListProduct.php
class ListProduct extends \Magento\Catalog\Block\ListProduct {
public function myOwnMethod() { … }
}
And then, you need to replace the references to that block in the layout. I believe the layout that uses this block is catalog_category_view, so in your module's Vendor/Module/view/frontend/layout/catalog_category_view.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="category.products.list" remove="true"/>
<block class="Vendor\Module\Block\Product\ListProduct" name="category.products.list.extend" as="product_list" template="Vendor_Module::product/list.phtml">
<container name="category.product.list.additional" as="additional" />
<block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
<block class="Magento\Framework\View\Element\Template" name="category.product.type.details.renderers.default" as="default"/>
</block>
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="category.product.addto" as="addto">
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
name="category.product.addto.compare" as="compare"
template="Magento_Catalog::product/list/addto/compare.phtml"/>
</block>
<block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
<block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName">
<argument name="name" xsi:type="string">product_list_toolbar</argument>
</action>
</block>
</body>
</page>
Notice that this is nearly a perfect copy of the old catalog_category_view.xml but the previous block was removed, and replaced with a new block that has a different class and template
Magento\Catalog\Test\Block\Product\ListProduct
block class (if you want to keep functionality)