Magento 2获取评论,评分收藏

正如您可能已经知道的那样,审核和评级在每个在线业务中都扮演着重要角色,尤其是那些在Magento 2平台上运行的业务,因为它直接与商店的声誉以及客户的购买决策相关。

因此,在今天的帖子中,我将为您提供最简单的方法来获取 Magento 2中的评论和评级

如何获得评论,评级收集

要进行产品审核,请务必收集,您需要创建一个ProductReviews.php文件。按照这条路径Mageplaza/HelloWorld/Model/ProductReviews.php,以下是您要如何做到这一点。

<?php

namespace Mageplaza\HelloWorld\Model;
use Magento\Framework\Model\AbstractModel;
class ProductReviews extends AbstractModel{

    protected $_ratingFactory;
    protected $_productFactory;
    protected $_ratingFactory;
    protected $_reviewFactory;

    public function __construct(
            \Magento\Store\Model\StoreManagerInterface $storeManager,
            \Magento\Catalog\Model\ProductFactory $productFactory,
            \Magento\Review\Model\RatingFactory $ratingFactory,
            \Magento\Review\Model\ResourceModel\Review\CollectionFactory $reviewFactory,
        ) {
            $this->_storeManager = $storeManager;
            $this->_productFactory = $productFactory;
            $this->_ratingFactory = $ratingFactory;
            $this->_reviewFactory = $reviewFactory;
        }

    public function getReviewCollection($productId){
        $collection = $this->_reviewFactory->create()
        ->addStatusFilter(
            \Magento\Review\Model\Review::STATUS_APPROVED
        )->addEntityFilter(
            'product',
            $productId
        )->setDateOrder();

    }

    public function getRatingCollection(){
        $ratingCollection = $this->_ratingFactory->create()
        ->getResourceCollection()
        ->addEntityFilter(
            'product' 
        )->setPositionOrder()->setStoreFilter(
            $this->_storeManager->getStore()->getId()
        )->addRatingPerStoreName(
            $this->_storeManager->getStore()->getId()
        )->load();

        return $ratingCollection->getData();
    }

}

结论

以上是关于如何在Magento 2中进行产品评审和评级收集的说明。我希望这篇文章在获取和管理集合时对您有所帮助

赞(0)
微信
支付宝
微信二维码图片

微信扫描二维码打赏

支付宝二维码图片

支付宝扫描二维码打赏

相关文章

Please Login to comment