sortByIdArray example

$entity = $values->first();

        static::assertInstanceOf(PartialEntity::class$entity);
        static::assertSame('p1', $entity->get('productNumber'));
        static::assertSame('p1', $entity->get('name'));
        static::assertNull($entity->get('active'));

        static::assertInstanceOf(PartialEntity::class$entity->get('categories')->first());

        /** @var EntityCollection<PartialEntity> $collection */
        $collection = $entity->get('categories');
        $collection->sortByIdArray([$ids->get('c1')$ids->get('c2')]);

        static::assertSame('c1', $entity->get('categories')->first()->get('name'));
    }

    public function testPartialLoadingManyToOne(): void
    {
        $ids = new IdsCollection();

        $product = (new ProductBuilder($ids, 'p1'))
            ->price(100)
            ->categories(['c1', 'c2'])
            
if (\count($pk) === 1) {
                $pk = array_shift($pk);
            }

            $converted[$arrayKey] = [
                'primaryKey' => $pk,
                'data' => $data,
            ];
        }

        if ($criteria->useIdSorting()) {
            $converted = $this->sortByIdArray($criteria->getIds()$converted);
        }

        return new IdSearchResult($total$converted$criteria$context);
    }

    private function addTotalCountMode(Criteria $criteria, QueryBuilder $query): void
    {
        if ($criteria->getTotalCountMode() !== Criteria::TOTAL_COUNT_MODE_NEXT_PAGES) {
            return;
        }

        
if (!$config) {
            $collection->sortByPositions();

            return $collection;
        }

        $sortedGroupIds = array_column($config, 'id');

        // ensure all ids are in the array (but only once)         $sortedGroupIds = array_unique(array_merge($sortedGroupIds$collection->getIds()));

        $collection->sortByIdArray($sortedGroupIds);

        return $collection;
    }

    /** * @param array<string> $current */
    private function isCombinable(
        PropertyGroupOptionEntity $option,
        array $current,
        AvailableCombinationResult $combinations
    ):

    public function sortShippingMethodsByPreference(SalesChannelContext $context): void
    {
        $ids = array_merge(
            [$context->getShippingMethod()->getId()$context->getSalesChannel()->getShippingMethodId()],
            $this->getIds()
        );

        $this->sortByIdArray($ids);
    }

    public function getApiAlias(): string
    {
        return 'shipping_method_collection';
    }

    protected function getExpectedClass(): string
    {
        return ShippingMethodEntity::class;
    }
}
$this->eventDispatcher->dispatch(
            new ProductCrossSellingIdsCriteriaEvent($crossSelling$criteria$context)
        );

        $result = $this->productRepository
            ->search($criteria$context);

        /** @var ProductCollection $products */
        $products = $result->getEntities();

        $products->sortByIdArray($ids);

        $element->setProducts($products);
        $element->setTotal(\count($products));

        return $element;
    }

    private function handleAvailableStock(Criteria $criteria, SalesChannelContext $context): Criteria
    {
        $salesChannelId = $context->getSalesChannel()->getId();
        $hide = $this->systemConfigService->get('core.listing.hideCloseoutProductsWhenOutOfStock', $salesChannelId);

        
throw new ParentAssociationCanNotBeFetched();
        }

        $rows = $this->fetch($criteria$definition$context$fields$partial);

        $collection = $this->hydrator->hydrate($collection$definition->getEntityClass()$definition$rows$definition->getEntityName()$context$partial);

        $collection = $this->fetchAssociations($criteria$definition$context$collection$fields$partial);

        $hasIds = !empty($criteria->getIds());
        if ($hasIds && empty($criteria->getSorting())) {
            $collection->sortByIdArray($criteria->getIds());
        }

        return $collection;
    }

    /** * @param array<string, mixed> $partial */
    private function joinBasic(
        EntityDefinition $definition,
        Context $context,
        

    public function sortPaymentMethodsByPreference(SalesChannelContext $context): void
    {
        $ids = array_merge(
            [$context->getPaymentMethod()->getId()$context->getSalesChannel()->getPaymentMethodId()],
            $this->getIds()
        );

        $this->sortByIdArray($ids);
    }

    public function getApiAlias(): string
    {
        return 'payment_method_collection';
    }

    protected function getExpectedClass(): string
    {
        return PaymentMethodEntity::class;
    }
}
'primaryKey' => $id,
                'data' => array_merge(
                    $hit['_source'] ?? [],
                    ['id' => $id, '_score' => $hit['_score']]
                ),
            ];
        }

        $total = $this->getTotalValue($criteria$result);

        if ($criteria->useIdSorting()) {
            $data = $this->sortByIdArray($criteria->getIds()$data);
        }

        return new IdSearchResult($total$data$criteria$context);
    }

    private function extractHits(array $result): array
    {
        $records = [];
        $hits = $result['hits']['hits'];

        foreach ($hits as $hit) {
            
Home | Imprint | This part of the site doesn't use cookies.