<?php
declare(strict_types=1);
namespace WbfkExtensions\Subscriber;
use ApplifactionGuidedShopping\Event\AccessoryProductsFetchedEvent;
use Shopware\Core\Content\Product\ProductEntity;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AccessoryProductsFetchedSubscriber implements EventSubscriberInterface
{
public function __construct()
{
}
public static function getSubscribedEvents(): array
{
return [AccessoryProductsFetchedEvent::class => 'sortProductAccessory'];
}
/**
* @param AccessoryProductsFetchedEvent $event
* @return void
*/
public function sortProductAccessory(AccessoryProductsFetchedEvent $event): void
{
$event->getProducts()->sort(function (ProductEntity $a, ProductEntity $b) {
return (($b->hasExtension('earliestShippingAndDeliveryTimeRange') ? 10000 : 0) + $b->getSales()) - (($a->hasExtension('earliestShippingAndDeliveryTimeRange') ? 10000 : 0) + $a->getSales());
});
}
}