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