reward.php (2097B)
1 <?php 2 class ControllerExtensionTotalReward extends Controller { 3 public function index() { 4 $points = $this->customer->getRewardPoints(); 5 6 $points_total = 0; 7 8 foreach ($this->cart->getProducts() as $product) { 9 if ($product['points']) { 10 $points_total += $product['points']; 11 } 12 } 13 14 if ($points && $points_total && $this->config->get('total_reward_status')) { 15 $this->load->language('extension/total/reward'); 16 17 $data['heading_title'] = sprintf($this->language->get('heading_title'), $points); 18 19 $data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total); 20 21 if (isset($this->session->data['reward'])) { 22 $data['reward'] = $this->session->data['reward']; 23 } else { 24 $data['reward'] = ''; 25 } 26 27 return $this->load->view('extension/total/reward', $data); 28 } 29 } 30 31 public function reward() { 32 $this->load->language('extension/total/reward'); 33 34 $json = array(); 35 36 $points = $this->customer->getRewardPoints(); 37 38 $points_total = 0; 39 40 foreach ($this->cart->getProducts() as $product) { 41 if ($product['points']) { 42 $points_total += $product['points']; 43 } 44 } 45 46 if (empty($this->request->post['reward'])) { 47 $json['error'] = $this->language->get('error_reward'); 48 } 49 50 if ($this->request->post['reward'] > $points) { 51 $json['error'] = sprintf($this->language->get('error_points'), $this->request->post['reward']); 52 } 53 54 if ($this->request->post['reward'] > $points_total) { 55 $json['error'] = sprintf($this->language->get('error_maximum'), $points_total); 56 } 57 58 if (!$json) { 59 $this->session->data['reward'] = abs($this->request->post['reward']); 60 61 $this->session->data['success'] = $this->language->get('text_success'); 62 63 if (isset($this->request->post['redirect'])) { 64 $json['redirect'] = $this->url->link($this->request->post['redirect']); 65 } else { 66 $json['redirect'] = $this->url->link('checkout/cart'); 67 } 68 } 69 70 $this->response->addHeader('Content-Type: application/json'); 71 $this->response->setOutput(json_encode($json)); 72 } 73 }