ProductListingRouteResponse example

/** * @internal */
class ProductListingTypeDataResolverTest extends TestCase
{
    private ProductListingCmsElementResolver $listingResolver;

    protected function setUp(): void
    {
        $mock = $this->createMock(ProductListingRoute::class);
        $mock->method('load')->willReturn(
            new ProductListingRouteResponse(
                new ProductListingResult('product', 0, new ProductCollection(), null, new Criteria(), Context::createDefaultContext())
            )
        );

        $this->listingResolver = new ProductListingCmsElementResolver($mock);
    }

    public function testGetType(): void
    {
        static::assertEquals('product-listing', $this->listingResolver->getType());
    }

    


        $this->extendCriteria($context$criteria$category);

        $entities = $this->listingLoader->load($criteria$context);

        $result = ProductListingResult::createFrom($entities);
        $result->addState(...$entities->getStates());

        $result->setStreamId($category->get('productStreamId'));

        return new ProductListingRouteResponse($result);
    }

    private function extendCriteria(SalesChannelContext $salesChannelContext, Criteria $criteria, PartialEntity $category): void
    {
        $hasProductStream = $category->get('productAssignmentType') === CategoryDefinition::PRODUCT_ASSIGNMENT_TYPE_PRODUCT_STREAM
            && $category->get('productStreamId') !== null;

        if ($hasProductStream) {
            $filters = $this->productStreamBuilder->buildFilters(
                $category->get('productStreamId'),
                $salesChannelContext->getContext()
            );
$salesChannel,
            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 ProductListingRouteResponse(
            new ProductListingResult(
                'entity',
                1,
                new ProductCollection(),
                null,
                new Criteria(),
                Context::createDefaultContext()
            )
        );

        $this->cachedRoute = new CachedProductListingRoute(
            
'sum' => new SumResult('sum', 2.3),
        ]);
        $productListingResultMock = $this->createMock(ProductListingResult::class);
        $productListingResultMock->method('getAggregations')->willReturn(
            new AggregationResultCollection(
                $testAggregations
            )
        );

        $request = new Request();

        $productListingRouteResponse = new ProductListingRouteResponse($productListingResultMock);
        $this->productListingRouteMock->method('load')->willReturn($productListingRouteResponse);

        $response = $this->controller->filter($ids->get('navigation')$request$this->createMock(SalesChannelContext::class));

        static::assertEquals(
            json_encode($testAggregations, \JSON_THROW_ON_ERROR),
            json_encode(json_decode($response->getContent() ?: '', true, 512, \JSON_THROW_ON_ERROR), \JSON_THROW_ON_ERROR)
        );

        static::assertTrue($request->request->get('only-aggregations'));
        static::assertTrue($request->request->get('reduce-aggregations'));
    }
->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
    }

    /** * @dataProvider criteriaProvider */
    public function testCriteria(Criteria $criteria): void
    {
        $ids = new IdsCollection();

        $context = $this->createMock(SalesChannelContext::class);
        $response = new ProductListingRouteResponse(new ProductListingResult('product', 0, new ProductCollection(), null, $criteria$context->getContext()));

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

        $route = new CachedProductListingRoute(
            $core,
            $this->getContainer()->get('cache.object'),
            $this->getContainer()->get(EntityCacheKeyGenerator::class),
            $this->getContainer()->get(CacheTracer::class),
            
Home | Imprint | This part of the site doesn't use cookies.