00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_CatalogSearch_Block_Advanced_Form extends Mage_Core_Block_Template
00035 {
00036 public function _prepareLayout()
00037 {
00038 if ($headBlock = $this->getLayout()->getBlock('head')) {
00039 $headBlock->setTitle(Mage::helper('catalogsearch')->__('Catalog Advanced Search'));
00040 }
00041
00042
00043 if ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) {
00044 $breadcrumbs->addCrumb('home', array(
00045 'label'=>Mage::helper('catalogsearch')->__('Home'),
00046 'title'=>Mage::helper('catalogsearch')->__('Go to Home Page'),
00047 'link'=>Mage::getBaseUrl()
00048 ))->addCrumb('search', array(
00049 'label'=>Mage::helper('catalogsearch')->__('Catalog Advanced Search')
00050 ));
00051 }
00052 return parent::_prepareLayout();
00053 }
00054
00055
00056
00057
00058
00059
00060 public function getSearchableAttributes()
00061 {
00062 $attributes = $this->getModel()->getAttributes();
00063 return $attributes;
00064 }
00065
00066
00067
00068
00069
00070
00071
00072 public function getAttributeLabel($attribute)
00073 {
00074 return Mage::helper('catalog')->__($attribute->getFrontend()->getLabel());
00075 }
00076
00077
00078
00079
00080
00081
00082
00083 public function getAttributeValidationClass($attribute)
00084 {
00085 return $attribute->getFrontendClass();
00086 }
00087
00088 public function getAttributeValue($attribute, $part=null)
00089 {
00090 $value = $this->getRequest()->getQuery($attribute->getAttributeCode());
00091 if ($part && $value) {
00092 if (isset($value[$part])) {
00093 $value = $value[$part];
00094 }
00095 else {
00096 $value = '';
00097 }
00098 }
00099
00100 if (!is_array($value)) {
00101 $value = htmlspecialchars($value);
00102 }
00103 return $value;
00104 }
00105
00106 public function getAvailableCurrencies()
00107 {
00108 $currencies = $this->getData('_currencies');
00109 if (is_null($currencies)) {
00110 $currencies = array();
00111 $codes = Mage::app()->getStore()->getAvailableCurrencyCodes(true);
00112 if (is_array($codes) && count($codes)) {
00113 $rates = Mage::getModel('directory/currency')->getCurrencyRates(
00114 Mage::app()->getStore()->getBaseCurrency(),
00115 $codes
00116 );
00117
00118 foreach ($codes as $code) {
00119 if (isset($rates[$code])) {
00120 $currencies[$code] = $code;
00121 }
00122 }
00123 }
00124
00125 $this->setData('currencies', $currencies);
00126 }
00127 return $currencies;
00128 }
00129
00130 public function getCurrencyCount()
00131 {
00132 return count($this->getAvailableCurrencies());
00133 }
00134
00135 public function getCurrency($attribute)
00136 {
00137 return Mage::app()->getStore()->getCurrentCurrencyCode();
00138
00139 $baseCurrency = Mage::app()->getStore()->getBaseCurrency()->getCurrencyCode();
00140 return $this->getAttributeValue($attribute, 'currency') ? $this->getAttributeValue($attribute, 'currency') : $baseCurrency;
00141 }
00142
00143
00144
00145
00146
00147
00148
00149 public function getAttributeInputType($attribute)
00150 {
00151 $dataType = $attribute->getBackend()->getType();
00152 $imputType = $attribute->getFrontend()->getInputType();
00153 if ($imputType == 'select' || $imputType == 'multiselect') {
00154 return 'select';
00155 }
00156
00157 if ($imputType == 'boolean') {
00158 return 'yesno';
00159 }
00160
00161 if ($imputType == 'price') {
00162 return 'price';
00163 }
00164
00165 if ($dataType == 'int' || $dataType == 'decimal') {
00166 return 'number';
00167 }
00168
00169 if ($dataType == 'datetime') {
00170 return 'date';
00171 }
00172
00173 return 'string';
00174 }
00175
00176 public function getAttributeSelectElement($attribute)
00177 {
00178 $extra = '';
00179 $options = $attribute->getSource()->getAllOptions(false);
00180
00181 $name = $attribute->getAttributeCode();
00182
00183
00184 if (is_array($options) && count($options)>2) {
00185 $extra = 'multiple="multiple" size="4"';
00186 $name.= '[]';
00187 }
00188 else {
00189 array_unshift($options, array('value'=>'', 'label'=>Mage::helper('catalogsearch')->__('All')));
00190 }
00191
00192
00193
00194 return $this->_getSelectBlock()
00195 ->setName($name)
00196 ->setId($attribute->getAttributeCode())
00197 ->setTitle($this->getAttributeLabel($attribute))
00198 ->setExtraParams($extra)
00199 ->setValue($this->getAttributeValue($attribute))
00200 ->setOptions($options)
00201 ->setClass('multiselect')
00202 ->getHtml();
00203 }
00204
00205 public function getAttributeYesNoElement($attribute)
00206 {
00207 $options = array(
00208 array('value' => '', 'label' => Mage::helper('catalogsearch')->__('All')),
00209 array('value' => '1', 'label' => Mage::helper('catalogsearch')->__('Yes')),
00210 array('value' => '0', 'label' => Mage::helper('catalogsearch')->__('No'))
00211 );
00212
00213 $name = $attribute->getAttributeCode();
00214 return $this->_getSelectBlock()
00215 ->setName($name)
00216 ->setId($attribute->getAttributeCode())
00217 ->setTitle($this->getAttributeLabel($attribute))
00218 ->setExtraParams("")
00219 ->setValue($this->getAttributeValue($attribute))
00220 ->setOptions($options)
00221 ->getHtml();
00222 }
00223
00224 protected function _getSelectBlock()
00225 {
00226 $block = $this->getData('_select_block');
00227 if (is_null($block)) {
00228 $block = $this->getLayout()->createBlock('core/html_select');
00229 $this->setData('_select_block', $block);
00230 }
00231 return $block;
00232 }
00233
00234 protected function _getDateBlock()
00235 {
00236 $block = $this->getData('_date_block');
00237 if (is_null($block)) {
00238 $block = $this->getLayout()->createBlock('core/html_date');
00239 $this->setData('_date_block', $block);
00240 }
00241 return $block;
00242 }
00243
00244
00245
00246
00247
00248 public function getModel()
00249 {
00250 return Mage::getSingleton('catalogsearch/advanced');
00251 }
00252
00253 public function getSearchPostUrl()
00254 {
00255 return $this->getUrl('*/*/result');
00256 }
00257
00258 public function getDateInput($attribute, $part = 'from')
00259 {
00260 $name = $attribute->getAttributeCode() . '[' . $part . ']';
00261 $value = $this->getAttributeValue($attribute, $part);
00262
00263 return $this->_getDateBlock()
00264 ->setName($name)
00265 ->setId($attribute->getAttributeCode() . '_' . $part)
00266 ->setTitle($this->getAttributeLabel($attribute))
00267 ->setValue($value)
00268 ->setImage($this->getSkinUrl('images/calendar.gif'))
00269 ->setFormat('%m/%d/%y')
00270 ->setClass('input-text')
00271 ->getHtml();
00272 }
00273 }