質問

Bestsellerと最も視聴された製品がホームページ magento 2

マゼント2のホームページスライダに BestSellerと最も視聴製品リストを表示する必要があります。

役に立ちましたか?

解決

BestSeller __constructでブロックを作成する

のインスタンスを取得します。
\Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory $collectionFactory,
.

ex

<?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 Sideからウィジェットを使用できます。そうしないと、カスタムブロックを書くことができます。 \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 
.

他のヒント

マージン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