문제

bestseller와 가장 많이 본 제품 magento 2

우리는 Magento 2의 홈페이지 슬라이더에서 베스트 셀러 및 대부분보기 제품 목록을 표시해야합니다.

도움이 되었습니까?

해결책

베스트 셀러의 경우 __construct에서 블록 생성

의 인스턴스 인스턴스 가져 오기
\Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory $collectionFactory,
.

ex / p>

<?php
namespace Sugarcode\Test\Block;

class Test extends \Magento\Framework\View\Element\Template
{
    protected $_coreRegistry = null;
    protected $_collectionFactory;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Registry $registry,
       \Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory $collectionFactory,
        array $data = []
    ) {
        $this->_collectionFactory = $collectionFactory;
        $this->_coreRegistry = $registry;
        parent::__construct($context, $data);
    }



    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }
    public function getBestSellerData()
    {
        $collection = $this->_collectionFactory->create()->setModel(
            'Magento\Catalog\Model\Product'
        );

        return $collection;
    }       

}
.

최근에 본 admin의 위젯을 사용할 수 있습니다. 그렇지 않으면 사용자 정의 블록을 작성할 수 있습니다. \Magento\Reports\Model\ResourceModel\Product\CollectionFactory $productsFactory

보기 :

vendor\magento\module-backend\Block\Dashboard\Tab\Products\Viewed.php

and

vendor\magento\module-backend\Block\Dashboard\Tab\Products\Ordered.php 
.

다른 팁

다음 코드를 사용하여 Magento 2 슬라이더에서 가장 많이 보는 제품을 볼 수 있습니다.

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();   
$productCollection = $objectManager->create('Magento\Reports\Model\ResourceModel\Report\Collection\Factory'); 
$collection = $productCollection->create('Magento\Sales\Model\ResourceModel\Report\Bestsellers\Collection'); ?>
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top