1: <?php
2: namespace Opencart\Catalog\Controller\Api\Sale;
3: /**
4: * Class Coupon
5: *
6: * @package Opencart\Catalog\Controller\Api\Sale
7: */
8: class Coupon extends \Opencart\System\Engine\Controller {
9: /**
10: * @return void
11: */
12: public function index(): void {
13: $this->load->language('api/sale/coupon');
14:
15: $json = [];
16:
17: if (isset($this->request->post['coupon'])) {
18: $coupon = (string)$this->request->post['coupon'];
19: } else {
20: $coupon = '';
21: }
22:
23: if ($coupon) {
24: $this->load->model('marketing/coupon');
25:
26: $coupon_info = $this->model_marketing_coupon->getCoupon($coupon);
27:
28: if (!$coupon_info) {
29: $json['error'] = $this->language->get('error_coupon');
30: }
31: }
32:
33: if (!$json) {
34: if ($coupon) {
35: $json['success'] = $this->language->get('text_success');
36:
37: $this->session->data['coupon'] = $coupon;
38: } else {
39: $json['success'] = $this->language->get('text_remove');
40:
41: unset($this->session->data['coupon']);
42: }
43: }
44:
45: $this->response->addHeader('Content-Type: application/json');
46: $this->response->setOutput(json_encode($json));
47: }
48: }
49: