1: | <?php
2: | namespace Opencart\Admin\Controller\Extension;
3: | /**
4: | * Class Payment
5: | *
6: | * @package Opencart\Admin\Controller\Extension
7: | */
8: | class Payment extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return void
13: | */
14: | public function index(): void {
15: | $this->response->setOutput($this->getList());
16: | }
17: |
18: | /**
19: | * Get List
20: | *
21: | * @return string
22: | */
23: | public function getList(): string {
24: | $this->load->language('extension/payment');
25: |
26: | $available = [];
27: |
28: | $results = glob(DIR_EXTENSION . '*/admin/controller/payment/*.php');
29: |
30: | foreach ($results as $result) {
31: | $available[] = basename($result, '.php');
32: | }
33: |
34: | $installed = [];
35: |
36: | $this->load->model('setting/extension');
37: |
38: | $extensions = $this->model_setting_extension->getExtensionsByType('payment');
39: |
40: | foreach ($extensions as $extension) {
41: | if (in_array($extension['code'], $available)) {
42: | $installed[] = $extension['code'];
43: | } else {
44: | $this->model_setting_extension->uninstall('payment', $extension['code']);
45: | }
46: | }
47: |
48: | $data['extensions'] = [];
49: |
50: | if ($results) {
51: | foreach ($results as $result) {
52: | $path = substr($result, strlen(DIR_EXTENSION));
53: |
54: | $extension = substr($path, 0, strpos($path, '/'));
55: |
56: | $code = basename($result, '.php');
57: |
58: | $this->load->language('extension/' . $extension . '/payment/' . $code, $code);
59: |
60: | $text_link = $this->language->get($code . '_text_' . $code);
61: |
62: | if ($text_link != $code . '_text_' . $code) {
63: | $link = $text_link;
64: | } else {
65: | $link = '';
66: | }
67: |
68: | $data['extensions'][] = [
69: | 'name' => $this->language->get($code . '_heading_title'),
70: | 'link' => $link,
71: | 'status' => $this->config->get('payment_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
72: | 'sort_order' => $this->config->get('payment_' . $code . '_sort_order'),
73: | 'install' => $this->url->link('extension/payment.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
74: | 'uninstall' => $this->url->link('extension/payment.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
75: | 'installed' => in_array($code, $installed),
76: | 'edit' => $this->url->link('extension/' . $extension . '/payment/' . $code, 'user_token=' . $this->session->data['user_token'])
77: | ];
78: | }
79: | }
80: |
81: | $data['promotion'] = $this->load->controller('marketplace/promotion');
82: |
83: | return $this->load->view('extension/payment', $data);
84: | }
85: |
86: | /**
87: | * Install
88: | *
89: | * @return void
90: | */
91: | public function install(): void {
92: | $this->load->language('extension/payment');
93: |
94: | $json = [];
95: |
96: | if (isset($this->request->get['extension'])) {
97: | $extension = basename($this->request->get['extension']);
98: | } else {
99: | $extension = '';
100: | }
101: |
102: | if (isset($this->request->get['code'])) {
103: | $code = basename($this->request->get['code']);
104: | } else {
105: | $code = '';
106: | }
107: |
108: | if (!$this->user->hasPermission('modify', 'extension/payment')) {
109: | $json['error'] = $this->language->get('error_permission');
110: | }
111: |
112: | if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/payment/' . $code . '.php')) {
113: | $json['error'] = $this->language->get('error_extension');
114: | }
115: |
116: | if (!$json) {
117: | $this->load->model('setting/extension');
118: |
119: | $this->model_setting_extension->install('payment', $extension, $code);
120: |
121: | $this->load->model('user/user_group');
122: |
123: | $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/payment/' . $code);
124: | $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/payment/' . $code);
125: |
126: | $namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
127: |
128: | // Register controllers, models and system extension folders
129: | $this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
130: | $this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
131: | $this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
132: |
133: | // Template directory
134: | $this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
135: |
136: | // Language directory
137: | $this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
138: |
139: | // Config directory
140: | $this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
141: |
142: | // Call install method if it exists
143: | $this->load->controller('extension/' . $extension . '/payment/' . $code . '.install');
144: |
145: | $json['success'] = $this->language->get('text_success');
146: | }
147: |
148: | $this->response->addHeader('Content-Type: application/json');
149: | $this->response->setOutput(json_encode($json));
150: | }
151: |
152: | /**
153: | * Uninstall
154: | *
155: | * @return void
156: | */
157: | public function uninstall(): void {
158: | $this->load->language('extension/payment');
159: |
160: | $json = [];
161: |
162: | if (!$this->user->hasPermission('modify', 'extension/payment')) {
163: | $json['error'] = $this->language->get('error_permission');
164: | }
165: |
166: | if (!$json) {
167: | $this->load->model('setting/extension');
168: |
169: | $this->model_setting_extension->uninstall('payment', $this->request->get['code']);
170: |
171: | // Call uninstall method if it exists
172: | $this->load->controller('extension/' . $this->request->get['extension'] . '/payment/' . $this->request->get['code'] . '.uninstall');
173: |
174: | $json['success'] = $this->language->get('text_success');
175: | }
176: |
177: | $this->response->addHeader('Content-Type: application/json');
178: | $this->response->setOutput(json_encode($json));
179: | }
180: | }
181: |

OpenCart API API documentation generated by ApiGen dev-master