Magento 2 : 홈페이지에서 베스트셀러 및 가장 많이 본 제품
-
13-12-2019 - |
문제
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'); ?>
. 제휴하지 않습니다 magento.stackexchange