custom/plugins/PixelLexikonSW6/src/Component/FrontHelpers.php line 104

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Pixel\LexikonSW6\Component;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
  5. use Shopware\Core\Framework\Uuid\Uuid;
  6. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  7. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  8. use Shopware\Core\System\SystemConfig\SystemConfigService;
  9. use Shopware\Core\Content\ProductStream\Service\ProductStreamBuilder;
  10. use Shopware\Core\Content\Seo\SeoUrlPlaceholderHandlerInterface;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  14. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  15. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  16. use Symfony\Component\DependencyInjection\ContainerInterface;
  17. class FrontHelpers
  18. {
  19.     private $systemConfigService;
  20.     private $lexikonRepository;
  21.     private $lexikonCatRepository;
  22.     private $salesChannelProductRepository;
  23.     private $productStreamBuilder;
  24.     private $connection;
  25.     private $seoUrlRewriter;
  26.     private $container;
  27.     public function __construct(
  28.         SeoUrlPlaceholderHandlerInterface $seoUrlRewriter,
  29.         SystemConfigService $systemConfigService,
  30.         EntityRepositoryInterface $lexikonRepository,
  31.         EntityRepositoryInterface $lexikonCatRepository,
  32.         SalesChannelRepositoryInterface $salesChannelProductRepository,
  33.         ProductStreamBuilder $productStreamBuilder,
  34.         Connection $connection,
  35.         ContainerInterface $container
  36.     ) {
  37.         $this->systemConfigService $systemConfigService;
  38.         $this->lexikonRepository $lexikonRepository;
  39.         $this->lexikonCatRepository $lexikonCatRepository;
  40.         $this->salesChannelProductRepository $salesChannelProductRepository;
  41.         $this->productStreamBuilder $productStreamBuilder;
  42.         $this->connection $connection;
  43.         $this->seoUrlRewriter $seoUrlRewriter;
  44.         $this->container $container;
  45.     }
  46.     public function getEntries($context$sales_channel_id$categoryId$systemConfig$limit null$offset null)
  47.     {
  48.         $catEntries = array();
  49.         $criteria = new Criteria();
  50.         $criteria->addAssociation('channels');
  51.         $criteria->getAssociation('channels');
  52.         if ($systemConfig['LEXIKONLISTIMAGES']  ) {
  53.             $criteria->addAssociation('media');
  54.             $criteria->getAssociation('media');
  55.         }
  56.         $criteria->addFilter(
  57.             new EqualsFilter('categoryid'$categoryId)
  58.         );
  59.         $criteria->addFilter(new EqualsFilter('active'true));
  60.         if ($systemConfig['LEXIKONSHOW'] == 'settings') {
  61.             $criteria->addFilter(new MultiFilter(MultiFilter::CONNECTION_OR, [
  62.                new EqualsFilter('pixel_lexikon.channels.id'null),
  63.                 new EqualsFilter('pixel_lexikon.channels.id'$sales_channel_id),
  64.             ]));
  65.         }
  66.         $criteria->addSorting(new FieldSorting('position'FieldSorting::ASCENDING));
  67.         if ($limit) {
  68.             $criteria->setLimit($limit);
  69.         }
  70.         if ($offset) {
  71.             $criteria->setOffset(($offset 1) * $limit);
  72.         }
  73.         $criteria->setTotalCountMode(Criteria::TOTAL_COUNT_MODE_EXACT);
  74.         $lexikonEntries $this->lexikonRepository->search($criteria$context);
  75.         if (count($lexikonEntries) > 0) {
  76.             $catEntries $lexikonEntries;
  77.         }
  78.         return $catEntries;
  79.     }
  80.     public function getAllLexikon(
  81.         $context,
  82.         $sales_channel_id,
  83.         $categoryId,
  84.         $systemConfig,
  85.         $limit null,
  86.         $offset null
  87.     ) {
  88.         $letters $this->getCategories($sales_channel_id$context$systemConfig);
  89.         $catEntries = array('categories' => array());
  90.         foreach ($letters as $catentry) {
  91.             $id $catentry->get('id');
  92.             $this->lexikonCatRepository->update(
  93.                 [
  94.                     ['id' => $id'shows' => $catentry->get('shows') + 1],
  95.                 ],
  96.                 $context
  97.             );
  98.             $catEntries['categories'][$id] = $catentry;
  99.             if ($id == $categoryId) {
  100.                 $catEntries['categories'][$id]->nav_active true;
  101.             } else {
  102.                 $catEntries['categories'][$id]->nav_active false;
  103.             }
  104.             $lexikonEntries $this->getCountOfCat($id$systemConfig,$sales_channel_id);
  105.             $catEntries['categories'][$id]->countItems = (int)$lexikonEntries;
  106.         }
  107.         return $catEntries;
  108.     }
  109.     public function getCountOfCat($categoryId$systemConfig,$sales_channel_id)
  110.     {
  111.         if ($systemConfig['LEXIKONSHOW'] == 'settings') {
  112.             $count $this->connection->fetchColumn('SELECT count(pixel_lexikon_channels.pixel_lexikon_id) FROM pixel_lexikon LEFT JOIN pixel_lexikon_channels ON pixel_lexikon_channels.pixel_lexikon_id = pixel_lexikon.id  WHERE HEX(pixel_lexikon.categoryid) = ? AND  HEX(pixel_lexikon_channels.sales_channel_id) = ?',
  113.                 [
  114.                     $categoryId,
  115.                     $sales_channel_id
  116.                 ]);
  117.         } else {
  118.             $count $this->connection->fetchColumn('SELECT count(id) FROM pixel_lexikon WHERE HEX(pixel_lexikon.categoryid) = ? ',
  119.                 [
  120.                     $categoryId
  121.                 ]);
  122.         }
  123.         return $count;
  124.     }
  125.     public function getLexikonById($context$id)
  126.     {
  127.         $criteria = new Criteria();
  128.         $criteria->addFilter(new EqualsFilter('id'$id));
  129.         $criteria->addAssociation('media');
  130.         $criteria->getAssociation('media');
  131.         $criteria->addAssociation('products');
  132.         $criteria->getAssociation('products');
  133.         $lexikonEntry $this->lexikonRepository->search($criteria$context)->first();
  134.         return $lexikonEntry;
  135.     }
  136.     public function getLexikonItem($context$id)
  137.     {
  138.         $criteria = new Criteria();
  139.         $criteria->addFilter(new EqualsFilter('id'$id));
  140.         $criteria->addAssociation('media');
  141.         $criteria->getAssociation('media');
  142.         $lexikonEntry $this->lexikonRepository->search($criteria$context)->first();
  143.         return $lexikonEntry;
  144.     }
  145.     public function getCategory($context$id)
  146.     {
  147.         $criteria = new Criteria();
  148.         $criteria->addFilter(new EqualsFilter('id'$id));
  149.         $criteria->addFilter(new EqualsFilter('active'true));
  150.         $lexikonCatEntry $this->lexikonCatRepository->search($criteria$context)->first();
  151.         return $lexikonCatEntry;
  152.     }
  153.     public function getCategories($sales_channel_id$context$systemConfig)
  154.     {
  155.         $criteria = new Criteria();
  156.         $criteria->addFilter(new EqualsFilter('active'true));
  157.         $criteria->addFilter(new EqualsFilter('notshow'false));
  158.         if ($systemConfig['LEXIKONSHOW'] == 'settings') {
  159.             $criteria->addFilter(new MultiFilter(MultiFilter::CONNECTION_OR, [
  160.                 new EqualsFilter('pixel_lexikon_categories.channels.id'$sales_channel_id),
  161.                new EqualsFilter('pixel_lexikon_categories.channels.id'null),
  162.             ]));
  163.         }
  164.         $criteria->addAssociation('seoUrls');
  165.         $criteria->getAssociation('seoUrls');
  166.         $criteria->addAssociation('channels');
  167.         $criteria->getAssociation('channels');
  168.         $criteria->addSorting(new FieldSorting('position'FieldSorting::ASCENDING));
  169.         $lexikonEntries $this->lexikonCatRepository->search($criteria$context)->getElements();
  170.         return $lexikonEntries;
  171.     }
  172.     public function getItemsFromCategory(Criteria $criteriaSalesChannelContext $salesChannelContext, ?string $categoryId)
  173.     {
  174.         $repo $this->container->get('pixel_lexikon_categories.repository');
  175.         $criteria->addAssociation('items');
  176.         $criteria->getAssociation('items');
  177.         if($categoryId != '00000000000000000000000000000000') {
  178.             $criteria->addFilter(new EqualsFilter('id'$categoryId));
  179.         }
  180.         $criteria->addSorting(new FieldSorting('title'FieldSorting::ASCENDING));
  181.         $results $repo->search($criteria$salesChannelContext->getContext());
  182.         return $results;
  183.     }
  184. }