00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Tag 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * List of tagged products 00029 * 00030 * @category Mage 00031 * @package Mage_Tag 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 00035 class Mage_Tag_Block_Product_Result extends Mage_Catalog_Block_Product_Abstract 00036 { 00037 protected $_productCollection; 00038 00039 00040 public function getTag() 00041 { 00042 return Mage::registry('current_tag'); 00043 } 00044 00045 protected function _prepareLayout() 00046 { 00047 $title = $this->getHeaderText(); 00048 $this->getLayout()->getBlock('head')->setTitle($title); 00049 $this->getLayout()->getBlock('root')->setHeaderTitle($title); 00050 return parent::_prepareLayout(); 00051 } 00052 00053 public function setListOrders() { 00054 $this->getChild('search_result_list') 00055 ->setAvailableOrders(array( 00056 'name' => Mage::helper('tag')->__('Name'), 00057 'price'=>Mage::helper('tag')->__('Price')) 00058 ); 00059 } 00060 00061 public function setListModes() { 00062 $this->getChild('search_result_list') 00063 ->setModes(array( 00064 'grid' => Mage::helper('tag')->__('Grid'), 00065 'list' => Mage::helper('tag')->__('List')) 00066 ); 00067 } 00068 00069 public function setListCollection() { 00070 $this->getChild('search_result_list') 00071 ->setCollection($this->_getProductCollection()); 00072 } 00073 00074 public function getProductListHtml() 00075 { 00076 return $this->getChildHtml('search_result_list'); 00077 } 00078 00079 protected function _getProductCollection() 00080 { 00081 if(is_null($this->_productCollection)) { 00082 $tagModel = Mage::getModel('tag/tag'); 00083 $this->_productCollection = $tagModel->getEntityCollection() 00084 ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()) 00085 ->addTagFilter($this->getTag()->getId()) 00086 ->addStoreFilter() 00087 ->addMinimalPrice() 00088 ->addUrlRewrite(); 00089 Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_productCollection); 00090 Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($this->_productCollection); 00091 } 00092 00093 return $this->_productCollection; 00094 } 00095 00096 public function getResultCount() 00097 { 00098 if (!$this->getData('result_count')) { 00099 $size = $this->_getProductCollection()->getSize(); 00100 $this->setResultCount($size); 00101 } 00102 return $this->getData('result_count'); 00103 } 00104 00105 public function getHeaderText() 00106 { 00107 if( $this->getTag()->getName() ) { 00108 return Mage::helper('tag')->__("Products tagged with '%s'", $this->htmlEscape($this->getTag()->getName())); 00109 } else { 00110 return false; 00111 } 00112 } 00113 00114 public function getSubheaderText() 00115 { 00116 return false; 00117 } 00118 00119 public function getNoResultText() 00120 { 00121 return Mage::helper('tag')->__('No matches found.'); 00122 } 00123 }