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_Adminhtml_Block_Widget_Grid_Column_Filter_Price extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Abstract
35: {
36: protected $_currencyList = null;
37: protected $_currencyModel = null;
38:
39: public function getHtml()
40: {
41: $html = '<div class="range">';
42: $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>';
43: $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>';
44: if ($this->getDisplayCurrencySelect())
45: $html .= '<div class="range-line"><span class="label">' . Mage::helper('adminhtml')->__('In').' : </span>' . $this->_getCurrencySelectHtml() . '</div>';
46: $html .= '</div>';
47:
48: return $html;
49: }
50:
51: public function getDisplayCurrencySelect()
52: {
53: if (!is_null($this->getColumn()->getData('display_currency_select'))) {
54: return $this->getColumn()->getData('display_currency_select');
55: } else {
56: return true;
57: }
58: }
59:
60: public function getCurrencyAffect()
61: {
62: if (!is_null($this->getColumn()->getData('currency_affect'))) {
63: return $this->getColumn()->getData('currency_affect');
64: } else {
65: return true;
66: }
67: }
68:
69: protected function _getCurrencyModel()
70: {
71: if (is_null($this->_currencyModel))
72: $this->_currencyModel = Mage::getModel('directory/currency');
73:
74: return $this->_currencyModel;
75: }
76:
77: protected function _getCurrencySelectHtml()
78: {
79:
80: $value = $this->getEscapedValue('currency');
81: if (!$value)
82: $value = $this->getColumn()->getCurrencyCode();
83:
84: $html = '';
85: $html .= '<select name="'.$this->_getHtmlName().'[currency]" id="'.$this->_getHtmlId().'_currency">';
86: foreach ($this->_getCurrencyList() as $currency) {
87: $html .= '<option value="' . $currency . '" '.($currency == $value ? 'selected="selected"' : '').'>' . $currency . '</option>';
88: }
89: $html .= '</select>';
90: return $html;
91: }
92:
93: protected function _getCurrencyList()
94: {
95: if (is_null($this->_currencyList)) {
96: $this->_currencyList = $this->_getCurrencyModel()->getConfigAllowCurrencies();
97: }
98: return $this->_currencyList;
99: }
100:
101: public function getValue($index=null)
102: {
103: if ($index) {
104: return $this->getData('value', $index);
105: }
106: $value = $this->getData('value');
107: if ((isset($value['from']) && strlen($value['from']) > 0) || (isset($value['to']) && strlen($value['to']) > 0)) {
108: return $value;
109: }
110: return null;
111: }
112:
113:
114: public function getCondition()
115: {
116: $value = $this->getValue();
117:
118: if (isset($value['currency']) && $this->getCurrencyAffect()) {
119: $displayCurrency = $value['currency'];
120: } else {
121: $displayCurrency = $this->getColumn()->getCurrencyCode();
122: }
123: $rate = $this->_getRate($displayCurrency, $this->getColumn()->getCurrencyCode());
124:
125: if (isset($value['from']))
126: $value['from'] *= $rate;
127:
128: if (isset($value['to']))
129: $value['to'] *= $rate;
130:
131: $this->prepareRates($displayCurrency);
132: return $value;
133: }
134:
135: protected function _getRate($from, $to)
136: {
137: return Mage::getModel('directory/currency')->load($from)->getAnyRate($to);
138: }
139:
140: public function prepareRates($displayCurrency)
141: {
142: $storeCurrency = $this->getColumn()->getCurrencyCode();
143:
144: $rate = $this->_getRate($storeCurrency, $displayCurrency);
145: if ($rate) {
146: $this->getColumn()->setRate($rate);
147: $this->getColumn()->setCurrencyCode($displayCurrency);
148: }
149: }
150: }
151: