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: class Mage_CatalogSearch_Block_Advanced_Form extends Mage_Core_Block_Template
35: {
36: public function _prepareLayout()
37: {
38:
39: if ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) {
40: $breadcrumbs->addCrumb('home', array(
41: 'label'=>Mage::helper('catalogsearch')->__('Home'),
42: 'title'=>Mage::helper('catalogsearch')->__('Go to Home Page'),
43: 'link'=>Mage::getBaseUrl()
44: ))->addCrumb('search', array(
45: 'label'=>Mage::helper('catalogsearch')->__('Catalog Advanced Search')
46: ));
47: }
48: return parent::_prepareLayout();
49: }
50:
51: 52: 53: 54: 55:
56: public function getSearchableAttributes()
57: {
58: $attributes = $this->getModel()->getAttributes();
59: return $attributes;
60: }
61:
62: 63: 64: 65: 66: 67:
68: public function getAttributeLabel($attribute)
69: {
70: return $attribute->getStoreLabel();
71: }
72:
73: 74: 75: 76: 77: 78:
79: public function getAttributeValidationClass($attribute)
80: {
81: return $attribute->getFrontendClass();
82: }
83:
84: 85: 86: 87: 88: 89: 90:
91: public function getAttributeValue($attribute, $part=null)
92: {
93: $value = $this->getRequest()->getQuery($attribute->getAttributeCode());
94: if ($part && $value) {
95: if (isset($value[$part])) {
96: $value = $value[$part];
97: }
98: else {
99: $value = '';
100: }
101: }
102:
103: return $value;
104: }
105:
106: 107: 108: 109: 110:
111: public function getAvailableCurrencies()
112: {
113: $currencies = $this->getData('_currencies');
114: if (is_null($currencies)) {
115: $currencies = array();
116: $codes = Mage::app()->getStore()->getAvailableCurrencyCodes(true);
117: if (is_array($codes) && count($codes)) {
118: $rates = Mage::getModel('directory/currency')->getCurrencyRates(
119: Mage::app()->getStore()->getBaseCurrency(),
120: $codes
121: );
122:
123: foreach ($codes as $code) {
124: if (isset($rates[$code])) {
125: $currencies[$code] = $code;
126: }
127: }
128: }
129:
130: $this->setData('currencies', $currencies);
131: }
132: return $currencies;
133: }
134:
135: 136: 137: 138: 139:
140: public function getCurrencyCount()
141: {
142: return count($this->getAvailableCurrencies());
143: }
144:
145: 146: 147: 148: 149: 150:
151: public function getCurrency($attribute)
152: {
153: return Mage::app()->getStore()->getCurrentCurrencyCode();
154:
155: $baseCurrency = Mage::app()->getStore()->getBaseCurrency()->getCurrencyCode();
156: return $this->getAttributeValue($attribute, 'currency') ?
157: $this->getAttributeValue($attribute, 'currency') : $baseCurrency;
158: }
159:
160: 161: 162: 163: 164: 165:
166: public function getAttributeInputType($attribute)
167: {
168: $dataType = $attribute->getBackend()->getType();
169: $imputType = $attribute->getFrontend()->getInputType();
170: if ($imputType == 'select' || $imputType == 'multiselect') {
171: return 'select';
172: }
173:
174: if ($imputType == 'boolean') {
175: return 'yesno';
176: }
177:
178: if ($imputType == 'price') {
179: return 'price';
180: }
181:
182: if ($dataType == 'int' || $dataType == 'decimal') {
183: return 'number';
184: }
185:
186: if ($dataType == 'datetime') {
187: return 'date';
188: }
189:
190: return 'string';
191: }
192:
193: 194: 195: 196: 197: 198:
199: public function getAttributeSelectElement($attribute)
200: {
201: $extra = '';
202: $options = $attribute->getSource()->getAllOptions(false);
203:
204: $name = $attribute->getAttributeCode();
205:
206:
207: if (is_array($options) && count($options)>2) {
208: $extra = 'multiple="multiple" size="4"';
209: $name.= '[]';
210: }
211: else {
212: array_unshift($options, array('value'=>'', 'label'=>Mage::helper('catalogsearch')->__('All')));
213: }
214:
215: return $this->_getSelectBlock()
216: ->setName($name)
217: ->setId($attribute->getAttributeCode())
218: ->setTitle($this->getAttributeLabel($attribute))
219: ->setExtraParams($extra)
220: ->setValue($this->getAttributeValue($attribute))
221: ->setOptions($options)
222: ->setClass('multiselect')
223: ->getHtml();
224: }
225:
226: public function getAttributeYesNoElement($attribute)
227: {
228: $options = array(
229: array('value' => '', 'label' => Mage::helper('catalogsearch')->__('All')),
230: array('value' => '1', 'label' => Mage::helper('catalogsearch')->__('Yes')),
231: array('value' => '0', 'label' => Mage::helper('catalogsearch')->__('No'))
232: );
233:
234: $name = $attribute->getAttributeCode();
235: return $this->_getSelectBlock()
236: ->setName($name)
237: ->setId($attribute->getAttributeCode())
238: ->setTitle($this->getAttributeLabel($attribute))
239: ->setExtraParams("")
240: ->setValue($this->getAttributeValue($attribute))
241: ->setOptions($options)
242: ->getHtml();
243: }
244:
245: protected function _getSelectBlock()
246: {
247: $block = $this->getData('_select_block');
248: if (is_null($block)) {
249: $block = $this->getLayout()->createBlock('core/html_select');
250: $this->setData('_select_block', $block);
251: }
252: return $block;
253: }
254:
255: protected function _getDateBlock()
256: {
257: $block = $this->getData('_date_block');
258: if (is_null($block)) {
259: $block = $this->getLayout()->createBlock('core/html_date');
260: $this->setData('_date_block', $block);
261: }
262: return $block;
263: }
264:
265: 266: 267: 268: 269:
270: public function getModel()
271: {
272: return Mage::getSingleton('catalogsearch/advanced');
273: }
274:
275: 276: 277: 278: 279:
280: public function getSearchPostUrl()
281: {
282: return $this->getUrl('*/*/result');
283: }
284:
285: 286: 287: 288: 289: 290: 291:
292: public function getDateInput($attribute, $part = 'from')
293: {
294: $name = $attribute->getAttributeCode() . '[' . $part . ']';
295: $value = $this->getAttributeValue($attribute, $part);
296:
297: return $this->_getDateBlock()
298: ->setName($name)
299: ->setId($attribute->getAttributeCode() . ($part == 'from' ? '' : '_' . $part))
300: ->setTitle($this->getAttributeLabel($attribute))
301: ->setValue($value)
302: ->setImage($this->getSkinUrl('images/calendar.gif'))
303: ->setFormat('%m/%d/%y')
304: ->setClass('input-text')
305: ->getHtml();
306: }
307: }
308: