PageRenderTime 44ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/magento/app/code/core/Mage/Reports/Block/Product/Abstract.php

https://bitbucket.org/jit_bec/shopifine
PHP | 173 lines | 70 code | 20 blank | 83 comment | 8 complexity | f71d1beea0b2f39f275064dcabd5172e MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Reports
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Reports Recently Products Abstract Block
  28. *
  29. * @category Mage
  30. * @package Mage_Reports
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. abstract class Mage_Reports_Block_Product_Abstract extends Mage_Catalog_Block_Product_Abstract
  34. {
  35. /**
  36. * Product Index model name
  37. *
  38. * @var string
  39. */
  40. protected $_indexName;
  41. /**
  42. * Product Index model instance
  43. *
  44. * @var Mage_Reports_Model_Product_Index_Abstract
  45. */
  46. protected $_indexModel;
  47. /**
  48. * Product Index Collection
  49. *
  50. * @var Mage_Reports_Model_Mysql4_Product_Index_Collection_Abstract
  51. */
  52. protected $_collection;
  53. /**
  54. * Retrieve page size
  55. *
  56. * @return int
  57. */
  58. public function getPageSize()
  59. {
  60. if ($this->hasData('page_size')) {
  61. return $this->getData('page_size');
  62. }
  63. return 5;
  64. }
  65. /**
  66. * Retrieve product ids, that must not be included in collection
  67. *
  68. * @return array
  69. */
  70. protected function _getProductsToSkip()
  71. {
  72. return array();
  73. }
  74. /**
  75. * Retrieve Product Index model instance
  76. *
  77. * @return Mage_Reports_Model_Product_Index_Abstract
  78. */
  79. protected function _getModel()
  80. {
  81. if (is_null($this->_indexModel)) {
  82. if (is_null($this->_indexName)) {
  83. Mage::throwException(Mage::helper('reports')->__('Index model name must be defined'));
  84. }
  85. $this->_indexModel = Mage::getModel($this->_indexName);
  86. }
  87. return $this->_indexModel;
  88. }
  89. /**
  90. * Public method for retrieve Product Index model
  91. *
  92. * @return Mage_Reports_Model_Product_Index_Abstract
  93. */
  94. public function getModel()
  95. {
  96. return $this->_getModel();
  97. }
  98. /**
  99. * Retrieve Index Product Collection
  100. *
  101. * @return Mage_Reports_Model_Resource_Product_Index_Collection_Abstract
  102. */
  103. public function getItemsCollection()
  104. {
  105. if (is_null($this->_collection)) {
  106. $attributes = Mage::getSingleton('catalog/config')->getProductAttributes();
  107. $this->_collection = $this->_getModel()
  108. ->getCollection()
  109. ->addAttributeToSelect($attributes);
  110. if ($this->getCustomerId()) {
  111. $this->_collection->setCustomerId($this->getCustomerId());
  112. }
  113. $this->_collection->excludeProductIds($this->_getModel()->getExcludeProductIds())
  114. ->addUrlRewrite()
  115. ->setPageSize($this->getPageSize())
  116. ->setCurPage(1);
  117. /* Price data is added to consider item stock status using price index */
  118. $this->_collection->addPriceData();
  119. $ids = $this->getProductIds();
  120. if (empty($ids)) {
  121. $this->_collection->addIndexFilter();
  122. } else {
  123. $this->_collection->addFilterByIds($ids);
  124. }
  125. $this->_collection->setAddedAtOrder();
  126. Mage::getSingleton('catalog/product_visibility')
  127. ->addVisibleInSiteFilterToCollection($this->_collection);
  128. }
  129. return $this->_collection;
  130. }
  131. /**
  132. * Retrieve count of product index items
  133. *
  134. * @return int
  135. */
  136. public function getCount()
  137. {
  138. if (!$this->_getModel()->getCount()) {
  139. return 0;
  140. }
  141. return $this->getItemsCollection()->count();
  142. }
  143. /**
  144. * Get products collection and apply recent events log to it
  145. *
  146. * @deprecated
  147. * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
  148. */
  149. protected function _getRecentProductsCollection()
  150. {
  151. return $this->getItemsCollection();
  152. }
  153. }