coupon.php (999B)
1 <?php 2 class ControllerApiCoupon extends Controller { 3 public function index() { 4 $this->load->language('api/coupon'); 5 6 // Delete past coupon in case there is an error 7 unset($this->session->data['coupon']); 8 9 $json = array(); 10 11 if (!isset($this->session->data['api_id'])) { 12 $json['error'] = $this->language->get('error_permission'); 13 } else { 14 $this->load->model('extension/total/coupon'); 15 16 if (isset($this->request->post['coupon'])) { 17 $coupon = $this->request->post['coupon']; 18 } else { 19 $coupon = ''; 20 } 21 22 $coupon_info = $this->model_extension_total_coupon->getCoupon($coupon); 23 24 if ($coupon_info) { 25 $this->session->data['coupon'] = $this->request->post['coupon']; 26 27 $json['success'] = $this->language->get('text_success'); 28 } else { 29 $json['error'] = $this->language->get('error_coupon'); 30 } 31 } 32 33 $this->response->addHeader('Content-Type: application/json'); 34 $this->response->setOutput(json_encode($json)); 35 } 36 }