Back to Opencart

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

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

4.1.0.37.0 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Catalog\Controller\Extension\Opencart\Total; | | 3: | /** | | 4: | * Class Voucher | | 5: | * | | 6: | * @package Opencart\Catalog\Controller\Extension\Opencart\Total | | 7: | */ | | 8: | class Voucher extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * Index | | 11: | * | | 12: | * @return string | | 13: | */ | | 14: | public function index(): string { | | 15: | if ($this->config->get('total_voucher_status')) { | | 16: | $this->load->language('extension/opencart/total/voucher'); | | 17: | | | 18: | $data['save'] = $this->url->link('extension/opencart/total/voucher.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['voucher'])) { | | 22: | $data['voucher'] = $this->session->data['voucher']; | | 23: | } else { | | 24: | $data['voucher'] = ''; | | 25: | } | | 26: | | | 27: | return $this->load->view('extension/opencart/total/voucher', $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/voucher'); | | 40: | | | 41: | $json = []; | | 42: | | | 43: | if (isset($this->request->post['voucher'])) { | | 44: | $voucher = (string)$this->request->post['voucher']; | | 45: | } else { | | 46: | $voucher = ''; | | 47: | } | | 48: | | | 49: | if (!$this->config->get('total_voucher_status')) { | | 50: | $json['error'] = $this->language->get('error_status'); | | 51: | } | | 52: | | | 53: | if ($voucher) { | | 54: | $this->load->model('checkout/voucher'); | | 55: | | | 56: | $voucher_info = $this->model_checkout_voucher->getVoucher($voucher); | | 57: | | | 58: | if (!$voucher_info) { | | 59: | $json['error'] = $this->language->get('error_voucher'); | | 60: | } | | 61: | } | | 62: | | | 63: | if (!$json) { | | 64: | if ($voucher) { | | 65: | $json['success'] = $this->language->get('text_success'); | | 66: | | | 67: | $this->session->data['voucher'] = $voucher; | | 68: | } else { | | 69: | $json['success'] = $this->language->get('text_remove'); | | 70: | | | 71: | unset($this->session->data['voucher']); | | 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