gpt4 book ai didi

magento2 - Magento 2 : Top rated products on homepage

转载 作者:行者123 更新时间:2023-12-02 19:34:54 25 4
gpt4 key购买 nike

如何在 magento 2 主页中获得评分最高的产品?

我们必须在 Magento 2 的主页中显示评价最高的产品列表。

最佳答案

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;
}

在您的自定义 block 中使用此代码来获取评级产品的 ID,并使用此 block 调用一个模板文件来显示产品数据

关于magento2 - Magento 2 : Top rated products on homepage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38869033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com