1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_CatalogSearch_Block_Result extends Mage_Core_Block_Template
36: {
37: 38: 39: 40: 41:
42: protected $_productCollection;
43:
44: 45: 46: 47: 48:
49: protected function _getQuery()
50: {
51: return $this->helper('catalogsearch')->getQuery();
52: }
53:
54: 55: 56: 57: 58:
59: protected function _prepareLayout()
60: {
61:
62: $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
63: if ($breadcrumbs) {
64: $title = $this->__("Search results for: '%s'", $this->helper('catalogsearch')->getQueryText());
65:
66: $breadcrumbs->addCrumb('home', array(
67: 'label' => $this->__('Home'),
68: 'title' => $this->__('Go to Home Page'),
69: 'link' => Mage::getBaseUrl()
70: ))->addCrumb('search', array(
71: 'label' => $title,
72: 'title' => $title
73: ));
74: }
75:
76:
77: $title = $this->__("Search results for: '%s'", $this->helper('catalogsearch')->getEscapedQueryText());
78: $this->getLayout()->getBlock('head')->setTitle($title);
79:
80: return parent::_prepareLayout();
81: }
82:
83: 84: 85: 86: 87:
88: public function getAdditionalHtml()
89: {
90: return $this->getLayout()->getBlock('search_result_list')->getChildHtml('additional');
91: }
92:
93: 94: 95: 96: 97:
98: public function getListBlock()
99: {
100: return $this->getChild('search_result_list');
101: }
102:
103: 104: 105: 106: 107:
108: public function setListOrders()
109: {
110: $category = Mage::getSingleton('catalog/layer')
111: ->getCurrentCategory();
112:
113: $availableOrders = $category->getAvailableSortByOptions();
114: unset($availableOrders['position']);
115: $availableOrders = array_merge(array(
116: 'relevance' => $this->__('Relevance')
117: ), $availableOrders);
118:
119: $this->getListBlock()
120: ->setAvailableOrders($availableOrders)
121: ->setDefaultDirection('desc')
122: ->setSortBy('relevance');
123:
124: return $this;
125: }
126:
127: 128: 129: 130: 131:
132: public function setListModes()
133: {
134: $this->getListBlock()
135: ->setModes(array(
136: 'grid' => $this->__('Grid'),
137: 'list' => $this->__('List'))
138: );
139: return $this;
140: }
141:
142: 143: 144: 145: 146:
147: public function setListCollection()
148: {
149:
150:
151: return $this;
152: }
153:
154: 155: 156: 157: 158:
159: public function getProductListHtml()
160: {
161: return $this->getChildHtml('search_result_list');
162: }
163:
164: 165: 166: 167: 168:
169: protected function _getProductCollection()
170: {
171: if (is_null($this->_productCollection)) {
172: $this->_productCollection = $this->getListBlock()->getLoadedProductCollection();
173: }
174:
175: return $this->_productCollection;
176: }
177:
178: 179: 180: 181: 182:
183: public function getResultCount()
184: {
185: if (!$this->getData('result_count')) {
186: $size = $this->_getProductCollection()->getSize();
187: $this->_getQuery()->setNumResults($size);
188: $this->setResultCount($size);
189: }
190: return $this->getData('result_count');
191: }
192:
193: 194: 195: 196: 197:
198: public function getNoResultText()
199: {
200: if (Mage::helper('catalogsearch')->isMinQueryLength()) {
201: return Mage::helper('catalogsearch')->__('Minimum Search query length is %s', $this->_getQuery()->getMinQueryLength());
202: }
203: return $this->_getData('no_result_text');
204: }
205:
206: 207: 208: 209: 210:
211: public function getNoteMessages()
212: {
213: return Mage::helper('catalogsearch')->getNoteMessages();
214: }
215: }
216: