custom/plugins/EconsorCrowdfunding/src/Subscriber/ExcessCategorySubscriber.php line 83

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace EconsorCrowdfunding\Subscriber;
  4. use EconsorBundles\Services\BundleService;
  5. use EconsorCrowdfunding\Models\Validation\ValidationEntity;
  6. use EconsorCrowdfunding\Services\CrowdfundingMailService;
  7. use Exception;
  8. use Shopware\Core\Framework\Context;
  9. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  12. use Shopware\Core\Framework\Uuid\Uuid;
  13. use Shopware\Core\System\SalesChannel\Context\SalesChannelContextService;
  14. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  15. use Shopware\Core\System\SystemConfig\SystemConfigService;
  16. use Shopware\Storefront\Event\StorefrontRenderEvent;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Symfony\Component\HttpFoundation\RedirectResponse;
  19. use Symfony\Component\HttpFoundation\Session\Session;
  20. use Symfony\Component\HttpKernel\Event\RequestEvent;
  21. use Symfony\Component\HttpKernel\KernelEvents;
  22. use Symfony\Component\Routing\RouterInterface;
  23. /**
  24.  * Class ExcessCategorySubscriber
  25.  * @package EconsorCrowdfunding\Subscriber
  26.  */
  27. class ExcessCategorySubscriber implements EventSubscriberInterface
  28. {
  29.     /**
  30.      * @var SystemConfigService
  31.      */
  32.     private $configService;
  33.     /**
  34.      * @var EntityRepositoryInterface
  35.      */
  36.     private $categoryRepo;
  37.     /**
  38.      * @var EntityRepositoryInterface
  39.      */
  40.     private $validationRepo;
  41.     /**
  42.      * @var Session
  43.      */
  44.     private $session;
  45.     /**
  46.      * @var BundleService
  47.      */
  48.     private $bundleService;
  49.     public function __construct(
  50.         SystemConfigService $configService,
  51.         EntityRepositoryInterface $category,
  52.         EntityRepositoryInterface $validation,
  53.         Session $session
  54.         /*BundleService $bundleService*/
  55.     ) {
  56.         $this->configService $configService;
  57.         $this->categoryRepo $category;
  58.         $this->validationRepo $validation;
  59.         $this->session $session;
  60.         /*$this->bundleService = $bundleService;*/
  61.     }
  62.     public static function getSubscribedEvents(): array
  63.     {
  64.         return [
  65.             StorefrontRenderEvent::class => 'handleRequest'
  66.         ];
  67.     }
  68.     /**
  69.      * @param StorefrontRenderEvent $event
  70.      * @throws Exception
  71.      */
  72.     public function handleRequest(StorefrontRenderEvent $event)
  73.     {
  74.         $route $event->getRequest()->attributes->get('navigationId');
  75.         $category $this->configService->get('EconsorCrowdfunding.config.excessCategory');
  76.         $hash $event->getRequest()->query->get('hash');
  77.         $currentUID $event->getSalesChannelContext()->getCustomer() ? $event->getSalesChannelContext()->getCustomer()->getId() : '';
  78.         $validation $this->getValidationEntry($hash);
  79.         $uID $validation $validation->getCampaign()->getCustomer()->getId() : null;
  80.         if($route === $category)
  81.         {
  82.             if($validation && $currentUID === $uID)
  83.             {
  84.                 //todo put bundle in WK
  85.                 //todo set session variable that campaign is being finished
  86.                 //todo add wk rebate of 10% per article added
  87.                 $this->session->set('test'true);
  88.                 dd($this->bundleService);
  89.             } else {
  90.                 //throw new Exception('Access denied');
  91.             }
  92.         }
  93.     }
  94.     /**
  95.      * @param $hash
  96.      * @return ValidationEntity|null
  97.      */
  98.     private function getValidationEntry($hash)
  99.     {
  100.         $c = new Criteria();
  101.         $c->addFilter(new EqualsFilter('hash'$hash));
  102.         return $this->validationRepo->search($cContext::createDefaultContext())->getEntities()->first();
  103.     }
  104. }