1

I'm overriding getProductCollection of ListProduct block to custom filter the collection dinamically depending on current customer session. First time it works perfectly but following times it gets cached and I can't override the collection. It filters collection by first iteration conditions.

My intention is that each time the client enters the catalog view this query is executed, since it filters the products by customer id.

How could I achieve that?

  • I need this too, can you show how you did this ? – Morgan Tartreau Oct 8 '18 at 15:17
  • In the layout catalog_category_view you need the next line: <block name="product_list" cacheable="false"/> In this way you deactivate the cache for this block – chdzma Oct 8 '18 at 15:24
  • Sorry, I was talking about the way you're overriding getProductCollection – Morgan Tartreau Oct 8 '18 at 15:27
  • I followed these steps: magento.stackexchange.com/questions/245218/… – chdzma Oct 8 '18 at 15:38
0

Use a Plugin for that :

app/code/Namespace/Module/etc/frontend/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="Namespace_Module:module_name" type="Namespace\Module\Plugin\Block\Product\ListProduct" sortOrder="1"/>
</type>

app/code/Namespace/Module/Plugin/Block/Product/ListProduct.php

<?php
namespace Namespace\Module\Plugin\Block\Product;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;

class ListProduct
{
 //put some logic
}
  • It is right. But once the page is cached the query does not run again unless a reindex is done. – chdzma Oct 8 '18 at 15:40
  • @chdzma did you get any solution of this? – Umar Mar 4 at 14:39

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.