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_Adminhtml_Block_Widget_Grid_Column_Filter_Price extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Abstract
00035 {
00036 protected $_currencyList = null;
00037 protected $_currencyModel = null;
00038
00039 public function getHtml()
00040 {
00041 $html = '<div class="range">';
00042 $html .= '<div class="range-line"><span class="label">' . Mage::helper('adminhtml')->__('From').':</span> <input type="text" name="'.$this->_getHtmlName().'[from]" id="'.$this->_getHtmlId().'_from" value="'.$this->getEscapedValue('from').'" class="input-text no-changes"/></div>';
00043 $html .= '<div class="range-line"><span class="label">' . Mage::helper('adminhtml')->__('To').' : </span><input type="text" name="'.$this->_getHtmlName().'[to]" id="'.$this->_getHtmlId().'_to" value="'.$this->getEscapedValue('to').'" class="input-text no-changes"/></div>';
00044 if ($this->getDisplayCurrencySelect())
00045 $html .= '<div class="range-line"><span class="label">' . Mage::helper('adminhtml')->__('In').' : </span>' . $this->_getCurrencySelectHtml() . '</div>';
00046 $html .= '</div>';
00047
00048 return $html;
00049 }
00050
00051 public function getDisplayCurrencySelect()
00052 {
00053 if (!is_null($this->getColumn()->getData('display_currency_select'))) {
00054 return $this->getColumn()->getData('display_currency_select');
00055 } else {
00056 return true;
00057 }
00058 }
00059
00060 public function getCurrencyAffect()
00061 {
00062 if (!is_null($this->getColumn()->getData('currency_affect'))) {
00063 return $this->getColumn()->getData('currency_affect');
00064 } else {
00065 return true;
00066 }
00067 }
00068
00069 protected function _getCurrencyModel()
00070 {
00071 if (is_null($this->_currencyModel))
00072 $this->_currencyModel = Mage::getModel('directory/currency');
00073
00074 return $this->_currencyModel;
00075 }
00076
00077 protected function _getCurrencySelectHtml()
00078 {
00079
00080 $value = $this->getEscapedValue('currency');
00081 if (!$value)
00082 $value = $this->getColumn()->getCurrencyCode();
00083
00084 $html = '';
00085 $html .= '<select name="'.$this->_getHtmlName().'[currency]" id="'.$this->_getHtmlId().'_currency">';
00086 foreach ($this->_getCurrencyList() as $currency) {
00087 $html .= '<option value="' . $currency . '" '.($currency == $value ? 'selected="selected"' : '').'>' . $currency . '</option>';
00088 }
00089 $html .= '</select>';
00090 return $html;
00091 }
00092
00093 protected function _getCurrencyList()
00094 {
00095 if (is_null($this->_currencyList)) {
00096 $this->_currencyList = $this->_getCurrencyModel()->getConfigAllowCurrencies();
00097 }
00098 return $this->_currencyList;
00099 }
00100
00101 public function getValue($index=null)
00102 {
00103 if ($index) {
00104 return $this->getData('value', $index);
00105 }
00106 $value = $this->getData('value');
00107 if ((isset($value['from']) && strlen($value['from']) > 0) || (isset($value['to']) && strlen($value['to']) > 0)) {
00108 return $value;
00109 }
00110 return null;
00111 }
00112
00113
00114 public function getCondition()
00115 {
00116 $value = $this->getValue();
00117
00118 if (isset($value['currency']) && $this->getCurrencyAffect()) {
00119 $displayCurrency = $value['currency'];
00120 } else {
00121 $displayCurrency = $this->getColumn()->getCurrencyCode();
00122 }
00123 $rate = $this->_getRate($displayCurrency, $this->getColumn()->getCurrencyCode());
00124
00125 if (isset($value['from']))
00126 $value['from'] *= $rate;
00127
00128 if (isset($value['to']))
00129 $value['to'] *= $rate;
00130
00131 $this->prepareRates($displayCurrency);
00132 return $value;
00133 }
00134
00135 protected function _getRate($from, $to)
00136 {
00137 return Mage::getModel('directory/currency')->load($from)->getRate($to);
00138 }
00139
00140 public function prepareRates($displayCurrency)
00141 {
00142 $storeCurrency = $this->getColumn()->getCurrencyCode();
00143
00144 $rate = $this->_getRate($storeCurrency, $displayCurrency);
00145 if ($rate) {
00146 $this->getColumn()->setRate($rate);
00147 $this->getColumn()->setCurrencyCode($displayCurrency);
00148 }
00149 }
00150 }