<?php
declare(strict_types=1);
namespace BartCPreemiumArticle\PremiumArticle\Subscriber;
use BartCPreemiumArticle\PremiumArticle\Service\ProductHelper;
use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity;
use Shopware\Core\Framework\Struct\ArrayEntity;
use Shopware\Storefront\Page\Wishlist\WishlistPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class WishlistPage implements EventSubscriberInterface
{
private ProductHelper $productHelper;
public function __construct(ProductHelper $productHelper)
{
$this->productHelper = $productHelper;
}
public static function getSubscribedEvents(): array
{
return [
WishlistPageLoadedEvent::class => 'onProductPageLoad',
];
}
public function onProductPageLoad(WishlistPageLoadedEvent $event): void
{
$page = $event->getPage();
$products = $page->getWishlist()->getProductListing()->getEntities();
/** @var SalesChannelProductEntity $product */
foreach ($products as $product) {
$sellAvailable = $this->productHelper->checkIfSellAvailable($product->getId());
$product->addExtension(
'view',
new ArrayEntity(
[
'sellAvailable' => $sellAvailable,
]
)
);
}
}
}