0

I have a ReviewCollection, im trying to each "Review/Product" get a product image so i can pass on and display on template file:

public function getCollection()
{
    $collection = $this->_reviewsColFactory->create()->addStoreFilter(
            $this->_storeManager->getStore()->getId()
        )->addStatusFilter(
            \Magento\Review\Model\Review::STATUS_APPROVED
        )->setDateOrder();

    $arr = array();
    foreach ($collection as $_review) {
        $days = $this->returnDays($_review);
        if ($days <= $this->_days) {
            if (!isset($arr[$_review->getSku()])) {
                $arr[$_review->getSku()]['cont'] = 1;
            } else {
                $arr[$_review->getSku()]['cont']++;
            }
            $arr[$_review->getSku()]['productUrl'] = $_review->getProductUrl();
            $arr[$_review->getSku()]['productName'] = $_review->getName();
            $arr[$_review->getSku()]['productImg'] = $_review->getImage();
        }
    }
    // arsort($arr);

    return $collection;
}

In that case is every $_review a Model/Product ? Ty

  • Please confirm whether you want to get the reviews collection by product sku ? – NIPPU Aug 11 '17 at 11:48
0

I found out that a review from \Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory method getId returns the productID that i load ProductRepositoryInterface as follow :

$this->_productRepository->getById($productId);

Then i get ImageURL with Magento\Catalog\Block\Product\ListProduct as follow :

$imageBlock =  $this->getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct');
$productImage = $imageBlock->getImage($product, 'category_page_grid');
$productImage->toHtml();

I have uploaded my code on GitHub if one needed, a review of my code would be nice. Ty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.