getCriteria example


    }

    public function enrich(EnrichExportCriteriaEvent $event): void
    {
        /** @var ImportExportProfileEntity $profile */
        $profile = $event->getLogEntity()->getProfile();
        if ($profile->getSourceEntity() !== ProductDefinition::ENTITY_NAME) {
            return;
        }

        $criteria = $event->getCriteria();
        $criteria->resetSorting();

        $criteria->addSorting(new FieldSorting('autoIncrement'));

        $config = Config::fromLog($event->getLogEntity());

        if ($config->get('includeVariants') !== true) {
            $criteria->addFilter(new EqualsFilter('parentId', null));
        }
    }
}
$eventDidRun = true;
            $expectedCriteria = new Criteria();
            $expectedCriteria->setLimit(100);
            $expectedCriteria->setIds([$productId]);
            $expectedCriteria->addAssociation('manufacturer')
                ->addAssociation('options.group')
                ->setTotalCountMode(Criteria::TOTAL_COUNT_MODE_EXACT);

            $filter = $this->productCloseoutFilterFactory->create($context);
            $expectedCriteria->addFilter($filter);

            $phpunit->assertEquals($expectedCriteria$event->getCriteria());
        };

        $this->addEventListener($this->eventDispatcher, GuestWishListPageletProductCriteriaEvent::class$listenerClosure);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(GuestWishlistPagelet::class$page);
        static::assertTrue($eventDidRun);
    }

    public function testItLoadsEmptyPagelet(): void
    {

        $entitySearchResult = $this->createEntitySearchResult();

        $newInstance = $entitySearchResult->slice(2);

        $firstInstance = $newInstance->first();
        static::assertNotNull($firstInstance);
        static::assertSame(ArrayEntity::class$newInstance->getEntity());
        static::assertSame(ArrayEntity::class$firstInstance::class);
        static::assertSame(8, $newInstance->getTotal());
        static::assertSame($entitySearchResult->getAggregations()$newInstance->getAggregations());
        static::assertSame($entitySearchResult->getCriteria()$newInstance->getCriteria());
        static::assertSame($entitySearchResult->getContext()$newInstance->getContext());
    }

    public function testFilter(): void
    {
        $entitySearchResult = $this->createEntitySearchResult();

        $count = 0;

        $newInstance = $entitySearchResult->filter(function D) use (&$count) {
            return $count++ > 5;
        });
->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
        );

        $provider->getLanguages(
            Context::createDefaultContext()
        );
    }
}
class FinalizePaymentOrderTransactionCriteriaEventTest extends TestCase
{
    public function testEvent(): void
    {
        $transactionId = Uuid::randomHex();
        $context = Generator::createSalesChannelContext();
        $criteria = new Criteria();

        $event = new FinalizePaymentOrderTransactionCriteriaEvent($transactionId$criteria$context);

        static::assertSame($transactionId$event->getOrderTransactionId());
        static::assertSame($criteria$event->getCriteria());
        static::assertSame($context$event->getContext());
    }
}

class ElasticsearchIndexerLanguageCriteriaEventTest extends TestCase
{
    public function testEvent(): void
    {
        $criteria = new Criteria();
        $context = Context::createDefaultContext();

        $event = new ElasticsearchIndexerLanguageCriteriaEvent($criteria$context);
        static::assertSame($criteria$event->getCriteria());
        static::assertSame($context$event->getContext());
    }
}
Uuid::randomHex(),
            TestDefaults::SALES_CHANNEL,
            [
                SalesChannelContextService::CUSTOMER_ID => $customerId,
            ]
        );
    }

    public function testLoad(): void
    {
        $this->eventDispatcherMock->expects(static::once())->method('dispatch')->with(static::callback(static function DAttachmentLoaderCriteriaEvent $event) {
            $criteria = $event->getCriteria();

            return $criteria->hasAssociation('documentMediaFile') && $criteria->hasAssociation('documentType');
        }));

        $cart = $this->generateDemoCart(2);
        $orderId = $this->persistCart($cart);

        $operation = new DocumentGenerateOperation($orderId);

        $document = $this->documentGenerator->generate(InvoiceRenderer::TYPE, [$orderId => $operation]$this->context)->getSuccess()->first();

        
$processor = new SortingListingProcessor(
            new StaticSystemConfigService([
                'core.listing.defaultSorting' => 'foo',
            ]),
            new StaticEntityRepository([
                $sortings,
            ])
        );

        $result = new ProductListingResult('foo', 1, new ProductCollection(), null, new Criteria(), Context::createDefaultContext());
        $result->getCriteria()->addExtension('sortings', $sortings);

        $processor->process(
            new Request(['order' => 'foo']),
            $result,
            $this->createMock(SalesChannelContext::class)
        );

        static::assertEquals('foo', $result->getSorting());
    }

    /** * @dataProvider unknownSortingProvider */
