custom/plugins/AutobatMarktThemePlugin-master/src/Subscriber/FrontendListingSubscriber.php line 22

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Expert\AutobatMarktThemePlugin\Subscriber;
  3. use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
  4. use Shopware\Core\Content\Product\Events\ProductSearchCriteriaEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  7. class FrontendListingSubscriber implements EventSubscriberInterface
  8. {
  9.     const EXCLUDE_SORTING = ['price-desc','price-asc','angebot','name-desc','name-asc'];
  10.     public static function getSubscribedEvents()
  11.     {
  12.         return [
  13.             ProductListingCriteriaEvent::class => ['handleListingRequestBefore'500],
  14.             ProductSearchCriteriaEvent::class => ['handleListingRequestBefore'500]
  15.         ];
  16.     }
  17.     public function handleListingRequestBefore(ProductListingCriteriaEvent $event): void
  18.     {
  19.         // add sorted properties group to listing
  20.         $event->getCriteria()->addAssociation('properties.group');
  21.         // AM-746 Sortierung nicht Verfügbarer Produkte
  22.         // AM-775 Sortierungsfunktion Preis Auf,- und Absteigend funktionslos
  23.         $request $event->getRequest();
  24.         if(!in_array($request->query->get('order'), self::EXCLUDE_SORTING)) {
  25.             $criteria $event->getCriteria();
  26.             $criteria->addSorting(
  27.                 new FieldSorting('product.available''DESC'),
  28.                 new FieldSorting('product.availableStock''DESC'),
  29.                 new FieldSorting('product.minPurchase''DESC'),
  30.             );
  31.         }
  32.     }
  33. }