如何在主页magento 2中获得最高评价的产品?
我们必须在Magento 2的主页上显示最受好评的产品列表。
答案 0 :(得分: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;
}
在自定义功能块中使用此代码获取评级产品的ID并使用此块调用一个模板文件以显示产品数据
答案 1 :(得分:0)
您也可以使用此扩展名https://www.detectadblock.com/ 特征 - 畅销产品 无顶产品 顶级产品