EntitySearchResult example

$this->eventDispatcher->dispatch(new WishListPageProductCriteriaEvent($criteria$context$request));

        $page = $this->genericLoader->load($request$context);
        $page = WishlistPage::createFrom($page);

        try {
            $page->setWishlist($this->wishlistLoadRoute->load($request$context$criteria$customer));
        } catch (CustomerWishlistNotFoundException) {
            $page->setWishlist(
                new LoadWishlistRouteResponse(
                    new CustomerWishlistEntity(),
                    new EntitySearchResult(
                        'wishlist',
                        0,
                        new ProductCollection(),
                        null,
                        $criteria,
                        $context->getContext()
                    )
                )
            );
        }

        
$this->expectExceptionMessageMatches(sprintf(
            $regexTemplate,
            preg_quote($plugin->getComposerName(), '#'),
            preg_quote('shopware/core', '#')
        ));
        $this->createValidator()->validateRequirements($plugin, Context::createDefaultContext(), 'test');
    }

    private function createValidator(): RequirementsValidator
    {
        $pluginRepo = $this->createMock(EntityRepository::class);
        $pluginRepo->method('search')->willReturn(new EntitySearchResult(
            'plugin',
            0,
            new PluginCollection(),
            null,
            new Criteria(),
            Context::createDefaultContext()
        ));

        return new RequirementsValidator(
            $pluginRepo,
            $this->projectDir
        );
$this->getContainer()->get('cache.object')
            ->invalidateTags([CachedCountryRoute::buildName(TestDefaults::SALES_CHANNEL)]);
    }

    /** * @dataProvider criteriaProvider */
    public function testCriteria(Criteria $criteria): void
    {
        $context = $this->createMock(SalesChannelContext::class);
        $response = new CountryRouteResponse(
            new EntitySearchResult('country', 0, new CountryCollection(), null, $criteria$context->getContext())
        );

        $core = $this->createMock(CountryRoute::class);
        $core->expects(static::exactly(2))
            ->method('load')
            ->willReturn($response);

        $route = new CachedCountryRoute(
            $core,
            new TagAwareAdapter(new ArrayAdapter(100)),
            $this->getContainer()->get(EntityCacheKeyGenerator::class),
            
static::expectException(DecorationPatternException::class);
        $this->searchIndexer->getDecorated();
    }

    public function testGlobalData(): void
    {
        $context = Context::createDefaultContext();
        $repository = $this->createMock(EntityRepository::class);
        $productStream = new ProductStreamEntity();
        $productStream->setUniqueIdentifier(Uuid::randomHex());
        $repository->method('search')->willReturn(
            new EntitySearchResult(
                'product_stream',
                1,
                new EntityCollection([$productStream]),
                null,
                new Criteria(),
                $context
            )
        );

        $indexer = new ProductStreamAdminSearchIndexer(
            $this->createMock(Connection::class),
            

        $languageRepository = $this->createMock(EntityRepository::class);

        $languageRepository
            ->method('search')
            ->willReturnCallback(function DCriteria $criteria) {
                static::assertTrue($criteria->hasEqualsFilter('fooo'));
                $sortings = $criteria->getSorting();
                static::assertCount(1, $sortings);
                static::assertEquals('id', $sortings[0]->getField());

                return new EntitySearchResult('foo', 0, new LanguageCollection(), null, $criteria, Context::createDefaultContext());
            });

        $dispatcher = new EventDispatcher();
        $dispatcher->addListener(ElasticsearchIndexerLanguageCriteriaEvent::classfunction DElasticsearchIndexerLanguageCriteriaEvent $event): void {
            $event->getCriteria()->addFilter(new EqualsFilter('fooo', null));
        });

        $provider = new ElasticsearchLanguageProvider(
            $languageRepository,
            $dispatcher
        );

        
static::assertEmpty($imageStruct->getMedia());
        static::assertEmpty($imageStruct->getMediaId());
    }

    public function testEnrichWithMediaOnly(): void
    {
        $resolverContext = new ResolverContext($this->createMock(SalesChannelContext::class)new Request());

        $media = new MediaEntity();
        $media->setUniqueIdentifier('media123');

        $mediaSearchResult = new EntitySearchResult(
            'media',
            1,
            new MediaCollection([$media]),
            null,
            new Criteria(),
            Context::createDefaultContext()
        );

        $result = new ElementDataCollection();
        $result->add('media_id', $mediaSearchResult);

        
'core.loginRegistration.passwordMinLength' => '8',
            ],
            'core.systemWideLoginRegistration.isCustomerBoundToSalesChannel' => true,
        ]);

        $customerEntity = new CustomerEntity();
        $customerEntity->setDoubleOptInRegistration(false);
        $customerEntity->setId('customer-1');
        $customerEntity->setGuest(false);

        $customerRepository = new StaticEntityRepository([
            new EntitySearchResult(
                'customer',
                1,
                new EntityCollection([$customerEntity]),
                null,
                new Criteria(),
                Context::createDefaultContext(),
            ),
        ]new CustomerDefinition());

        $definition = new DataValidationDefinition('address.create');

        
