custom/plugins/plugin-MoorlOrderNotice-master/src/Subscriber/StorefrontSubscriber.php line 51

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlOrderNotice\Subscriber;
  3. use Composer\IO\NullIO;
  4. use Doctrine\DBAL\Connection;
  5. use Doctrine\DBAL\FetchMode;
  6. use Doctrine\DBAL\ParameterType;
  7. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  8. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  11. use Shopware\Core\Framework\Struct\ArrayEntity;
  12. use Shopware\Core\System\SystemConfig\SystemConfigService;
  13. use Shopware\Core\Checkout\Cart\SalesChannel\CartService;
  14. use Shopware\Storefront\Pagelet\Header\HeaderPageletLoadedEvent;
  15. use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
  16. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Symfony\Component\HttpFoundation\Session\Session;
  19. use Shopware\Core\Content\Product\ProductEvents;
  20. use Shopware\Core\Content\Product\Events\ProductSuggestCriteriaEvent;
  21. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter;
  22. use Shopware\Core\Content\Product\SalesChannel\ProductAvailableFilter;
  23. use Shopware\Core\Content\Product\Aggregate\ProductVisibility\ProductVisibilityDefinition;
  24. class StorefrontSubscriber implements EventSubscriberInterface {
  25.     private $systemConfigService;
  26.     private $orderRepository;
  27.     private $connection;
  28.     private $cartService;
  29.     public function __construct(
  30.         CartService $cartService,
  31.         SystemConfigService $systemConfigService,
  32.         EntityRepositoryInterface $orderRepository,
  33.         Connection $connection
  34.     ) {
  35.         $this->cartService $cartService;
  36.         $this->systemConfigService $systemConfigService;
  37.         $this->orderRepository $orderRepository;
  38.         $this->connection $connection;
  39.     }
  40.     public static function getSubscribedEvents(): array {
  41.         return [
  42.             CheckoutOrderPlacedEvent::class => 'onCheckoutOrderPlacedEvent',
  43.         ];
  44.     }
  45.     public function onCheckoutOrderPlacedEvent(CheckoutOrderPlacedEvent $event): void {
  46.         $session = new Session();
  47.         $order $event->getOrder();
  48.         if (!$order) {
  49.             return;
  50.         }
  51.         $notice $session->get('moorl-order-notice.notice');
  52.         $to_continous $session->get('moorl-order-notice.to_continous');
  53.         $libreka_download_links $session->get('moorl-order-notice.libreka_download_links');
  54.         $order_target_group_number $session->get('moorl-order-notice.order_target_group_number');
  55.         $advertising_permission $session->get('moorl-order-notice.advertising_permission');
  56.         $hochschul_kontingent_check $session->get('moorl-order-notice.hochschul_kontingent_check');
  57.         $bestellinformationen $session->get('moorl-order-notice.bestellinformationen');
  58.         if ($bestellinformationen != null) {
  59.             $orderProducts $event->getOrder()->getLineItems();
  60.             $documentProductInOrder false;
  61.             /**
  62.              * @var OrderLineItemEntity $product
  63.              */
  64.             foreach ($orderProducts as $product) {
  65.                 if ($bestellinformationen->Bestellnummer == $product->getPayload()['productNumber']) {
  66.                     $documentProductInOrder true;
  67.                     break;
  68.                 }
  69.             }
  70.             if (!$documentProductInOrder) {
  71.                 $bestellinformationen null;
  72.             }
  73.         }
  74.         if (!isset($bestellinformationen->Titel)) {
  75.             $bestellinformationen = (object) [
  76.                 'Titel' => '',
  77.                 'Bestellnummer' => '',
  78.                 'NextUrl' => '',
  79.                 'DokumentenId' => '',
  80.             ];
  81.         }
  82.         if ($notice == 'test@die.de') {
  83.             die();
  84.         }
  85.         if (
  86.             $notice ||
  87.             $notice != '' ||
  88.             $to_continous ||
  89.             $libreka_download_links ||
  90.             $order_target_group_number ||
  91.             $advertising_permission ||
  92.             $hochschul_kontingent_check ||
  93.             isset($bestellinformationen->DokumentenId)
  94.         ) {
  95.             $session->set('moorl-order-notice.notice'null);
  96.             $session->set('moorl-order-notice.to_continous'null);
  97.             //            $session->set('moorl-order-notice.order_target_group_number', null);
  98.             $session->set('moorl-order-notice.bestellinformationen'null);
  99.             //            '&titel=' . $_SESSION['bestellinformationen']->Titel .
  100.             //            '&product_nr=' . $_SESSION['bestellinformationen']->Bestellnummer .
  101.             //            '&next_url=' . $_SESSION['bestellinformationen']->NextUrl .
  102.             //            '&document_id=' . $_SESSION['bestellinformationen']->DokumentenId;
  103.             $this->orderRepository->update(
  104.                 [
  105.                     [
  106.                         'id' => $order->getId(),
  107.                         'customFields' => [
  108.                             'order_notice_notice' => $notice,
  109.                             'order_products_to_continous' => $to_continous,
  110.                             'order_products_libreka_download_links' => $libreka_download_links,
  111.                             'order_target_group_number' => $order_target_group_number,
  112.                             'order_notice_allow_spam' => $advertising_permission,
  113.                             'order_notice_hochschul_kontingent_check' => $hochschul_kontingent_check//Hochschulkontigent
  114.                             'order_document_title' => $bestellinformationen->Titel,
  115.                             'order_document_number' => $bestellinformationen->Bestellnummer,
  116.                             'order_document_nexturl' => $bestellinformationen->NextUrl,
  117.                             'order_document_id' => $bestellinformationen->DokumentenId,
  118.                         ],
  119.                     ],
  120.                 ],
  121.                 $event->getContext(),
  122.             );
  123.         }
  124.     }
  125. }