custom/plugins/WbfkExtensions/src/Subscriber/AccessoryProductsFetchedSubscriber.php line 26

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace WbfkExtensions\Subscriber;
  4. use ApplifactionGuidedShopping\Event\AccessoryProductsFetchedEvent;
  5. use Shopware\Core\Content\Product\ProductEntity;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class AccessoryProductsFetchedSubscriber implements EventSubscriberInterface
  8. {
  9.     public function __construct()
  10.     {
  11.     }
  12.     public static function getSubscribedEvents(): array
  13.     {
  14.         return [AccessoryProductsFetchedEvent::class => 'sortProductAccessory'];
  15.     }
  16.     /**
  17.      * @param AccessoryProductsFetchedEvent $event
  18.      * @return void
  19.      */
  20.     public function sortProductAccessory(AccessoryProductsFetchedEvent $event): void
  21.     {
  22.         $event->getProducts()->sort(function (ProductEntity $aProductEntity $b) {
  23.             return (($b->hasExtension('earliestShippingAndDeliveryTimeRange') ? 10000 0) + $b->getSales()) - (($a->hasExtension('earliestShippingAndDeliveryTimeRange') ? 10000 0) + $a->getSales());
  24.         });
  25.     }
  26. }