SyliusCon 2025
Early Bird Deal
LogoLogo
🛣️ Roadmap💻 Sylius Demo💬 Community Slack
  • Sylius Documentation
  • Sylius Plugins
  • Sylius Stack
  • 📖Sylius 2.0 Documentation
    • Organization
      • Release Cycle
      • Backwards Compatibility Promise
      • Sylius Team
      • Sylius Roadmap
  • Getting Started with Sylius
    • Installation
    • Basic Configuration
    • Shipping & Payment
    • First Product
    • Customizing the Shop
    • Customizing Business Logic
    • Using API
    • Installing Plugins
    • Deployment
    • Summary
  • The Book
    • Introduction to Sylius
    • Installation
      • System Requirements
      • Sylius CE Installation
        • Sylius CE Installation with Docker
      • ➕Sylius Plus Installation
      • Upgrading Sylius CE
      • Upgrading Sylius Plus
    • Architecture
      • Architecture Overview
      • Architectural Drivers
      • Resource Layer
      • State Machine
      • Translations
      • E-Mails
      • Contact
      • Fixtures
      • Events
    • Configuration
      • Channels
      • Locales
      • Currencies
    • Customers
      • Customer & ShopUser
      • ➕Customer Pools
      • AdminUser
      • Addresses
        • Countries
        • Zones
        • Addresses
        • Address Book
    • Products
      • Products
      • Product Reviews
      • Product Associations
      • Attributes
      • Pricing
      • Catalog Promotions
      • Taxons
      • Inventory
      • ➕Multi-Source Inventory
      • Search
    • Carts & Orders
      • Orders
      • Cart flow
      • Taxation
      • Adjustments
      • Cart Promotions
      • Coupons
      • Payments
      • 🧩Invoices
      • Shipments
    • Support
    • Contributing
      • Contributing Code
        • Submitting a Patch
        • ⚠️Security Issues
        • Coding Standards
        • Conventions
        • Sylius License and Trademark
      • Contributing Translations
      • Key Contributors
  • The Customization Guide
    • Customizing Models
      • How to add a custom model?
      • How to add a custom translatable model?
    • Customizing Forms
      • How to add a live form for a custom model?
    • Customizing Styles
    • Customizing Validation
    • Customizing Menus
    • Customizing Templates
    • Customizing Translations
    • Customizing Flashes
    • Customizing State Machines
    • Customizing Grids
    • Customizing Fixtures
    • Customizing API
    • Customizing Serialization of API
    • Customizing Payments
      • How to integrate a Payment Gateway as a Plugin?
  • 🧑‍🍳The Cookbook
  • How to resize images?
  • How to add one image to an entity?
  • How to add multiple images to an entity?
  • Sylius 1.X Documentation
    • 📓Sylius 1.x Documentation
Powered by GitBook
LogoLogo

Developer

  • Community
  • Online Course

About

  • Team

© 2025 Sylius. All Rights Reserved

On this page
  • Rating
  • Product review state machine
  • How is the average rating calculated?
  • How to add a ProductReview programmatically?

Was this helpful?

Edit on GitHub
  1. The Book
  2. Products

Product Reviews

PreviousProductsNextProduct Associations

Last updated 8 months ago

Was this helpful?

Product Reviews are a marketing tool that lets your customers give opinions about the products they buy in your shop. They have a rating and comment.

Rating

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:

  • new,

  • accepted,

  • rejected

There are only two possible transitions: accept (from new to accepted) and reject (from new to rejected).

When a review is accepted the average rating of a product is updated.

How is the average rating calculated?

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 in 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' => '[email protected]']);

$review->setAuthor($customer);

Remember to set the object that is the subject of your review and then add the review to the repository.

$review->setReviewSubject($product);

$this->container->get('sylius.repository.product_review')->add($review);

The average rating is updated by the service.

It wraps the and uses it inside the updateFromReview method.

AverageRatingUpdater
AverageRatingCalculator