Newer
Older
Andrei Mateescu
committed
1
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
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* Filter handler to convert price filter to use decimal + currency.
*/
class commerce_price_handler_filter_commerce_price_amount extends views_handler_filter_numeric {
function operators() {
$operators = parent::operators();
// Remove the regular expression operator.
unset($operators['regular_expression']);
return $operators;
}
function option_definition(){
$options = parent::option_definition();
$options['currency'] = array('default' => commerce_default_currency());
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['currency'] = array(
'#type' => 'select',
'#title' => t('Currency'),
'#description' => t('Pick a currency to use for this filter.'),
'#options' => commerce_currency_code_options_list(),
'#default_value' => $this->options['currency'],
);
}
function query() {
// Convert user input to a price amount based on selected currency.
foreach ($this->value as $key => $value) {
if ($value) {
$this->value[$key] = commerce_currency_decimal_to_amount($value, $this->options['currency']);
}
}
parent::query();
}
}