getRatingAverage example

$this->createProduct($productId);

        $pointsOnAReview = 5.0;
        $pointsOnBReview = 1.0;

        $this->createReview($reviewAId$pointsOnAReview$productId, true);

        $products = $this->productRepository->search(new Criteria([$productId])$this->salesChannel->getContext());

        static::assertInstanceOf(ProductEntity::class$product = $products->get($productId));
        static::assertEquals($pointsOnAReview$product->getRatingAverage());

        $expected = ($pointsOnAReview + $pointsOnBReview) / 2;
        $this->createReview($reviewBId$pointsOnBReview$productId, true);
        $products = $this->productRepository->search(new Criteria([$productId])$this->salesChannel->getContext());

        static::assertInstanceOf(ProductEntity::class$product = $products->get($productId));
        static::assertEquals($expected$product->getRatingAverage());
    }

    /** * tests that a deactivated review is not considered for calculation * rating would be 3, but because the reviewA is deactivated only reviewB points will * be taken for calculation * * @group reviews */
Home | Imprint | This part of the site doesn't use cookies.