Skip to content
Snippets Groups Projects

ZERO-162-changes

Open Eduarda Lentz Rodrigues da Silva requested to merge ZERO-162-changes into develop
Compare and Show latest version
1 file
+ 1
1
Compare changes
  • Side-by-side
  • Inline
+ 90
0
<?php
declare(strict_types=1);
/**
* Copyright (c) 2025 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see https://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*
* @copyright Copyright (c) 2025 TechDivision GmbH (https://www.techdivision.com)
* @author TechDivision Team Zero <zero@techdivision.com>
* @link https://www.techdivision.com/
*/
namespace Firegento\ContentProvisioning\Model\Query;
use Firegento\ContentProvisioning\Model\DTO\CmsBlockDto;
use Firegento\ContentProvisioning\Model\Repository\CmsBlockStoreRepository;
use Magento\Store\Model\StoreManagerInterface;
class GetDbCmsBlockContent
{
/**
* @var CmsBlockStoreRepository
*/
private CmsBlockStoreRepository $cmsBlockStoreRepository;
/**
* @var StoreManagerInterface
*/
private StoreManagerInterface $storeManager;
/**
* @param CmsBlockStoreRepository $cmsBlockStoreRepository
* @param StoreManagerInterface $storeManager
*/
public function __construct(
CmsBlockStoreRepository $cmsBlockStoreRepository,
StoreManagerInterface $storeManager
) {
$this->cmsBlockStoreRepository = $cmsBlockStoreRepository;
$this->storeManager = $storeManager;
}
/**
* @param array $dbBlocks
* @param string[] $codeStoreCode
* @return string[]
*/
public function execute(array $dbBlocks, array $codeStoreCode): array
{
return $this->getCmsBlockContent($dbBlocks, $codeStoreCode);
}
/**
* @param CmsBlockDto[] $blocks
* @param string[] $storesCode
* @return string[]|null
*/
public function getCmsBlockContent(array $blocks, array $storesCode): ?array
{
$dbBlockContent = [];
$dbStoreCode = '';
foreach ($blocks as $dbBlock) {
if (!$dbBlock['row_id']) {
$dbStoreIds = $this->cmsBlockStoreRepository->getStoreIdsByBlockId((int)$dbBlock['block_id']);
foreach ($dbStoreIds as $storeId) {
$dbStoreCode = $storeId['store_code'];
}
} else {
$dbStoreIds = $this->cmsBlockStoreRepository->getStoreIdsByRowId((int)$dbBlock['row_id']);
foreach ($dbStoreIds as $storeId) {
$dbStoreCode = $this->storeManager->getStore($storeId)->getCode();
}
}
foreach ($storesCode as $storeCode) {
if ($storeCode === $dbStoreCode) {
$dbBlockContent[] = $dbBlock['content'];
}
}
}
return $dbBlockContent;
}
}
Loading