I want to use CMS blocks inside product attributes, eg in description and short description.
- inside product description I've added
{{block id="test1"}}
. - i have two observer
catalog_product_collection_load_after
for collectionscatalog_controller_product_view
for products
Observer:
public function execute(Observer $observer): void
{
$product = $observer->getProduct();
$this->helper->parse($product);
}
Helper:
use Magento\Cms\Model\Template\FilterProvider
...
public function __construct(Context $context, FilterProvider $filterProvider)
{
$this->filterProvider = $filterProvider;
parent::__construct($context);
}
public function parse(Product $product): void
{
# some code to get attribute code and value
...
$attributeValue = $this->insertCmsBlocks($product, $attributeCode, $attributeValue);
$product->setData($attributeCode, $attributeValue);
}
public function insertCmsBlocks(Product $product, string $attributeCode, string $attributeValue): string
{
...
$attributeValue = $this->filterProvider->getBlockFilter()->filter($attributeValue);
...
return $attributeValue;
}
Category page
This works w/o any problems ...
Product page
Instead of default LUMA theme product page "compare" and "wishlist" block is loaded ...
block_html
andfull_page
is disabled ...$this->filterProvider->getBlockFilter()->filter($attributeValue)
looks ok when debugging
If I comment $this->filterProvider->getBlockFilter()->filter($attributeValue)
everthing works ... so, there is no problem with the event, cache or $product->setData()
...
Any ideas whats wrong with this code?
\Magento\Catalog\Block\Product\View\Description::getProduct
and what does the description holds? Maybe it's changed to default somewhere. And last thing, you cleared the cache right? :)