I want to get selected attributes in product listing page using observer,
app\code\Zero\DescBlock\registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Zero_DescBlock', __DIR__ );
app\code\Zero\DescBlock\etc\frontend\events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="catalog_product_collection_load_before">
<observer name="ChangeDescBlock" instance="Zero\DescBlock\Observer\Data" />
</event>
</config>
app\code\Zero\DescBlock\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="Zero_DescBlock" setup_version="1.0.0"/>
</config>
app\code\Zero\DescBlock\Observer\Data.php
<?php
namespace Zero\DescBlock\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Catalog\Model\Layer\Resolver as LayerResolver;
class Data implements ObserverInterface
{
protected $catalogLayer;
public function __construct( LayerResolver $layerResolver
) {
$this->catalogLayer = $layerResolver->get();
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$layer = $this->catalogLayer;
$activeFilters = $layer->getState()->getFilters();
$this->logger->info(print_r( $activeFilters, true));
}
}
The logger not return selected attributes.