|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/** |
| 3 | + * This file is part of the Magebit_StaticContentProcessor package |
| 4 | + * |
| 5 | + * DISCLAIMER |
| 6 | + * |
| 7 | + * Do not edit or add to this file if you wish to upgrade Magebit_StaticContentProcessor |
| 8 | + * to newer versions in the future. |
| 9 | + * |
| 10 | + * @copyright Copyright (c) 2021 Magebit (https://magebit.com/) |
| 11 | + * @author Kristofers Ozolins <info@magebit.com> |
| 12 | + * @license GNU General Public License ("GPL") v3.0 |
| 13 | + * |
| 14 | + * For the full copyright and license information, please view the LICENSE |
| 15 | + * file that was distributed with this source code. |
| 16 | + */ |
| 17 | + |
| 18 | +namespace Magebit\StaticContentProcessor\Model\Indexer\DataProvider\Category; |
| 19 | + |
| 20 | +use Divante\VsbridgeIndexerCatalog\Model\Category\GetAttributeCodesByIds; |
| 21 | +use Magento\Store\Model\ScopeInterface; |
| 22 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 23 | +use Divante\VsbridgeIndexerCms\Model\Indexer\DataProvider\CmsContentFilter; |
| 24 | +use Divante\VsbridgeIndexerCore\Api\DataProviderInterface; |
| 25 | + |
| 26 | +/** |
| 27 | + * Class WysiwygBlockData |
| 28 | + */ |
| 29 | +class WysiwygBlockData implements DataProviderInterface |
| 30 | +{ |
| 31 | + /** |
| 32 | + * @var CmsContentFilter |
| 33 | + */ |
| 34 | + private $cmsContentFilter; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var ScopeConfigInterface |
| 38 | + */ |
| 39 | + private $scopeConfig; |
| 40 | + |
| 41 | + /** |
| 42 | + * ContentData constructor. |
| 43 | + * |
| 44 | + * @param CmsContentFilter $cmsContentFilter |
| 45 | + */ |
| 46 | + public function __construct( |
| 47 | + CmsContentFilter $cmsContentFilter, |
| 48 | + ScopeConfigInterface $scopeConfig, |
| 49 | + GetAttributeCodesByIds $getAttributeCodesByIds |
| 50 | + ) { |
| 51 | + $this->cmsContentFilter = $cmsContentFilter; |
| 52 | + $this->scopeConfig = $scopeConfig; |
| 53 | + $this->getAttributeCodesByIds = $getAttributeCodesByIds; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @inheritdoc |
| 58 | + */ |
| 59 | + public function addData(array $indexData, $storeId) |
| 60 | + { |
| 61 | + $processable = []; |
| 62 | + |
| 63 | + $cmsContentAttributes = $this->scopeConfig->getValue( |
| 64 | + 'vsbridge_indexer_settings/url_rewrites/category_content_attributes', |
| 65 | + ScopeInterface::SCOPE_STORE |
| 66 | + ); |
| 67 | + |
| 68 | + if (is_string($cmsContentAttributes)) { |
| 69 | + $parseBlockIds = explode(',', $cmsContentAttributes); |
| 70 | + |
| 71 | + foreach ($indexData as $categoryId => $categoryData) { |
| 72 | + foreach ($categoryData as $attributeCode => $attribute) { |
| 73 | + if (in_array($attributeCode, $parseBlockIds) && is_string($attribute)) { |
| 74 | + $processable[] = [ |
| 75 | + 'categoryId' => $categoryId, |
| 76 | + 'attributeId' => $attributeCode, |
| 77 | + 'content' => $attribute |
| 78 | + ]; |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + $filteredIndexData = $this->cmsContentFilter->filter($processable, $storeId, 'block'); |
| 84 | + |
| 85 | + foreach ($filteredIndexData as $data) { |
| 86 | + $indexData[$data['categoryId']][$data['attributeId']] = $data['content']; |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + return $indexData; |
| 91 | + } |
| 92 | +} |
0 commit comments