小智 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;
}
Run Code Online (Sandbox Code Playgroud)
在您的自定义块中使用此代码来获取评级产品的 ID,并使用此块调用一个模板文件来显示产品数据
| 归档时间: |
|
| 查看次数: |
563 次 |
| 最近记录: |