$repository = $this->createMock(EntityRepository::class);

        $appSnippets = [];
        foreach ($snippetsFromApp as $snippet) {
            $appSnippet = new AppAdministrationSnippetEntity();
            $appSnippet->assign($snippet);

            $appSnippets[] = $appSnippet;
        }

        $collection = new AppAdministrationSnippetCollection($appSnippets);
        $entitySearchResult = new EntitySearchResult(
            AppAdministrationSnippetDefinition::ENTITY_NAME,
            $collection->count(),
            $collection,
            null,
            new Criteria(),
            Context::createDefaultContext()
        );

        $repository
            ->method('search')
            ->willReturn($entitySearchResult);

        
$criteria = clone $criteria;

        $this->processCriteria($criteria$salesChannelContext);

        $aggregations = null;
        if ($criteria->getAggregations()) {
            $aggregations = $this->aggregate($criteria$salesChannelContext);
        }
        if (!RepositorySearchDetector::isSearchRequired($this->definition, $criteria)) {
            $entities = $this->read($criteria$salesChannelContext);

            return new EntitySearchResult($this->definition->getEntityName()$entities->count()$entities$aggregations$criteria$salesChannelContext->getContext());
        }

        $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());
        }

        
$product->setIsCloseout($closeout);

        $salesChannel = new SalesChannelEntity();
        $salesChannel->setId($salesChannelId);

        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $salesChannelContext->method('getSalesChannelId')->willReturn($salesChannelId);
        $salesChannelContext->method('getSalesChannel')->willReturn($salesChannel);

        $resolverContext = new ResolverContext($salesChannelContextnew Request());
        $result = new ElementDataCollection();
        $result->add('product_id', new EntitySearchResult(
            'product',
            1,
            new ProductCollection([clone $product]),
            null,
            new Criteria(),
            $resolverContext->getSalesChannelContext()->getContext()
        ));

        $slot = $this->enrichProductWithCmsConfig($product);

        $this->productBoxResolver->enrich($slot$resolverContext$result);
        
$aggregations = null;
        if ($criteria->getAggregations()) {
            $aggregations = $this->aggregate($criteria$context);
        }

        if (!RepositorySearchDetector::isSearchRequired($this->definition, $criteria)) {
            $this->eventDispatcher->dispatch(
                new EntitySearchedEvent($criteria$this->definition, $context)
            );
            $entities = $this->read($criteria$context);

            return new EntitySearchResult($this->definition->getEntityName()$entities->count()$entities$aggregations$criteria$context);
        }

        $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);
        }

        
$deliveryEntity->setId(Uuid::randomHex());
        $deliveryEntity->setStateId(Uuid::randomHex());

        $deliveries = new OrderDeliveryCollection([$deliveryEntity]);

        $orderEntity = $this->orderEntity();
        $orderEntity->setDeliveries($deliveries);
        $cart = $this->getCart();

        $entityRepository = $this->createMock(EntityRepository::class);
        $entityRepository->method('search')->willReturnOnConsecutiveCalls(
            new EntitySearchResult('order', 1, new OrderCollection([$orderEntity]), null, new Criteria()$this->salesChannelContext->getContext()),
        );

        $entityRepository
            ->expects(static::once())
            ->method('upsert')
            ->willReturnCallback(function Darray $data, Context $context) use ($orderEntity) {
                static::assertSame($data[0]['stateId']$orderEntity->getStateId());
                static::assertNotNull($data[0]['deliveries']);
                static::assertNotNull($data[0]['deliveries'][0]);
                static::assertSame($data[0]['deliveries'][0]['stateId']$orderEntity->getDeliveries()?->first()?->getStateId());

                
static::expectException(DecorationPatternException::class);
        $this->searchIndexer->getDecorated();
    }

    public function testGlobalData(): void
    {
        $context = Context::createDefaultContext();
        $repository = $this->createMock(EntityRepository::class);
        $product = new ProductEntity();
        $product->setUniqueIdentifier(Uuid::randomHex());
        $repository->method('search')->willReturn(
            new EntitySearchResult(
                'product',
                1,
                new EntityCollection([$product]),
                null,
                new Criteria(),
                $context
            )
        );

        $indexer = new ProductAdminSearchIndexer(
            $this->createMock(Connection::class),
            

    private StaticEntityRepository $appFlowEventRepository;

    protected function setUp(): void
    {
        $appFlowEvent = new AppFlowEventEntity();
        $appFlowEvent->setUniqueIdentifier(Uuid::randomHex());
        $appFlowEvent->setAware(['customerId']);
        $appFlowEvent->setName('custom.checkout.event');

        $this->appFlowEventRepository = new StaticEntityRepository([
            new EntitySearchResult(
                'app_flow_event',
                1,
                new AppFlowEventCollection([$appFlowEvent]),
                null,
                new Criteria(),
                Context::createDefaultContext(),
            ),
        ]);

        $this->triggerFlowController = new TriggerFlowController(new EventDispatcher()$this->appFlowEventRepository);
    }

    
new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(1, 1.1, true),
            new CashRoundingConfig(1, 1.1, true)
        );
        $this->response = new PaymentMethodRouteResponse(
            new EntitySearchResult(
                'entity',
                1,
                new PaymentMethodCollection(),
                null,
                new Criteria(),
                Context::createDefaultContext()
            )
        );

        $this->cachedRoute = new CachedPaymentMethodRoute(
            $this->decorated,
            
Home | Imprint | This part of the site doesn't use cookies.