0

i want to get all data from magento core table table name is

report_viewed_product_index

i searched on stakeexchange and found some solution but havn't for success

class Wbtab extends \Magento\Framework\View\Element\Template
{
    protected $_recentlyViewed;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Reports\Block\Product\Viewed $recentlyViewed,
        array $data = []
    ) {
        $this->_recentlyViewed = $recentlyViewed;
        parent::__construct($context, $data);
    }



    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }
    public function getOrderItems()
    {
        echo "<pre>";
        $collection = $this->_recentlyViewed->getItemsCollection();

        print_r($collection->load()->getData());
        exit();

    }
}
  • get recent view product collection ???? – Rk Rathod Jun 12 at 10:04
  • yesss actually that what i want but i am gettingnull when tried that code – Waqar Ali Jun 12 at 10:06
  • try this print_r($collection->getData()); – Prathap Gunasekaran Jun 12 at 10:08
  • tried that already still getting same – Waqar Ali Jun 12 at 10:10
1

Try This :-

class Wbtab extends \Magento\Framework\View\Element\Template
{
    protected $_recentlyViewed;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Reports\Block\Product\Viewed $recentlyViewed,
        array $data = []
    ){
        $this->_recentlyViewed = $recentlyViewed;
        parent::__construct($context, $data);
    }  
    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }
    public function getOrderItems()
    {
        echo "<pre>";
        $collection = $this->_recentlyViewed->getItemsCollection();
        foreach($collection as $data)
        {
             $info = $data->getData();
             print_r($info);      
        }
    }
}
  • thank you.. its working – Waqar Ali Jun 12 at 10:23
  • wel come..happy coding...:) – Rk Rathod Jun 12 at 10:27
  • can i add filters to collection like product_id filter or date filter – Waqar Ali Jun 12 at 10:49
  • let me check.... – Rk Rathod Jun 12 at 10:51
  • another thing when i logout user i returns null – Waqar Ali Jun 12 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.