vendor/shopware/core/Checkout/Promotion/Gateway/PromotionGateway.php line 42

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Promotion\Gateway;
  3. use Shopware\Core\Checkout\Promotion\PromotionCollection;
  4. use Shopware\Core\Checkout\Promotion\PromotionEntity;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  9. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  10. class PromotionGateway implements PromotionGatewayInterface
  11. {
  12.     /**
  13.      * @var EntityRepositoryInterface
  14.      */
  15.     private $promotionRepository;
  16.     /**
  17.      * @internal
  18.      */
  19.     public function __construct(EntityRepositoryInterface $promotionRepository)
  20.     {
  21.         $this->promotionRepository $promotionRepository;
  22.     }
  23.     /**
  24.      * Gets a list of promotions for the provided criteria and
  25.      * sales channel context.
  26.      *
  27.      * @return EntityCollection<PromotionEntity>
  28.      */
  29.     public function get(Criteria $criteriaSalesChannelContext $context): EntityCollection
  30.     {
  31.         $criteria->setTitle('cart::promotion');
  32.         $criteria->addSorting(
  33.             new FieldSorting('priority'FieldSorting::DESCENDING)
  34.         );
  35.         /** @var PromotionCollection $entities */
  36.         $entities $this->promotionRepository->search($criteria$context->getContext())->getEntities();
  37.         return $entities;
  38.     }
  39. }