custom/plugins/BartCPreemiumArticle/src/Subscriber/RemoveBuyButton.php line 28

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace BartCPreemiumArticle\PremiumArticle\Subscriber;
  4. use BartCPreemiumArticle\PremiumArticle\Service\ProductHelper;
  5. use Shopware\Core\Framework\Struct\ArrayEntity;
  6. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class RemoveBuyButton implements EventSubscriberInterface
  9. {
  10.     private ProductHelper $productHelper;
  11.     public function __construct(ProductHelper $productHelper)
  12.     {
  13.         $this->productHelper $productHelper;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             ProductPageLoadedEvent::class => 'onProductPageLoad',
  19.         ];
  20.     }
  21.     public function onProductPageLoad(ProductPageLoadedEvent $event): void
  22.     {
  23.         $page $event->getPage();
  24.         $productId $page->getProduct()->getId();
  25.         if ($page->getProduct()->getParentId()) {
  26.             $sellAvailable false;
  27.             if ($this->productHelper->checkIfSellAvailable($page->getProduct()->getId())
  28.                 && $this->productHelper->checkIfSellAvailable($page->getProduct()->getParentId())
  29.             ) {
  30.                 $sellAvailable true;
  31.             }
  32.         } else {
  33.             $sellAvailable $this->productHelper->checkIfSellAvailable($productId);
  34.         }
  35.         $event->getPage()->addExtension(
  36.             'view',
  37.             new ArrayEntity(
  38.                 [
  39.                     'sellAvailable' => $sellAvailable,
  40.                 ]
  41.             )
  42.         );
  43.     }
  44. }