Question

Since I removed the review tab on product page, now I'd like to display all customer reviews in the product page itself (but outside of the tab).

How can I display them?

I'm running Magento 2.4.2.

Was it helpful?

Solution 2

I did it in this really clean way:

I created app/design/frontend/Vendor/Theme/Magento_Catalog/layout/catalog_product_view.xml with this layout:

<referenceBlock  name="reviews.tab" remove="true" />

<referenceContainer name="content">          
    <container name="product.info.details" htmlTag="div" htmlClass="product info detailed" after="product.info.media">
        <block class="Magento\Review\Block\Form" name="product.review.form" as="review_form" ifconfig="catalog/review/active" after="product_review_list.toolbar">
            <container name="product.review.form.fields.before" as="form_fields_before" label="Review Form Fields Before" htmlTag="div" htmlClass="rewards"/>
        </block>
        <block class="Magento\Review\Block\Product\View\ListView" name="product.info.product_additional_data" as="product_additional_data" template="Magento_Review::product/view/list.phtml" ifconfig="catalog/review/active"/>
        <block class="Magento\Theme\Block\Html\Pager" name="product_review_list.toolbar" ifconfig="catalog/review/active"/>
    </container>
</referenceContainer>

OTHER TIPS

You can get Product review data with the use of product id. Check the below code:

  protected $productRepository; 
  protected $_reviewCollection; 

  public function __construct(
      ...
      \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
      \Magento\Review\Model\ResourceModel\Review\CollectionFactory $reviewCollection,
      ...
  ) {
      ...
      $this->productRepository = $productRepository;
      $this->_reviewCollection = $reviewCollection;
      ...
  }

  public function getCollection($productId)
  {
    $product = $this->productRepository->getById($productId);
    $collection = $this->_reviewCollection->create()
      ->addStatusFilter(
        \Magento\Review\Model\Review::STATUS_APPROVED
      )->addEntityFilter(
      'product',
        $productId
      )->setDateOrder();

      print_r($collection->getData()); //Get all review data of product
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top