Viewed.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Reports\Block\Product;
  7. use \Magento\Framework\DataObject\IdentityInterface;
  8. /**
  9. * Reports Recently Viewed Products Block
  10. *
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. * @deprecated 100.2.0
  13. */
  14. class Viewed extends AbstractProduct implements IdentityInterface
  15. {
  16. /**
  17. * Config path to recently viewed product count
  18. */
  19. const XML_PATH_RECENTLY_VIEWED_COUNT = 'catalog/recently_products/viewed_count';
  20. /**
  21. * Viewed Product Index type
  22. *
  23. * @var string
  24. */
  25. protected $_indexType = \Magento\Reports\Model\Product\Index\Factory::TYPE_VIEWED;
  26. /**
  27. * Retrieve page size (count)
  28. *
  29. * @return int
  30. */
  31. public function getPageSize()
  32. {
  33. if ($this->hasData('page_size')) {
  34. return $this->getData('page_size');
  35. }
  36. return $this->_scopeConfig->getValue(
  37. self::XML_PATH_RECENTLY_VIEWED_COUNT,
  38. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  39. );
  40. }
  41. /**
  42. * Added predefined ids support
  43. *
  44. * @return int
  45. */
  46. public function getCount()
  47. {
  48. $ids = $this->getProductIds();
  49. if (!empty($ids)) {
  50. return count($ids);
  51. }
  52. return parent::getCount();
  53. }
  54. /**
  55. * Prepare to html
  56. * check has viewed products
  57. *
  58. * @return string
  59. */
  60. protected function _toHtml()
  61. {
  62. $this->setRecentlyViewedProducts($this->getItemsCollection());
  63. return parent::_toHtml();
  64. }
  65. /**
  66. * Return identifiers for produced content
  67. *
  68. * @return array
  69. */
  70. public function getIdentities()
  71. {
  72. $identities = [];
  73. foreach ($this->getItemsCollection() as $item) {
  74. $identities = array_merge($identities, $item->getIdentities());
  75. }
  76. return $identities;
  77. }
  78. }