public static function getSubscribedEvents(): array
{ return [ 'sales_channel.' . ProductEvents::PRODUCT_LOADED_EVENT => 'salesChannelLoaded',
'sales_channel.product.partial_loaded' => 'salesChannelLoaded',
];
} public function salesChannelLoaded(SalesChannelEntityLoadedEvent
$event): void
{ $stocks =
$this->stockStorage->
load( new StockLoadRequest($event->
getIds()),
$event->
getSalesChannelContext() );
foreach ($event->
getEntities() as $product) { /** @var ProductEntity $product */
$stock =
$stocks->
getStockForProductId($product->
getId());
if ($stock === null
) { continue;
}