Pergunta

Hi I am trying to get ratings for each review. I am able to get the reviews for each product. This is my review variable $_review but when I tried to get rating it doesn't work. The below code should work, but it returns Error filtering template: Warning: count(): Parameter must be an array or an object that implements Countable

<?php if (count($_review->getRatingVotes())) : ?>

Am I missing something here?

Foi útil?

Solução

I figured it out. I am missing something on the function. I am posting the full function here:

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

        return $collection->getItems(); //Get all review data of product
    }

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top