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

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\Framework\Log\Package;
  10. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  11. #[Package('checkout')]
  12. class PromotionGateway implements PromotionGatewayInterface
  13. {
  14.     /**
  15.      * @var EntityRepositoryInterface
  16.      */
  17.     private $promotionRepository;
  18.     /**
  19.      * @internal
  20.      */
  21.     public function __construct(EntityRepositoryInterface $promotionRepository)
  22.     {
  23.         $this->promotionRepository $promotionRepository;
  24.     }
  25.     /**
  26.      * Gets a list of promotions for the provided criteria and
  27.      * sales channel context.
  28.      *
  29.      * @return EntityCollection<PromotionEntity>
  30.      */
  31.     public function get(Criteria $criteriaSalesChannelContext $context): EntityCollection
  32.     {
  33.         $criteria->setTitle('cart::promotion');
  34.         $criteria->addSorting(
  35.             new FieldSorting('priority'FieldSorting::DESCENDING)
  36.         );
  37.         /** @var PromotionCollection $entities */
  38.         $entities $this->promotionRepository->search($criteria$context->getContext())->getEntities();
  39.         return $entities;
  40.     }
  41. }