Back to Opencart

File extension\opencart\catalog\controller\total\coupon.php

docs/api/source-extension.opencart.catalog.controller.total.coupon.html

4.1.0.37.0 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Catalog\Controller\Extension\Opencart\Total; | | 3: | /** | | 4: | * Class Coupon | | 5: | * | | 6: | * @package Opencart\Catalog\Controller\Extension\Opencart\Total | | 7: | */ | | 8: | class Coupon extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * Index | | 11: | * | | 12: | * @return string | | 13: | */ | | 14: | public function index(): string { | | 15: | if ($this->config->get('total_coupon_status')) { | | 16: | $this->load->language('extension/opencart/total/coupon'); | | 17: | | | 18: | $data['save'] = $this->url->link('extension/opencart/total/coupon.save', 'language=' . $this->config->get('config_language'), true); | | 19: | $data['list'] = $this->url->link('checkout/cart.list', 'language=' . $this->config->get('config_language'), true); | | 20: | | | 21: | if (isset($this->session->data['coupon'])) { | | 22: | $data['coupon'] = $this->session->data['coupon']; | | 23: | } else { | | 24: | $data['coupon'] = ''; | | 25: | } | | 26: | | | 27: | return $this->load->view('extension/opencart/total/coupon', $data); | | 28: | } | | 29: | | | 30: | return ''; | | 31: | } | | 32: | | | 33: | /** | | 34: | * Save | | 35: | * | | 36: | * @return void | | 37: | */ | | 38: | public function save(): void { | | 39: | $this->load->language('extension/opencart/total/coupon'); | | 40: | | | 41: | $json = []; | | 42: | | | 43: | if (isset($this->request->post['coupon'])) { | | 44: | $coupon = $this->request->post['coupon']; | | 45: | } else { | | 46: | $coupon = ''; | | 47: | } | | 48: | | | 49: | if (!$this->config->get('total_coupon_status')) { | | 50: | $json['error'] = $this->language->get('error_status'); | | 51: | } | | 52: | | | 53: | if ($coupon) { | | 54: | $this->load->model('marketing/coupon'); | | 55: | | | 56: | $coupon_info = $this->model_marketing_coupon->getCoupon($coupon); | | 57: | | | 58: | if (!$coupon_info) { | | 59: | $json['error'] = $this->language->get('error_coupon'); | | 60: | } | | 61: | } | | 62: | | | 63: | if (!$json) { | | 64: | if ($coupon) { | | 65: | $json['success'] = $this->language->get('text_success'); | | 66: | | | 67: | $this->session->data['coupon'] = $coupon; | | 68: | } else { | | 69: | $json['success'] = $this->language->get('text_remove'); | | 70: | | | 71: | unset($this->session->data['coupon']); | | 72: | } | | 73: | | | 74: | unset($this->session->data['shipping_method']); | | 75: | unset($this->session->data['shipping_methods']); | | 76: | unset($this->session->data['payment_method']); | | 77: | unset($this->session->data['payment_methods']); | | 78: | } | | 79: | | | 80: | $this->response->addHeader('Content-Type: application/json'); | | 81: | $this->response->setOutput(json_encode($json)); | | 82: | } | | 83: | } | | 84: | |

OpenCart API API documentation generated by ApiGen dev-master