Magento 2 : 홈페이지에서 베스트셀러 및 가장 많이 본 제품


13

홈페이지 Magento 2 에서 베스트셀러와 가장 많이 본 제품 을 얻는 방법 ?

magento 2의 홈페이지 슬라이더에 베스트셀러 및 가장 많이 본 제품 목록 을 표시해야합니다 .

답변:


12

베스트 셀러의 __construct경우 get 인스턴스 에서 블록을 만듭니다.

\Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory $collectionFactory,

전의

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

}

최근에 본다면 관리자 측에서 위젯을 사용하거나 다른 방법으로 사용자 정의 블록을 작성할 수 있습니다 \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 

가장 많이 본 제품 목록을 얻는 방법?
— Rakesh Jesadiya

베스트셀러가 당신을 위해 일한다면 내 답변을 수락하여 다른 사람들에게 유용 할 것입니다
— Pradeep Kumar

좋아, 먼저 베스트셀러를 확인하겠습니다. 감사.
— Rakesh Jesadiya

잘 작동하면 제품 ID와 이름을 얻을 수 있습니다. 수집을 위해 각 루프에 넣고 데이터를 인쇄하십시오
— Pradeep Kumar

1
@RBJesadiya :-포럼에서 당신은 당신의 작업에 100 % 솔루션을 얻지 못할 것입니다, 당신은 아이디어를 얻을 것입니다.
— Pradeep Kumar

0

다음 코드를 사용하여 Magento 2 슬라이더에서 BEST SELLER와 가장 많이 본 제품을 봅니다.

<?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'); ?>

사이트를 처음 시작할 때 판매 데이터가 없으므로 판매 테이블에 아무것도없는 경우 카탈로그에서 임의의 제품을 검색하는 등의 백업 논리를 추가해야합니다.
— thdoan
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.