Initial Commit
This commit is contained in:
1 parent
4f495177e4
commit
b6d2142214
166 files changed
+13952
-178
No files matched your search
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\DataProcessing;
|
||||
|
||||
use Evomedien\Vitec\Domain\Repository\ProductRepository;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
|
||||
|
||||
/**
|
||||
* Simple and direct data processor for vitec_productlist
|
||||
*/
|
||||
class VitecProductProcessor implements DataProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly ProductRepository $productRepository,
|
||||
protected readonly FlexFormService $flexFormService
|
||||
) {
|
||||
}
|
||||
|
||||
public function process(
|
||||
ContentObjectRenderer $cObj,
|
||||
array $contentObjectConfiguration,
|
||||
array $processorConfiguration,
|
||||
array $processedData
|
||||
): array {
|
||||
// Only process vitec_productlist
|
||||
if (($processedData['data']['list_type'] ?? '') !== 'vitec_productlist') {
|
||||
return $processedData;
|
||||
}
|
||||
|
||||
// Get FlexForm settings
|
||||
$flexFormData = $this->flexFormService->convertFlexFormContentToArray(
|
||||
$processedData['data']['pi_flexform'] ?? ''
|
||||
);
|
||||
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
|
||||
// Extract category UIDs
|
||||
$categoryUids = array_filter(
|
||||
array_map('intval', explode(',', (string)($settings['categories'] ?? '')))
|
||||
);
|
||||
|
||||
// Get products
|
||||
$products = $this->productRepository->findFilteredProducts($categoryUids);
|
||||
|
||||
// Serialize products
|
||||
$productsData = [];
|
||||
foreach ($products as $product) {
|
||||
$productsData[] = [
|
||||
'uid' => $product->getUid(),
|
||||
'title' => $product->getTitle(),
|
||||
'slug' => $product->getSlug(),
|
||||
];
|
||||
}
|
||||
|
||||
// Add to processedData at content level
|
||||
if (!isset($processedData['content'])) {
|
||||
$processedData['content'] = [];
|
||||
}
|
||||
$processedData['content']['products'] = $productsData;
|
||||
|
||||
return $processedData;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user