Using observer how to set catalog categories content Add CMS Block (category.description) programmatically
My observer:
<?php
namespace Zero\DescBlock\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
/**
* Class CollectionObserver
* @package Vendor\Module\Observer
*/
class CollectionObserver implements ObserverInterface
{
/**
* @var \Magento\Catalog\Model\Layer\Resolver
*/
protected $layerResolver;
/**
* CollectionObserver constructor.
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
*/
public function __construct(
\Magento\Catalog\Model\Layer\Resolver $layerResolver
) {
$this->layerResolver = $layerResolver;
}
/**
* @param Observer $observer
*/
public function execute(Observer $observer)
{
$layer = $this->layerResolver->get();
$activeFilters = $layer->getState()->getFilters();
foreach ($activeFilters as $filter)
{
$filterLabel = $filter->getLabel();
$filterValue = $filter->getValue();
}
}
}
Condition : Here my filterLabel is, apple and orange if filterLabel is apple i need to set cms block identifier my_apple if orange cms block identifier my_orange.
I am added cms block to Product listing page category description section,.
path :
app\design\frontend\Zero\mytheme\Magento_Catalog\layout\catalog_category_view.xml
<referenceContainer name="content">
<block class="Magento\Cms\Block\Block" name="category.description">
<arguments>
<argument name="block_id" xsi:type="string">cms_block_identifier</argument>
</arguments>
</block>
</referenceContainer>
How to merge into my observer?