Magento2 Magento 2:主页上的顶级产品
如何在主页magento 2中获得顶级产品 我们必须在Magento 2的主页上显示顶级产品列表Magento2 Magento 2:主页上的顶级产品,magento2,Magento2,如何在主页magento 2中获得顶级产品 我们必须在Magento 2的主页上显示顶级产品列表 public function getRatingSummary() { $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $reviewFactory = $objectManager->get(\Magento\Review\Model\ReviewFactory::class);
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,并使用此块调用一个模板文件以显示产品数据您也可以使用此扩展名 特征- 畅销产品 顶级免费产品 顶级产品