$this->load->model('openbay/ebay');
$this->load->model('openbay/ebay_template');
$this->data['token'] = $this->session->data['token'];
$this->data['shipping_international_zones'] = $this->model_openbay_ebay->getShippingLocations();
$this->data['templates'] = $this->model_openbay_ebay_template->getAll();
$this->data['types'] = $this->model_openbay_ebay_profile->getTypes();
$setting = array();
$setting['dispatch_times'] = $this->openbay->ebay->getSetting('dispatch_time_max');
$setting['countries'] = $this->openbay->ebay->getSetting('countries');
$setting['returns'] = $this->openbay->ebay->getSetting('returns');
if(empty($setting['dispatch_times']) || empty($setting['countries']) || empty($setting['returns'])){
$this->session->data['warning'] = $this->language->get('lang_error_missing_settings');
$this->redirect($this->url->link('openbay/openbay/viewSync&token=' . $this->session->data['token'], 'SSL'));
}
if(is_array($setting['dispatch_times'])){ ksort($setting['dispatch_times']); }
if(is_array($setting['countries'])){ ksort($setting['countries']); }
$this->data['setting'] = $setting;
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
$profile_info = array();
if (isset($this->request->get['ebay_profile_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$profile_info = $this->model_openbay_ebay_profile->get($this->request->get['ebay_profile_id']);
}
if (isset($this->request->post['type'])) {
$type = $this->request->post['type'];
} else {
$type = $profile_info['type'];
}
if (!array_key_exists($type, $this->data['types'])) {
$this->session->data['error'] = $this->data['lang_no_template'];
$this->redirect($this->url->link('openbay/ebay_profile/profileAll&token=' . $this->session->data['token']));
}
$this->document->setTitle($this->data['page_title']);
$this->document->addStyle('view/stylesheet/openbay.css');
$this->document->addScript('view/javascript/openbay/faq.js');
$this->template = $this->data['types'][$type]['template'];
$this->children = array(
'common/header',
'common/footer'
);
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'text' => $this->language->get('text_home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'href' => $this->url->link('extension/openbay', 'token=' . $this->session->data['token'], 'SSL'),
'text' => 'OpenBay Pro',
'separator' => ' :: '
);
$this->data['breadcrumbs'][] = array(
'href' => $this->url->link('openbay/openbay', 'token=' . $this->session->data['token'], 'SSL'),
'text' => 'eBay',
'separator' => ' :: '
);
$this->data['breadcrumbs'][] = array(
'href' => $this->url->link('openbay/ebay_profile/profileAll', 'token=' . $this->session->data['token'], 'SSL'),
'text' => 'Profiles',
'separator' => ' :: '
);
if (isset($this->request->post['default'])) {
$this->data['default'] = $this->request->post['default'];
} elseif (!empty($profile_info)) {
$this->data['default'] = $profile_info['default'];
} else {
$this->data['default'] = 0;
}
if (isset($this->request->post['name'])) {
$this->data['name'] = $this->request->post['name'];
} elseif (!empty($profile_info)) {
$this->data['name'] = $profile_info['name'];
} else {
$this->data['name'] = '';
}
if (isset($this->request->post['description'])) {
$this->data['description'] = $this->request->post['description'];
} elseif (!empty($profile_info)) {
$this->data['description'] = $profile_info['description'];
} else {
$this->data['description'] = '';
}
if (isset($this->request->post['type'])) {
$this->data['type'] = $this->request->post['type'];
} else {
$this->data['type'] = $profile_info['type'];
}
if (isset($this->request->get['ebay_profile_id'])) {
$this->data['ebay_profile_id'] = $this->request->get['ebay_profile_id'];
} else {
$this->data['ebay_profile_id'] = '';
}
if (isset($this->request->post['data'])) {
$this->data['data'] = $this->request->post['data'];
} elseif (!empty($profile_info)) {
$this->data['data'] = $profile_info['data'];
} else {
$this->data['data'] = '';
}
if ($type == 0 && isset($profile_info['data'])) {
$national = array();
$i = 0;
if (isset($profile_info['data']['service_national']) && is_array($profile_info['data']['service_national'])) {
foreach ($profile_info['data']['service_national'] as $key => $service) {
$national[] = array(
'id' => $service,
'price' => $profile_info['data']['price_national'][$key],
'additional' => $profile_info['data']['priceadditional_national'][$key],
'name' => $this->model_openbay_ebay->getShippingServiceName('0', $service)
);
$i++;
}
}
$this->data['data']['shipping_national'] = $national;
$this->data['data']['shipping_national_count'] = $i;
$international = array();
$i = 0;
if (isset($profile_info['data']['service_international']) && is_array($profile_info['data']['service_international'])) {
foreach ($profile_info['data']['service_international'] as $key => $service) {
if(!isset($profile_info['data']['shipto_international'][$key])){
$profile_info['data']['shipto_international'][$key] = array();
}
$international[] = array(
'id' => $service,
'price' => $profile_info['data']['price_international'][$key],
'additional' => $profile_info['data']['priceadditional_international'][$key],
'name' => $this->model_openbay_ebay->getShippingServiceName('1', $service),
'shipto' => $profile_info['data']['shipto_international'][$key]
);
$i++;
}
}
$this->data['data']['shipping_international'] = $international;
$this->data['data']['shipping_international_count'] = $i;
}
$this->response->setOutput($this->render(true), $this->config->get('config_compression'));