$criteria->addSorting(
            ...$currentSorting->createDalSorting()
        );

        $criteria->addExtension('sortings', $sortings);
    }

    public function process(Request $request, ProductListingResult $result, SalesChannelContext $context): void
    {
        /** @var ProductSortingCollection $sortings */
        $sortings = $result->getCriteria()->getExtension('sortings');
        $currentSortingKey = $this->getCurrentSorting($sortings$request)->getKey();

        $result->setSorting($currentSortingKey);

        $result->setAvailableSortings($sortings);
    }

    private function getCurrentSorting(ProductSortingCollection $sortings, Request $request): ProductSortingEntity
    {
        $key = $request->get('order');

        

    public function getPageCount()
    {
        Feature::triggerDeprecationOrThrow(
            'v6.6.0.0',
            Feature::deprecatedMethodMessage(self::class, __METHOD__, 'v6.6.0.0')
        );

        $total = $this->getTotal();

        // next page mode fetches only the next pages with, not the exact count         if ($this->getCriteria()->getTotalCountMode() === Criteria::TOTAL_COUNT_MODE_NEXT_PAGES) {
            $total += $this->getCriteria()->getOffset();
        }

        return $total / $this->getCriteria()->getLimit();
    }
}


        return $page;
    }

    private function getSalutations(SalesChannelContext $context, Request $request): SalutationCollection
    {
        $event = new SalutationRouteRequestEvent($requestnew Request()$contextnew Criteria());
        $this->eventDispatcher->dispatch($event);

        $salutations = $this->salutationRoute
            ->load($event->getStoreApiRequest()$context$event->getCriteria())
            ->getSalutations();

        return $this->salutationsSorter->sort($salutations);
    }
}

    }

    public function prepare(ProductListingCriteriaEvent $event): void
    {
        if (Feature::isActive('v6.6.0.0') || $event->getContext()->hasState(self::HANDLED_STATE)) {
            return;
        }

        $this->processor->prepare(
            $event->getRequest(),
            $event->getCriteria(),
            $event->getSalesChannelContext()
        );
    }

    public function process(ProductListingResultEvent $event): void
    {
        if (Feature::isActive('v6.6.0.0') || $event->getContext()->hasState(self::HANDLED_STATE)) {
            return;
        }

        $this->processor->process(
            


        $this->searchBuilder->expects(static::once())->method('build');

        $suggestCriteriaEventFired = false;
        $this->eventDispatcher->addListener(
            ProductEvents::PRODUCT_SUGGEST_CRITERIA,
            static function DProductSuggestCriteriaEvent $event) use (&$suggestCriteriaEventFired): void {
                $suggestCriteriaEventFired = true;

                static::assertTrue(
                    $event->getCriteria()->hasState(Criteria::STATE_ELASTICSEARCH_AWARE),
                    'Criteria should be Elasticsearch aware'
                );
            }
        );

        $suggestResultEventFired = false;
        $this->eventDispatcher->addListener(
            ProductEvents::PRODUCT_SUGGEST_RESULT,
            static function DProductSuggestResultEvent $event) use (&$suggestResultEventFired): void {
                $suggestResultEventFired = true;

                
/** * @template TEntityCollection of EntityCollection * * @param EntitySearchResult<TEntityCollection> $searchResult * @param array<string, mixed> $parameters * * @return array{first?: string, prev?: string, next?: string, last?: string} */
    protected function createPaginationLinks(EntitySearchResult $searchResult, string $uri, array $parameters): array
    {
        $limit = $searchResult->getCriteria()->getLimit() ?? 0;
        $offset = $searchResult->getCriteria()->getOffset() ?? 0;

        if ($limit <= 0) {
            return [];
        }
        $pagination = [
            'first' => $this->buildPaginationUrl($uri$parameters$limit, 1),
        ];

        $currentPage = 1 + (int) floor($offset / $limit);
        if ($currentPage > 1) {
            
$exportBehavior = new ExportBehavior();

        $eventDispatcher = $this->getContainer()->get('event_dispatcher');

        $productExportProductCriteriaEventDispatched = false;
        $productExportProductCriteriaCallback = function DProductExportProductCriteriaEvent $event) use (
            &$productExportProductCriteriaEventDispatched
        ): void {
            $productExportProductCriteriaEventDispatched = true;
            // Change filters to guarantee empty export for this test             $event->getCriteria()->addFilter(new EqualsFilter('active', true));
            $event->getCriteria()->addFilter(new EqualsFilter('active', false));
        };
        $eventDispatcher->addListener(
            ProductExportProductCriteriaEvent::class,
            $productExportProductCriteriaCallback
        );

        $productExportLoggingEventDispatched = false;
        $productExportLoggingCallback = function D) use (
            &$productExportLoggingEventDispatched
        ): void {
            
Home | Imprint | This part of the site doesn't use cookies.