coupon.php (1380B)
1 <?php 2 class ControllerExtensionTotalCoupon extends Controller { 3 public function index() { 4 if ($this->config->get('total_coupon_status')) { 5 $this->load->language('extension/total/coupon'); 6 7 if (isset($this->session->data['coupon'])) { 8 $data['coupon'] = $this->session->data['coupon']; 9 } else { 10 $data['coupon'] = ''; 11 } 12 13 return $this->load->view('extension/total/coupon', $data); 14 } 15 } 16 17 public function coupon() { 18 $this->load->language('extension/total/coupon'); 19 20 $json = array(); 21 22 $this->load->model('extension/total/coupon'); 23 24 if (isset($this->request->post['coupon'])) { 25 $coupon = $this->request->post['coupon']; 26 } else { 27 $coupon = ''; 28 } 29 30 $coupon_info = $this->model_extension_total_coupon->getCoupon($coupon); 31 32 if (empty($this->request->post['coupon'])) { 33 $json['error'] = $this->language->get('error_empty'); 34 35 unset($this->session->data['coupon']); 36 } elseif ($coupon_info) { 37 $this->session->data['coupon'] = $this->request->post['coupon']; 38 39 $this->session->data['success'] = $this->language->get('text_success'); 40 41 $json['redirect'] = $this->url->link('checkout/cart'); 42 } else { 43 $json['error'] = $this->language->get('error_coupon'); 44 } 45 46 $this->response->addHeader('Content-Type: application/json'); 47 $this->response->setOutput(json_encode($json)); 48 } 49 }