custom/plugins/BartCPreemiumArticle/src/Subscriber/WishlistPage.php line 29

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\Content\Product\SalesChannel\SalesChannelProductEntity;
  6. use Shopware\Core\Framework\Struct\ArrayEntity;
  7. use Shopware\Storefront\Page\Wishlist\WishlistPageLoadedEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class WishlistPage implements EventSubscriberInterface
  10. {
  11.     private ProductHelper $productHelper;
  12.     public function __construct(ProductHelper $productHelper)
  13.     {
  14.         $this->productHelper $productHelper;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             WishlistPageLoadedEvent::class => 'onProductPageLoad',
  20.         ];
  21.     }
  22.     public function onProductPageLoad(WishlistPageLoadedEvent $event): void
  23.     {
  24.         $page $event->getPage();
  25.         $products $page->getWishlist()->getProductListing()->getEntities();
  26.         /** @var SalesChannelProductEntity $product */
  27.         foreach ($products as $product) {
  28.             $sellAvailable $this->productHelper->checkIfSellAvailable($product->getId());
  29.             $product->addExtension(
  30.                 'view',
  31.                 new ArrayEntity(
  32.                     [
  33.                         'sellAvailable' => $sellAvailable,
  34.                     ]
  35.                 )
  36.             );
  37.         }
  38.     }
  39. }