1: | <?php
2: | namespace Opencart\Admin\Controller\Marketplace;
3: | /**
4: | * Class Promotion
5: | *
6: | * @package Opencart\Admin\Controller\Marketplace
7: | */
8: | class Promotion extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return string
13: | */
14: | public function index(): string {
15: | $this->load->language('marketplace/promotion');
16: |
17: | if (isset($this->request->get['type'])) {
18: | $type = $this->request->get['type'];
19: | } else {
20: | // Just in case there are any direct calls to methods we need to remove them to get the extension type
21: | $pos = strrpos($this->request->get['route'], '.');
22: |
23: | if ($pos !== false) {
24: | $route = substr($this->request->get['route'], 0, $pos);
25: | } else {
26: | $route = $this->request->get['route'];
27: | }
28: |
29: | $type = substr($route, strrpos($route, '/') + 1);
30: | }
31: |
32: | $promotion = $this->cache->get('promotion.' . $type);
33: |
34: | if (!$promotion) {
35: | $curl = curl_init();
36: |
37: | curl_setopt($curl, CURLOPT_URL, OPENCART_SERVER . 'index.php?route=api/recommended&type=' . $type . '&version=' . VERSION);
38: | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
39: | curl_setopt($curl, CURLOPT_HEADER, false);
40: | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
41: | curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
42: | curl_setopt($curl, CURLOPT_TIMEOUT, 30);
43: |
44: | $response = curl_exec($curl);
45: |
46: | curl_close($curl);
47: |
48: | if ($response) {
49: | $promotion = json_decode($response, true);
50: | } else {
51: | $promotion = '';
52: | }
53: |
54: | $this->cache->set('promotion.' . $type, $promotion, 3600 * 24);
55: | }
56: |
57: | if (isset($promotion['banner'])) {
58: | $data['banner'] = $promotion['banner'];
59: | } else {
60: | $data['banner'] = '';
61: | }
62: |
63: | $data['extensions'] = [];
64: |
65: | if (isset($promotion['extensions'])) {
66: | $this->load->model('setting/extension');
67: |
68: | foreach ($promotion['extensions'] as $result) {
69: | $extension_install_info = $this->model_setting_extension->getInstallByExtensionDownloadId($result['extension_download_id']);
70: |
71: | // Download
72: | if (!$extension_install_info) {
73: | $download = $this->url->link('marketplace/marketplace.download', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $result['extension_id'] . '&extension_download_id=' . $result['extension_download_id']);
74: | } else {
75: | $download = '';
76: | }
77: |
78: | // Install
79: | if ($extension_install_info && !$extension_install_info['status']) {
80: | $install = $this->url->link('marketplace/installer.install', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_info['extension_install_id']);
81: | } else {
82: | $install = '';
83: | }
84: |
85: | // Delete
86: | if ($extension_install_info && !$extension_install_info['status']) {
87: | $delete = $this->url->link('marketplace/installer.delete', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_info['extension_install_id']);
88: | } else {
89: | $delete = '';
90: | }
91: |
92: | if (!$extension_install_info || !$extension_install_info['status']) {
93: | $data['extensions'][] = [
94: | 'name' => $result['name'],
95: | 'href' => $this->url->link('marketplace/marketplace.info', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $result['extension_id']),
96: | 'download' => $download,
97: | 'install' => $install,
98: | 'delete' => $delete
99: | ];
100: | }
101: | }
102: | }
103: |
104: | return $this->load->view('marketplace/promotion', $data);
105: | }
106: | }
107: |

OpenCart API API documentation generated by ApiGen dev-master