1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
<?php
class ControllerExtensionOpenbayEtsy extends Controller {
public function install() {
$this->load->language('extension/openbay/etsy');
$this->load->model('extension/openbay/etsy');
$this->load->model('setting/setting');
$this->load->model('setting/extension');
$this->load->model('user/user_group');
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/etsy_product');
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/etsy_product');
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/etsy_shipping');
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/etsy_shipping');
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/etsy_shop');
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/etsy_shop');
$this->model_extension_openbay_etsy->install();
}
public function uninstall() {
$this->load->model('extension/openbay/etsy');
$this->load->model('setting/setting');
$this->load->model('setting/extension');
$this->model_extension_openbay_etsy->uninstall();
$this->model_setting_extension->uninstall('openbay', $this->request->get['extension']);
$this->model_setting_setting->deleteSetting($this->request->get['extension']);
}
public function index() {
$this->load->language('extension/openbay/etsy');
$data = $this->language->all();
$this->document->setTitle($this->language->get('text_dashboard'));
$this->document->addScript('view/javascript/openbay/js/faq.js');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true),
'text' => $this->language->get('text_home'),
);
$data['breadcrumbs'][] = array(
'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true),
'text' => $this->language->get('text_openbay'),
);
$data['breadcrumbs'][] = array(
'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true),
'text' => $this->language->get('text_dashboard'),
);
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
if (isset($this->session->data['error'])) {
$data['error_warning'] = $this->session->data['error'];
unset($this->session->data['error']);
} else {
$data['error_warning'] = '';
}
$data['validation'] = $this->openbay->etsy->validate();
$data['links_settings'] = $this->url->link('extension/openbay/etsy/settings', 'user_token=' . $this->session->data['user_token'], true);
$data['links_products'] = $this->url->link('extension/openbay/etsy_product/links', 'user_token=' . $this->session->data['user_token'], true);
$data['links_listings'] = $this->url->link('extension/openbay/etsy_product/listings', 'user_token=' . $this->session->data['user_token'], true);
$data['link_signup'] = 'https://account.openbaypro.com/etsy/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=dashboard&utm_campaign=etsy';
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('extension/openbay/etsy', $data));
}
public function settings() {
$this->load->model('setting/setting');
$this->load->model('extension/openbay/etsy');
$this->load->model('localisation/order_status');
$this->load->language('extension/openbay/etsy_settings');
$data = $this->language->all();
if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) {
$this->model_setting_setting->editSetting('etsy', $this->request->post);
$this->openbay->etsy->resetConfig($this->request->post['etsy_token'], $this->request->post['etsy_encryption_key']);
$account_info = $this->model_extension_openbay_etsy->verifyAccount();
if (isset($account_info['header_code']) && $account_info['header_code'] == 200) {
$this->openbay->etsy->settingsUpdate();
$this->session->data['success'] = $this->language->get('text_success');
} else {
$this->session->data['error'] = $this->language->get('error_account_info');
}
$this->response->redirect($this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true));
}
$this->document->setTitle($this->language->get('heading_title'));
$this->document->addScript('view/javascript/openbay/js/faq.js');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true),
'text' => $this->language->get('text_home'),
);
$data['breadcrumbs'][] = array(
'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true),
'text' => $this->language->get('text_openbay'),
);
$data['breadcrumbs'][] = array(
'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true),
'text' => $this->language->get('text_etsy'),
);
$data['breadcrumbs'][] = array(
'href' => $this->url->link('extension/openbay/etsy/settings', 'user_token=' . $this->session->data['user_token'], true),
'text' => $this->language->get('heading_title'),
);
$data['action'] = $this->url->link('extension/openbay/etsy/settings', 'user_token=' . $this->session->data['user_token'], true);
$data['cancel'] = $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true);
$data['user_token'] = $this->session->data['user_token'];
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->request->post['etsy_status'])) {
$data['etsy_status'] = $this->request->post['etsy_status'];
} else {
$data['etsy_status'] = $this->config->get('etsy_status');
}
if (isset($this->request->post['etsy_token'])) {
$data['etsy_token'] = $this->request->post['etsy_token'];
} else {
$data['etsy_token'] = $this->config->get('etsy_token');
}
if (isset($this->request->post['etsy_encryption_key'])) {
$data['etsy_encryption_key'] = $this->request->post['etsy_encryption_key'];
} else {
$data['etsy_encryption_key'] = $this->config->get('etsy_encryption_key');
}
if (isset($this->request->post['etsy_encryption_iv'])) {
$data['etsy_encryption_iv'] = $this->request->post['etsy_encryption_iv'];
} else {
$data['etsy_encryption_iv'] = $this->config->get('etsy_encryption_iv');
}
if (isset($this->request->post['etsy_address_format'])) {
$data['etsy_address_format'] = $this->request->post['etsy_address_format'];
} else {
$data['etsy_address_format'] = $this->config->get('etsy_address_format');
}
if (isset($this->request->post['etsy_order_status_new'])) {
$data['etsy_order_status_new'] = $this->request->post['etsy_order_status_new'];
} else {
$data['etsy_order_status_new'] = $this->config->get('etsy_order_status_new');
}
if (isset($this->request->post['etsy_order_status_paid'])) {
$data['etsy_order_status_paid'] = $this->request->post['etsy_order_status_paid'];
} else {
$data['etsy_order_status_paid'] = $this->config->get('etsy_order_status_paid');
}
if (isset($this->request->post['etsy_order_status_shipped'])) {
$data['etsy_order_status_shipped'] = $this->request->post['etsy_order_status_shipped'];
} else {
$data['etsy_order_status_shipped'] = $this->config->get('etsy_order_status_shipped');
}
if (isset($this->request->post['etsy_logging'])) {
$data['etsy_logging'] = $this->request->post['etsy_logging'];
} else {
$data['etsy_logging'] = $this->config->get('etsy_logging');
}
$data['api_server'] = $this->openbay->etsy->getServer();
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
$data['account_info'] = $this->model_extension_openbay_etsy->verifyAccount();
$data['link_signup'] = 'https://account.openbaypro.com/etsy/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=settings&utm_campaign=etsy';
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('extension/openbay/etsy_settings', $data));
}
public function settingsUpdate() {
$this->openbay->etsy->settingsUpdate();
$response = array('header_code' => 200);
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($response));
}
public function getOrders() {
$response = $this->openbay->etsy->call('v1/etsy/order/get/all/', 'GET');
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($response));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'extension/openbay/etsy')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
}
|