blob: 6a3a0107bfeb58afc90f0a60c719da6f0ac31dc1 (
plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<?php
class ControllerExtensionTotalReward extends Controller {
public function index() {
$points = $this->customer->getRewardPoints();
$points_total = 0;
foreach ($this->cart->getProducts() as $product) {
if ($product['points']) {
$points_total += $product['points'];
}
}
if ($points && $points_total && $this->config->get('total_reward_status')) {
$this->load->language('extension/total/reward');
$data['heading_title'] = sprintf($this->language->get('heading_title'), $points);
$data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total);
if (isset($this->session->data['reward'])) {
$data['reward'] = $this->session->data['reward'];
} else {
$data['reward'] = '';
}
return $this->load->view('extension/total/reward', $data);
}
}
public function reward() {
$this->load->language('extension/total/reward');
$json = array();
$points = $this->customer->getRewardPoints();
$points_total = 0;
foreach ($this->cart->getProducts() as $product) {
if ($product['points']) {
$points_total += $product['points'];
}
}
if (empty($this->request->post['reward'])) {
$json['error'] = $this->language->get('error_reward');
}
if ($this->request->post['reward'] > $points) {
$json['error'] = sprintf($this->language->get('error_points'), $this->request->post['reward']);
}
if ($this->request->post['reward'] > $points_total) {
$json['error'] = sprintf($this->language->get('error_maximum'), $points_total);
}
if (!$json) {
$this->session->data['reward'] = abs($this->request->post['reward']);
$this->session->data['success'] = $this->language->get('text_success');
if (isset($this->request->post['redirect'])) {
$json['redirect'] = $this->url->link($this->request->post['redirect']);
} else {
$json['redirect'] = $this->url->link('checkout/cart');
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
|