Product Reviews are a marketing tool that let your customers to give opinions about the products they buy in your shop.
They have a
The rating of a product review is required and must be between 1 and 5.
Product review state machine¶
When you look inside the
CoreBundle/Resources/config/app/state_machine/sylius_product_review.yml you will find out that a Review can have
3 different states:
There are only two possible transitions:
When a review is accepted the average rating of a product is updated.
How is the average rating calculated?¶
The average rating is updated by the AverageRatingUpdater service.
It has inside the AverageRatingCalculator,
and uses it inside the
How to add a ProductReview programmatically?¶
Create a new review using a factory:
/** @var ReviewInterface $review */ $review = $this->container->get('sylius.factory.product_review')->createNew();
Fill the content of your review.
$review->setTitle('My Review'); $review->setRating(5); $review->setComment('This product is really great');
Then get a customer from the repository, which you would like to make an author of this review.
$customer = $this->container->get('sylius.repository.customer')->findOneBy(['email' => 'firstname.lastname@example.org']); $review->setAuthor($customer);
Remember to set the object that is the subject of your review and then add the review to the repository.