$this->load->language('catalog/product');
$this->load->language('openbay/amazon');
$this->load->model('openbay/amazon');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$this->load->library('amazon');
$this->data = array_merge($this->data, $this->load->language('openbay/amazon_listing'));
$this->document->addStyle('view/stylesheet/openbay.css');
$this->document->addScript('view/javascript/openbay/openbay.js');
$this->document->setTitle($this->language->get('lang_title'));
$url = '';
if (isset($this->request->get['filter_name'])) {
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_model'])) {
$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_price'])) {
$url .= '&filter_price=' . $this->request->get['filter_price'];
}
if (isset($this->request->get['filter_price_to'])) {
$url .= '&filter_price_to=' . $this->request->get['filter_price_to'];
}
if (isset($this->request->get['filter_quantity'])) {
$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
}
if (isset($this->request->get['filter_quantity_to'])) {
$url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to'];
}
if (isset($this->request->get['filter_status'])) {
$url .= '&filter_status=' . $this->request->get['filter_status'];
}
if (isset($this->request->get['filter_sku'])) {
$url .= '&filter_sku=' . $this->request->get['filter_sku'];
}
if (isset($this->request->get['filter_desc'])) {
$url .= '&filter_desc=' . $this->request->get['filter_desc'];
}
if (isset($this->request->get['filter_category'])) {
$url .= '&filter_category=' . $this->request->get['filter_category'];
}
if (isset($this->request->get['filter_manufacturer'])) {
$url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => 'Products',
'href' => $this->url->link('extension/openbay/itemList', 'token=' . $this->session->data['token'] . $url, 'SSL'),
'separator' => ' :: '
);
if(isset($this->request->get['product_id'])) {
$product_id = $this->request->get['product_id'];
} else {
die('No product id');
}
if(isset($this->request->get['var'])) {
$variation = $this->request->get['var'];
} else {
$variation = '';
}
$this->data['variation'] = $variation;
$this->data['errors'] = array();
/*
* Perform updates to database if form is posted
*/
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
$dataArray = $this->request->post;
$this->model_openbay_amazon->saveProduct($product_id, $dataArray);
if($dataArray['upload_after'] === 'true') {
$uploadResult = $this->uploadSaved();
if($uploadResult['status'] == 'ok') {
$this->session->data['success'] = $this->language->get('uploaded_alert_text');
$this->redirect($this->url->link('extension/openbay/itemList', 'token=' . $this->session->data['token'] . $url, 'SSL'));
} else {
$this->data['errors'][] = Array('message' => $uploadResult['error_message']);
}
} else {
$this->session->data['success'] = $this->language->get('saved_localy_text');
$this->redirect($this->url->link('openbay/amazon_product', 'token=' . $this->session->data['token'] . '&product_id=' . $product_id . $url, 'SSL'));
}
}
if(isset($this->session->data['success'])) {
$this->data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
}
$savedListingData = $this->model_openbay_amazon->getProduct($product_id, $variation);
if(empty($savedListingData)) {
$listingSaved = false;
} else {
$listingSaved = true;
}
$errors = $this->model_openbay_amazon->getProductErrors($product_id);
foreach($errors as $error) {
$error['message'] = 'Error for SKU: "' . $error['sku'] . '" - ' . $this->formatUrlsInText($error['message']);
$this->data['errors'][] = $error;
}
if(!empty($errors)) {
$this->data['has_listing_errors'] = true;
} else {
$this->data['has_listing_errors'] = false;
}
$product_info = $this->model_catalog_product->getProduct($product_id);
$this->data['listing_name'] = $product_info['name'] . " : " . $product_info['model'];
$this->data['listing_sku'] = $product_info['sku'];
$this->data['listing_url'] = $this->url->link('catalog/product/update', 'token=' . $this->session->data['token'] . '&product_id=' . $product_id . $url, 'SSL');
if($listingSaved) {
$this->data['edit_product_category'] = $savedListingData['category'];
} else {
$this->data['edit_product_category'] = '';
}
$this->data['amazon_categories'] = array();
$amazon_templates = $this->openbay->amazon->getCategoryTemplates();
foreach($amazon_templates as $template) {
$template = (array)$template;
$categoryData = array(
'friendly_name' => $template['friendly_name'],
'name' => $template['name'],
'template' => $template['xml']
);
$this->data['amazon_categories'][] = $categoryData;
}
if($listingSaved) {
$this->data['template_parser_url'] = $this->url->link('openbay/amazon_product/parseTemplateAjax&edit_id=' . $product_id, 'token=' . $this->session->data['token'], 'SSL');
} else {
$this->data['template_parser_url'] = $this->url->link('openbay/amazon_product/parseTemplateAjax&product_id=' . $product_id, 'token=' . $this->session->data['token'], 'SSL');
}
$this->data['url_remove_errors'] = $this->url->link('openbay/amazon_product/removeErrors', 'token=' . $this->session->data['token'] . '&product_id=' . $product_id . $url, 'SSL');
$this->data['cancel_url'] = $this->url->link('extension/openbay/itemList', 'token=' . $this->session->data['token'] . $url, 'SSL');
$this->data['saved_listings_url'] = $this->url->link('openbay/amazon/savedListings', 'token=' . $this->session->data['token'], 'SSL');
$this->data['main_url'] = $this->url->link('openbay/amazon_product', 'token=' . $this->session->data['token'] . $url, 'SSL');
$this->data['token'] = $this->session->data['token'];
$this->data['no_image'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
if($this->openbay->addonLoad('openstock')) {
$this->load->model('openstock/openstock');
$this->data['options'] = $this->model_openstock_openstock->getProductOptionStocks($product_id);
} else {
$this->data['options'] = array();
}
$this->data['marketplaces'] = array(
array('name' => $this->language->get('de_text'), 'id' => 'A1PA6795UKMFR9', 'code' => 'de'),
array('name' => $this->language->get('fr_text'), 'id' => 'A13V1IB3VIYZZH', 'code' => 'fr'),
array('name' => $this->language->get('it_text'), 'id' => 'APJ6JRA9NG5V4', 'code' => 'it'),
array('name' => $this->language->get('es_text'), 'id' => 'A1RKKUPIHCS9HS', 'code' => 'es'),
array('name' => $this->language->get('uk_text'), 'id' => 'A1F83G8C2ARO7P', 'code' => 'uk'),
);
$marketplaceMapping = array(
'uk' => 'A1F83G8C2ARO7P',
'de' => 'A1PA6795UKMFR9',
'fr' => 'A13V1IB3VIYZZH',
'it' => 'APJ6JRA9NG5V4',
'es' => 'A1RKKUPIHCS9HS',
);
if($this->config->get('openbay_amazon_default_listing_marketplace')) {
$this->data['default_marketplaces'] = array($marketplaceMapping[$this->config->get('openbay_amazon_default_listing_marketplace')]);
} else {
$this->data['default_marketplaces'] = array();
}
$this->data['saved_marketplaces'] = isset($savedListingData['marketplaces']) ? (array)unserialize($savedListingData['marketplaces']) : false;
$this->template = 'openbay/amazon_listing_advanced.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());