vendor/shopware/core/Content/Product/SalesChannel/Sorting/ProductSortingCollection.php line 10

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Product\SalesChannel\Sorting;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  4. use Shopware\Core\Framework\Log\Package;
  5. /**
  6.  * @extends EntityCollection<ProductSortingEntity>
  7.  */
  8. #[Package('inventory')]
  9. class ProductSortingCollection extends EntityCollection
  10. {
  11.     public function sortByKeyArray(array $keys): void
  12.     {
  13.         $sorted = [];
  14.         foreach ($keys as $key) {
  15.             $sorting $this->getByKey($key);
  16.             if ($sorting !== null) {
  17.                 $sorted[$sorting->getId()] = $this->elements[$sorting->getId()];
  18.             }
  19.         }
  20.         $this->elements $sorted;
  21.     }
  22.     public function getByKey(string $key): ?ProductSortingEntity
  23.     {
  24.         return $this->filterByProperty('key'$key)->first();
  25.     }
  26.     public function removeByKey(string $key): void
  27.     {
  28.         foreach ($this->elements as $element) {
  29.             if ($element->getKey() === $key) {
  30.                 $this->remove($element->getId());
  31.             }
  32.         }
  33.     }
  34.     public function getApiAlias(): string
  35.     {
  36.         return 'product_sorting_collection';
  37.     }
  38.     protected function getExpectedClass(): string
  39.     {
  40.         return ProductSortingEntity::class;
  41.     }
  42. }