2016-08-10 7 views
3

ホームページマゼンタ2で最高定格製品を得るには?私たちは、定格の製品のIDを取得し、製品データを表示するには、このブロックで1つのテンプレートファイルを呼び出すために、カスタムブロックでこのコードを使用しますMagentoの2Magento 2:ホームページ上の定格製品

答えて

0
にホームページに
public function getRatingSummary() 
{ 

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
    $reviewFactory = $objectManager->get(\Magento\Review\Model\ReviewFactory::class); 
    $storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class); 
    $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory'); 
    $collection = $productCollection->create() 
     ->addAttributeToSelect('*') 
     ->load(); 
    $rating = array(); 
    foreach ($collection as $product) { 
     $reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId()); 
     $ratingSummary = $product->getRatingSummary()->getRatingSummary(); 
     if($ratingSummary!=null){ 
      $rating[$product->getId()] = $ratingSummary; 
     } 
    } 
    return $rating; 
} 

をトップクラスの製品の一覧を表示する必要が

関連する問題