getSearchResult example


    }

    public function testVisibilityInSuggest(): void
    {
        $salesChannelContext = $this->contextFactory->create(Uuid::randomHex()$this->salesChannelId1);

        $request = new Request(['search' => 'test']);

        $page = $this->suggestPageLoader->load($request$salesChannelContext);

        static::assertCount(2, $page->getSearchResult());
        static::assertTrue($page->getSearchResult()->has($this->productId2));
        static::assertTrue($page->getSearchResult()->has($this->productId3));

        $salesChannelContext = $this->contextFactory->create(Uuid::randomHex()$this->salesChannelId2);
        $page = $this->searchPageLoader->load($request$salesChannelContext);

        static::assertCount(2, $page->getListing());
        static::assertTrue($page->getListing()->has($this->productId1));
        static::assertTrue($page->getListing()->has($this->productId2));
    }

    
$eventDidRun = null;
        $phpunit = $this;
        $listenerClosure = function DGuestWishlistPageletLoadedEvent $event) use (
            &$eventDidRun,
            $phpunit,
            $context,
            $request
        ): void {
            $eventDidRun = true;
            $phpunit->assertEquals($context$event->getSalesChannelContext());
            $phpunit->assertEquals($request$event->getRequest());
            $phpunit->assertEquals(3, $event->getPagelet()->getSearchResult()->getProducts()->count());
        };

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

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

        static::assertInstanceOf(GuestWishlistPagelet::class$page);
        $phpunit->assertEquals(3, $page->getSearchResult()->getProducts()->count());
        static::assertTrue($eventDidRun);
    }

    
$customer = $context->getCustomer();

        if ($customer !== null && $customer->getGuest() === false) {
            throw new NotFoundHttpException();
        }

        $pagelet = $this->guestPageletLoader->load($request$context);
        $this->hook(new GuestWishlistPageletLoadedHook($pagelet$context));

        return $this->renderStorefront(
            '@Storefront/storefront/page/wishlist/wishlist-pagelet.html.twig',
            ['page' => $pagelet, 'searchResult' => $pagelet->getSearchResult()->getObject()]
        );
    }

    #[Route(path: '/widgets/wishlist', name: 'widgets.wishlist.pagelet', options: ['seo' => false], defaults: ['XmlHttpRequest' => true, '_loginRequired' => true], methods: ['GET', 'POST'])]     public function ajaxPagination(Request $request, SalesChannelContext $context, CustomerEntity $customer): Response
    {
        $request->request->set('no-aggregations', true);

        $page = $this->wishlistPageLoader->load($request$context$customer);
        $this->hook(new WishlistPageLoadedHook($page$context));

        
Home | Imprint | This part of the site doesn't use cookies.