Closed technoquo closed 5 years ago
@technoquo thank you for your feedback. Please, format this issue according to the Issue reporting guidelines: with steps to reproduce, actual result and expected result. Please, also identify which version of Magento you are running. If you are looking for an advice and discussion please refer to the Community Forums or the Magento Stack Exchange site as GitHub issue tracker is intended for technical issues only.
Hi, Valoraven, sure I will explain follow with guidelines:
Title: "add ->addViewsCount()"
# Prediction Our version Magento CE 2.1.2
# Reproduce
namespace Lncnacion\Hello\Block;
use Magento\Framework\View\Element\Template;
class Hello extends Template {
protected $_coreRegistry = null;
/**
* @var \Magento\Reports\Model\ResourceModel\Product\CollectionFactory
*/
protected $_reportsCollectionFactory;
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Reports\Model\ResourceModel\Product\CollectionFactory $reportsCollectionFactory,
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Reports\Model\ResourceModel\Product\CollectionFactory $reportsCollectionFactory,
array $data = []
) {
$this->_reportsCollectionFactory = $reportsCollectionFactory;
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}
public function _prepareLayout()
{
return parent::_prepareLayout();
}
/**
* Getting most viewed products
*/
public function getViewedProducts() {
$storeId = $this->_storeManager->getStore()->getId();
$productCount = 5;
$collection = $this->_reportsCollectionFactory->create()
->addAttributeToSelect('*')
->setStoreId($storeId)
->addStoreFilter($storeId)
->setPageSize($productCount);
return $collection;
}
}
Crate a sample.phtml (magento2\app\code\Lncnacion\Hello\view\frontend\templates)
$products = $this->getViewedProducts();
if ($products->count()) { ?> Most Viewed Products
<?php foreach($products as $product) :
$productUrl = $product->getUrlModel()->getUrl($product);
$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
$productImage = $_imagehelper->init($product, 'category_page_list')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(400)->getUrl();
?>
<?php echo $product->getName(); ?>
<?php endforeach;?>
Show results all product without AddCountViews , that's ok then when add when add ->addViewsCount() with range date in most viewed products
$today = time(); $yesterday = $today - (606024*1);
$from = date("Y-m-d", $yesterday);
$to = date("Y-m-d", $today);
$collection = $this->_reportsCollectionFactory->create()
->addAttributeToSelect('*')
->addViewsCount()
->addViewsCount($from,$to)
->setStoreId($storeId)
->addStoreFilter($storeId)
->setPageSize($productCount);
Not showing product when added addViewsCount().
# Expected result: Show most viewed products on homepage
# Actual result: Show blank
That's problem without addViewsCount() yes show products but when add addViewsCount() for most view product not show products.
Any solution?
@technoquo, thank you for your report. We've created internal ticket(s) MAGETWO-80087 to track progress on the issue.
@okorshenko it is working fine in Magento 2.2, may be It was creating an issue on older version @technoquo
@keyurshah070 I was able to reproduce this in 2.2. Can you double check please?
@miguelbalparda Still I can not reproduce this on magento 2.2 , I am trying on module router not on home page. You are trying to on home page ? This is my code
$storeId = $this->_storeManager->getStore()->getId();
$productCount = 5;
$today = time();
$yesterday = $today - (606024*1);
$from = date("Y-m-d", $yesterday);
$to = date("Y-m-d", $today);
$collection = $this->_reportsCollectionFactory->create()
->addAttributeToSelect('*')
->addViewsCount()
->addViewsCount($from,$to)
->setStoreId($storeId)
->addStoreFilter($storeId)
->setPageSize($productCount);
return $collection;
and here is my phtml code
<?php
$products = $this->getViewedProducts();
?>
<?php foreach($products as $product) :
$productUrl = $product->getUrlModel()->getUrl($product);
$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
$productImage = $_imagehelper->init($product, 'category_page_list')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(400)->getUrl();
?>
<?php echo $product->getName(); ?>
<img src="<?php echo $productImage?>" alt="image" height="100"/>
<?php endforeach;?>
<?php exit;?>
@miguelbalparda did you get the chance to confirm or my code ?
Due to no activities for a long time, the Issue should be re-verified and Confirmed is it still reproducible on 2.3-develop
, 2.2-develop
I am working on this at #dmcdindia1
Hi @darshan-khatri-16. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.3-develop
branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop
branch, please, add the label Reproduced on 2.3.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Verify that the issue is reproducible on 2.2-develop
branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop
branch, please add the label Reproduced on 2.2.x
Hi,
Its working as expected but you need to pass entire date and time in $to
like below:
$storeId = $this->_storeManager->getStore()->getId();
$productCount = 5;
$today = time();
$yesterday = $today - (606024 * 1);
$from = date("Y-m-d", $yesterday);
$to = date("Y-m-d", $today) . " 23:59:59";
$collection = $this->_reportsCollectionFactory->create() ->addAttributeToSelect('*') ->addViewsCount() ->addViewsCount($from, $to) ->setStoreId($storeId) ->addStoreFilter($storeId) ->setPageSize($productCount);
return $collection;
Products image not showing when add ->addViewsCount() in most-viewed products I have added a new module “Most Viewed Products” Block in product view page
public function getViewedProducts() { $storeId = $this->_storeManager->getStore()->getId(); $getViewedProducts = $this->_reportsCollectionFactory->create() ->addAttributeToSelect('*') ->addViewsCount() ->setStoreId($storeId) ->addStoreFilter($storeId);
return $getViewedProducts; } and success.phtml
<?php $products = $this->getViewedProducts(); if ($products->count()) { ?>
Most Viewed Products
getUrlModel()->getUrl($product); $_imagehelper = $this->helper('Magento\Catalog\Helper\Image'); $productImage = $_imagehelper->init($product, 'category_page_list')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(400)->getUrl(); ?>-
getName(); ?>
<?php } ?>
Is working but Products image not showing when add ->addViewsCount() in most-viewed products
I hope your help, Thanks
Preconditions
Our version Magento CE 2.1.2
Steps to reproduce
for Most View Product create a block Lncnacion\Hello\Block namespace Lncnacion\Hello\Block;
use Magento\Framework\View\Element\Template;
class Hello extends Template {
protected $_coreRegistry = null;
/**
/**
@param array $data */ public function construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Reports\Model\ResourceModel\Product\CollectionFactory $reportsCollectionFactory, array $data = [] ) { $this->_reportsCollectionFactory = $reportsCollectionFactory; $this->_coreRegistry = $registry; parent::construct($context, $data); }
public function _prepareLayout() { return parent::_prepareLayout(); }
/**
Getting most viewed products */ public function getViewedProducts() {
$storeId = $this->_storeManager->getStore()->getId(); $productCount = 5;
$collection = $this->_reportsCollectionFactory->create() ->addAttributeToSelect('*')
->setStoreId($storeId) ->addStoreFilter($storeId)
->setPageSize($productCount);
return $collection; } }
Crate a sample.phtml (magento2\app\code\Lncnacion\Hello\view\frontend\templates)
$products = $this->getViewedProducts();
if ($products->count()) { ?> Most Viewed Products
Show results all product without AddCountViews , that's ok then when add when add ->addViewsCount() with range date in most viewed products
$today = time(); $yesterday = $today - (606024*1);
$from = date("Y-m-d", $yesterday); $to = date("Y-m-d", $today); $collection = $this->_reportsCollectionFactory->create() ->addAttributeToSelect('*') ->addViewsCount() ->addViewsCount($from,$to) ->setStoreId($storeId) ->addStoreFilter($storeId) ->setPageSize($productCount);
Not showing product when added addViewsCount().
Expected result:
Show most viewed products on homepage
Actual result:
Show blank
That's problem without addViewsCount() yes show products but when add addViewsCount() for most view product not show products.