I want to override the class
MagentoCatalogModelLayer
In my /etc/di.xml
<preference for="MagentoCatalogModelLayer" type="CustomModuleModelLayer" />
Then I did the class
<?php
namespace CustomModuleModel;
class Layer extends MagentoCatalogModelLayer
{
public function getProductCollection()
{
//Logic to modify the $collection data
return $collection;
}
}
And also etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vhl_Catalog" setup_version="1.0.28">
<sequence>
<module name="Magento_Catalog"/>
</sequence>
</module>
</config>
But this is not working. I know that I can use a plugin before or after getProductCollection but when I apply the filter
$collection->addAttributeToFilter('custom_attribute', ['neq' => 1]);
But the filter is not working as expected. If I change the scope in a custom attribute, the filter take the last saving value (It does not matter what scope) and not the current scope for store