cloneForRead example



        $ids = $this->searchIds($criteria$context);

        if (empty($ids->getIds())) {
            /** @var TEntityCollection $collection */
            $collection = $this->definition->getCollectionClass();

            return new EntitySearchResult($this->definition->getEntityName()$ids->getTotal()new $collection()$aggregations$criteria$context);
        }

        $readCriteria = $criteria->cloneForRead($ids->getIds());

        $entities = $this->read($readCriteria$context);

        $search = $ids->getData();

        foreach ($entities as $element) {
            if (!\array_key_exists($element->getUniqueIdentifier()$search)) {
                continue;
            }

            $data = $search[$element->getUniqueIdentifier()];
            
$mapping = array_combine($keys$keys);

        $hasOptionFilter = $this->hasOptionFilter($criteria);
        if (!$hasOptionFilter) {
            $mapping = $this->resolvePreviews($keys$context);
        }

        $event = new ProductListingResolvePreviewEvent($context$criteria$mapping$hasOptionFilter);
        $this->eventDispatcher->dispatch($event);
        $mapping = $event->getMapping();

        $read = $criteria->cloneForRead(array_values($mapping));
        $read->addAssociation('options.group');

        $searchResult = $this->productRepository->search($read$context);

        $this->addExtensions($ids$searchResult$mapping);

        $result = new EntitySearchResult(ProductDefinition::ENTITY_NAME, $ids->getTotal()$searchResult->getEntities()$aggregations$origin$context->getContext());
        $result->addState(...$ids->getStates());

        return $result;
    }

    


        $ids = $this->doSearch($criteria$salesChannelContext);

        if (empty($ids->getIds())) {
            /** @var TEntityCollection $collection */
            $collection = $this->definition->getCollectionClass();

            return new EntitySearchResult($this->definition->getEntityName()$ids->getTotal()new $collection()$aggregations$criteria$salesChannelContext->getContext());
        }

        $readCriteria = $criteria->cloneForRead($ids->getIds());

        $entities = $this->read($readCriteria$salesChannelContext);

        $search = $ids->getData();

        foreach ($entities as $element) {
            if (!\array_key_exists($element->getUniqueIdentifier()$search)) {
                continue;
            }

            $data = $search[$element->getUniqueIdentifier()];
            
Home | Imprint | This part of the site doesn't use cookies.