vendor/shopware/core/Content/Product/SalesChannel/Sorting/ProductSortingEntity.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Product\SalesChannel\Sorting;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Entity;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  6. use Shopware\Core\Framework\Log\Package;
  7. #[Package('inventory')]
  8. class ProductSortingEntity extends Entity
  9. {
  10.     use EntityIdTrait;
  11.     /**
  12.      * @var string
  13.      */
  14.     protected $key;
  15.     /**
  16.      * @var int
  17.      */
  18.     protected $priority;
  19.     /**
  20.      * @var bool
  21.      */
  22.     protected $active;
  23.     /**
  24.      * @var array
  25.      */
  26.     protected $fields;
  27.     /**
  28.      * @var string|null
  29.      */
  30.     protected $label;
  31.     /**
  32.      * @var ProductSortingTranslationCollection|null
  33.      */
  34.     protected $translations;
  35.     /**
  36.      * @var bool
  37.      */
  38.     protected $locked;
  39.     public function createDalSorting(): array
  40.     {
  41.         $sorting = [];
  42.         $fields $this->fields;
  43.         usort($fields, function ($a$b) {
  44.             return $b['priority'] <=> $a['priority'];
  45.         });
  46.         foreach ($fields as $field) {
  47.             $direction mb_strtoupper($field['order']) === FieldSorting::ASCENDING
  48.                 FieldSorting::ASCENDING
  49.                 FieldSorting::DESCENDING;
  50.             $sorting[] = new FieldSorting(
  51.                 $field['field'],
  52.                 $direction,
  53.                 (bool) ($field['naturalSorting'] ?? false)
  54.             );
  55.         }
  56.         return $sorting;
  57.     }
  58.     public function getKey(): string
  59.     {
  60.         return $this->key;
  61.     }
  62.     public function setKey(string $key): void
  63.     {
  64.         $this->key $key;
  65.     }
  66.     public function getPriority(): int
  67.     {
  68.         return $this->priority;
  69.     }
  70.     public function setPriority(int $priority): void
  71.     {
  72.         $this->priority $priority;
  73.     }
  74.     public function isActive(): bool
  75.     {
  76.         return $this->active;
  77.     }
  78.     public function setActive(bool $active): void
  79.     {
  80.         $this->active $active;
  81.     }
  82.     public function getFields(): array
  83.     {
  84.         return $this->fields;
  85.     }
  86.     public function setFields(array $fields): void
  87.     {
  88.         $this->fields $fields;
  89.     }
  90.     public function getLabel(): ?string
  91.     {
  92.         return $this->label;
  93.     }
  94.     public function setLabel(?string $label): void
  95.     {
  96.         $this->label $label;
  97.     }
  98.     public function getTranslations(): ?ProductSortingTranslationCollection
  99.     {
  100.         return $this->translations;
  101.     }
  102.     public function setTranslations(ProductSortingTranslationCollection $translations): void
  103.     {
  104.         $this->translations $translations;
  105.     }
  106.     public function isLocked(): bool
  107.     {
  108.         return $this->locked;
  109.     }
  110.     public function setLocked(bool $locked): void
  111.     {
  112.         $this->locked $locked;
  113.     }
  114.     public function getApiAlias(): string
  115.     {
  116.         return 'product_sorting';
  117.     }
  118. }