Rounding.php
1017 Bytes
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
namespace ACA\WC;
use AC\Ajax;
use AC\Registerable;
final class Rounding implements Registerable
{
public function register(): void
{
$this->get_ajax_handler()->register();
}
protected function get_ajax_handler(): Ajax\Handler
{
$handler = new Ajax\Handler();
$handler->set_action('acp-rounding')
->set_callback([$this, 'ajax_send_feedback']);
return $handler;
}
public function ajax_send_feedback(): void
{
$price = filter_input(INPUT_GET, 'price');
$decimals = filter_input(INPUT_GET, 'decimals');
$rounding = new Helper\Price\Rounding();
switch (filter_input(INPUT_GET, 'type')) {
case 'roundup':
echo $rounding->up($price, $decimals);
exit;
case 'rounddown':
echo $rounding->down($price, $decimals);
exit;
default :
echo $price;
exit;
}
}
}