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_Tag
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: /**
28: * List of tagged products
29: *
30: * @category Mage
31: * @package Mage_Tag
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34:
35: class Mage_Tag_Block_Product_Result extends Mage_Catalog_Block_Product_Abstract
36: {
37: protected $_productCollection;
38:
39:
40: public function getTag()
41: {
42: return Mage::registry('current_tag');
43: }
44:
45: protected function _prepareLayout()
46: {
47: $title = $this->getHeaderText();
48: $this->getLayout()->getBlock('head')->setTitle($title);
49: $this->getLayout()->getBlock('root')->setHeaderTitle($title);
50: return parent::_prepareLayout();
51: }
52:
53: public function setListOrders() {
54: $this->getChild('search_result_list')
55: ->setAvailableOrders(array(
56: 'name' => Mage::helper('tag')->__('Name'),
57: 'price'=>Mage::helper('tag')->__('Price'))
58: );
59: }
60:
61: public function setListModes() {
62: $this->getChild('search_result_list')
63: ->setModes(array(
64: 'grid' => Mage::helper('tag')->__('Grid'),
65: 'list' => Mage::helper('tag')->__('List'))
66: );
67: }
68:
69: public function setListCollection() {
70: $this->getChild('search_result_list')
71: ->setCollection($this->_getProductCollection());
72: }
73:
74: public function getProductListHtml()
75: {
76: return $this->getChildHtml('search_result_list');
77: }
78:
79: protected function _getProductCollection()
80: {
81: if(is_null($this->_productCollection)) {
82: $tagModel = Mage::getModel('tag/tag');
83: $this->_productCollection = $tagModel->getEntityCollection()
84: ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
85: ->addTagFilter($this->getTag()->getId())
86: ->addStoreFilter(Mage::app()->getStore()->getId())
87: ->addMinimalPrice()
88: ->addUrlRewrite()
89: ->setActiveFilter();
90: Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_productCollection);
91: Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($this->_productCollection);
92: }
93:
94: return $this->_productCollection;
95: }
96:
97: public function getResultCount()
98: {
99: if (!$this->getData('result_count')) {
100: $size = $this->_getProductCollection()->getSize();
101: $this->setResultCount($size);
102: }
103: return $this->getData('result_count');
104: }
105:
106: public function getHeaderText()
107: {
108: if( $this->getTag()->getName() ) {
109: return Mage::helper('tag')->__("Products tagged with '%s'", $this->htmlEscape($this->getTag()->getName()));
110: } else {
111: return false;
112: }
113: }
114:
115: public function getSubheaderText()
116: {
117: return false;
118: }
119:
120: public function getNoResultText()
121: {
122: return Mage::helper('tag')->__('No matches found.');
123: }
124: }
125: