shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

amazon_listing.php (25291B)


      1 <?php
      2 class ControllerExtensionOpenbayAmazonListing extends Controller {
      3 	public function create() {
      4 		$this->load->language('extension/openbay/amazon_listing');
      5 		$this->load->model('extension/openbay/amazon_listing');
      6 		$this->load->model('extension/openbay/amazon');
      7 		$this->load->model('catalog/product');
      8 		$this->load->model('localisation/country');
      9 
     10 		$this->document->setTitle($this->language->get('heading_title'));
     11 		$this->document->addScript('view/javascript/openbay/js/faq.js');
     12 
     13 		if (isset($this->session->data['error'])) {
     14 			$data['error_warning'] = $this->session->data['error'];
     15 			unset($this->session->data['error']);
     16 		} else {
     17 			$data['error_warning'] = '';
     18 		}
     19 
     20 		$url = '';
     21 
     22 		if (isset($this->request->get['filter_name'])) {
     23 			$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
     24 		}
     25 
     26 		if (isset($this->request->get['filter_model'])) {
     27 			$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
     28 		}
     29 
     30 		if (isset($this->request->get['filter_price'])) {
     31 			$url .= '&filter_price=' . $this->request->get['filter_price'];
     32 		}
     33 
     34 		if (isset($this->request->get['filter_price_to'])) {
     35 			$url .= '&filter_price_to=' . $this->request->get['filter_price_to'];
     36 		}
     37 
     38 		if (isset($this->request->get['filter_quantity'])) {
     39 			$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
     40 		}
     41 
     42 		if (isset($this->request->get['filter_quantity_to'])) {
     43 			$url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to'];
     44 		}
     45 
     46 		if (isset($this->request->get['filter_status'])) {
     47 			$url .= '&filter_status=' . $this->request->get['filter_status'];
     48 		}
     49 
     50 		if (isset($this->request->get['filter_sku'])) {
     51 			$url .= '&filter_sku=' . $this->request->get['filter_sku'];
     52 		}
     53 
     54 		if (isset($this->request->get['filter_desc'])) {
     55 			$url .= '&filter_desc=' . $this->request->get['filter_desc'];
     56 		}
     57 
     58 		if (isset($this->request->get['filter_category'])) {
     59 			$url .= '&filter_category=' . $this->request->get['filter_category'];
     60 		}
     61 
     62 		if (isset($this->request->get['filter_manufacturer'])) {
     63 			$url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer'];
     64 		}
     65 
     66 		if (isset($this->request->get['sort'])) {
     67 			$url .= '&sort=' . $this->request->get['sort'];
     68 		}
     69 
     70 		if (isset($this->request->get['order'])) {
     71 			$url .= '&order=' . $this->request->get['order'];
     72 		}
     73 
     74 		if (isset($this->request->get['page'])) {
     75 			$url .= '&page=' . $this->request->get['page'];
     76 		}
     77 
     78 		if ($this->request->post) {
     79 			$result = $this->model_extension_openbay_amazon_listing->simpleListing($this->request->post);
     80 
     81 			if ($result['status'] === 1) {
     82 				$this->session->data['success'] = $this->language->get('text_product_sent');
     83 				$this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true));
     84 			} else {
     85 				$this->session->data['error'] = sprintf($this->language->get('text_product_not_sent'), $result['message']);
     86 				$this->response->redirect($this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->post['product_id'] . $url, true));
     87 			}
     88 		}
     89 
     90 		if (isset($this->request->get['product_id'])) {
     91 			$product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
     92 
     93 			if (empty($product_info)) {
     94 				$this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true));
     95 			}
     96 
     97 			$listing_status = $this->model_extension_openbay_amazon->getProductStatus($this->request->get['product_id']);
     98 
     99 			if ($listing_status === 'processing' || $listing_status === 'ok') {
    100 				$this->response->redirect($this->url->link('extension/openbay/amazon_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true));
    101 			} else if ($listing_status === 'error_advanced' || $listing_status === 'saved' || $listing_status === 'error_few') {
    102 				$this->response->redirect($this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true));
    103 			}
    104 		} else {
    105 			$this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true));
    106 		}
    107 
    108 		$data['url_return']  = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true);
    109 		$data['url_search']  = $this->url->link('extension/openbay/amazon_listing/search', 'user_token=' . $this->session->data['user_token'], true);
    110 		$data['url_advanced']  = $this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true);
    111 
    112 		$data['button_search'] = $this->language->get('button_search');
    113 		$data['button_new'] = $this->language->get('button_new');
    114 		$data['button_cancel'] = $this->language->get('button_cancel');
    115 		$data['button_amazon_price'] = $this->language->get('button_amazon_price');
    116 		$data['button_list'] = $this->language->get('button_list');
    117 		$data['heading_title'] = $this->language->get('heading_title');
    118 		$data['text_not_in_catalog'] = $this->language->get('text_not_in_catalog');
    119 		$data['text_no_results'] = $this->language->get('text_no_results');
    120 		$data['button_view_on_amazon'] = $this->language->get('button_view_on_amazon');
    121 		$data['text_list'] = $this->language->get('text_list');
    122 		$data['text_placeholder_search'] = $this->language->get('text_placeholder_search');
    123 		$data['text_placeholder_condition'] = $this->language->get('text_placeholder_condition');
    124 		$data['column_image'] = $this->language->get('column_image');
    125 		$data['column_asin'] = $this->language->get('column_asin');
    126 		$data['column_name'] = $this->language->get('column_name');
    127 		$data['column_price'] = $this->language->get('column_price');
    128 		$data['column_action'] = $this->language->get('column_action');
    129 		$data['entry_sku'] = $this->language->get('entry_sku');
    130 		$data['entry_condition'] = $this->language->get('entry_condition');
    131 		$data['entry_condition_note'] = $this->language->get('entry_condition_note');
    132 		$data['entry_price'] = $this->language->get('entry_price');
    133 		$data['entry_sale_price'] = $this->language->get('entry_sale_price');
    134 		$data['entry_sale_date'] = $this->language->get('entry_sale_date');
    135 		$data['entry_quantity'] = $this->language->get('entry_quantity');
    136 		$data['entry_start_selling'] = $this->language->get('entry_start_selling');
    137 		$data['entry_restock_date'] = $this->language->get('entry_restock_date');
    138 		$data['entry_from'] = $this->language->get('entry_from');
    139 		$data['entry_to'] = $this->language->get('entry_to');
    140 		$data['help_restock_date'] = $this->language->get('help_restock_date');
    141 		$data['help_sku'] = $this->language->get('help_sku');
    142 		$data['help_sale_price'] = $this->language->get('help_sale_price');
    143 		$data['tab_required'] = $this->language->get('tab_required');
    144 		$data['tab_additional'] = $this->language->get('tab_additional');
    145 		$data['error_price'] = $this->language->get('error_price');
    146 		$data['error_sku'] = $this->language->get('error_sku');
    147 		$data['error_stock'] = $this->language->get('error_stock');
    148 
    149 		$data['form_action'] = $this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'], true);
    150 
    151 		$data['sku'] = trim($product_info['sku']);
    152 
    153 		if ($this->config->get('openbay_amazon_listing_tax_added')) {
    154 			$data['price'] = $product_info['price'] * (1 + $this->config->get('openbay_amazon_listing_tax_added') / 100);
    155 		} else {
    156 			$data['price'] = $product_info['price'];
    157 		}
    158 
    159 		$data['listing_errors'] = array();
    160 
    161 		if ($listing_status == 'error_quick') {
    162 			$data['listing_errors'] = $this->model_extension_openbay_amazon->getProductErrors($product_info['product_id'], 3);
    163 		}
    164 
    165 		$data['price'] = number_format($data['price'], 2, '.', '');
    166 		$data['quantity'] = $product_info['quantity'];
    167 		$data['product_id'] = $product_info['product_id'];
    168 
    169 		$data['conditions'] = array(
    170 			'New' => $this->language->get('text_new'),
    171 			'UsedLikeNew' => $this->language->get('text_used_like_new'),
    172 			'UsedVeryGood' => $this->language->get('text_used_very_good'),
    173 			'UsedGood' => $this->language->get('text_used_good'),
    174 			'UsedAcceptable' => $this->language->get('text_used_acceptable'),
    175 			'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'),
    176 			'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'),
    177 			'CollectibleGood' => $this->language->get('text_collectible_good'),
    178 			'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'),
    179 			'Refurbished' => $this->language->get('text_refurbished'),
    180 		);
    181 
    182 		$data['marketplaces'] = array(
    183 			'uk' => $this->language->get('text_united_kingdom'),
    184 			'de' => $this->language->get('text_germany'),
    185 			'fr' => $this->language->get('text_france'),
    186 			'it' => $this->language->get('text_italy'),
    187 			'es' => $this->language->get('text_spain'),
    188 		);
    189 
    190 		$data['default_marketplace'] = $this->config->get('openbay_amazon_default_listing_marketplace');
    191 		$data['default_condition'] = $this->config->get('openbay_amazon_listing_default_condition');
    192 
    193 		$data['user_token'] = $this->session->data['user_token'];
    194 		
    195 		$data['breadcrumbs'] = array();
    196 
    197 		$data['breadcrumbs'][] = array(
    198 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true),
    199 			'text' => $this->language->get('text_home'),
    200 		);
    201 
    202 		$data['breadcrumbs'][] = array(
    203 			'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true),
    204 			'text' => $this->language->get('text_openbay'),
    205 		);
    206 
    207 		$data['breadcrumbs'][] = array(
    208 			'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true),
    209 			'text' => $this->language->get('text_amazon'),
    210 		);
    211 
    212 		$data['breadcrumbs'][] = array(
    213 			'href' => $this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'], true),
    214 			'text' => $this->language->get('heading_title'),
    215 		);
    216 
    217 		$data['header'] = $this->load->controller('common/header');
    218 		$data['column_left'] = $this->load->controller('common/column_left');
    219 		$data['footer'] = $this->load->controller('common/footer');
    220 
    221 		$this->response->setOutput($this->load->view('extension/openbay/amazon_listing', $data));
    222 	}
    223 
    224 	public function edit() {
    225 		$this->load->model('extension/openbay/amazon_listing');
    226 		$this->load->model('extension/openbay/amazon');
    227 		$this->load->language('extension/openbay/amazon_listing');
    228 
    229 		$this->document->setTitle($this->language->get('text_edit_heading'));
    230 		$this->document->addScript('view/javascript/openbay/js/faq.js');
    231 
    232 		$url = '';
    233 
    234 		if (isset($this->request->get['filter_name'])) {
    235 			$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
    236 		}
    237 
    238 		if (isset($this->request->get['filter_model'])) {
    239 			$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
    240 		}
    241 
    242 		if (isset($this->request->get['filter_price'])) {
    243 			$url .= '&filter_price=' . $this->request->get['filter_price'];
    244 		}
    245 
    246 		if (isset($this->request->get['filter_price_to'])) {
    247 			$url .= '&filter_price_to=' . $this->request->get['filter_price_to'];
    248 		}
    249 
    250 		if (isset($this->request->get['filter_quantity'])) {
    251 			$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
    252 		}
    253 
    254 		if (isset($this->request->get['filter_quantity_to'])) {
    255 			$url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to'];
    256 		}
    257 
    258 		if (isset($this->request->get['filter_status'])) {
    259 			$url .= '&filter_status=' . $this->request->get['filter_status'];
    260 		}
    261 
    262 		if (isset($this->request->get['filter_sku'])) {
    263 			$url .= '&filter_sku=' . $this->request->get['filter_sku'];
    264 		}
    265 
    266 		if (isset($this->request->get['filter_desc'])) {
    267 			$url .= '&filter_desc=' . $this->request->get['filter_desc'];
    268 		}
    269 
    270 		if (isset($this->request->get['filter_category'])) {
    271 			$url .= '&filter_category=' . $this->request->get['filter_category'];
    272 		}
    273 
    274 		if (isset($this->request->get['filter_manufacturer'])) {
    275 			$url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer'];
    276 		}
    277 
    278 		if (isset($this->request->get['sort'])) {
    279 			$url .= '&sort=' . $this->request->get['sort'];
    280 		}
    281 
    282 		if (isset($this->request->get['order'])) {
    283 			$url .= '&order=' . $this->request->get['order'];
    284 		}
    285 
    286 		if (isset($this->request->get['page'])) {
    287 			$url .= '&page=' . $this->request->get['page'];
    288 		}
    289 
    290 		if (isset($this->request->get['product_id'])) {
    291 			$product_id = $this->request->get['product_id'];
    292 		} else {
    293 			$this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true));
    294 		}
    295 
    296 		$data['breadcrumbs'] = array();
    297 		$data['breadcrumbs'][] = array(
    298 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true),
    299 			'text' => $this->language->get('text_home'),
    300 		);
    301 		$data['breadcrumbs'][] = array(
    302 			'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true),
    303 			'text' => $this->language->get('text_openbay'),
    304 		);
    305 		$data['breadcrumbs'][] = array(
    306 			'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true),
    307 			'text' => $this->language->get('text_amazon'),
    308 		);
    309 		$data['breadcrumbs'][] = array(
    310 			'href' => $this->url->link('extension/openbay/amazon_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true),
    311 			'text' => $this->language->get('text_edit_heading'),
    312 		);
    313 
    314 		$status = $this->model_extension_openbay_amazon->getProductStatus($product_id);
    315 
    316 		if ($status === false) {
    317 			$this->response->redirect($this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true));
    318 			return;
    319 		}
    320 
    321 		$data['product_links'] = $this->model_extension_openbay_amazon->getProductLinks($product_id);
    322 		$data['url_return']  = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true);
    323 
    324 		if ($status == 'ok' || $status == 'linked') {
    325 			$data['url_create_new']  = $this->url->link('extension/openbay/amazon_listing/createNew', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true);
    326 			$data['url_delete_links']  = $this->url->link('extension/openbay/amazon_listing/deleteLinks', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true);
    327 		}
    328 
    329 		if ($status == 'saved') {
    330 			$data['has_saved_listings'] = true;
    331 		} else {
    332 			$data['has_saved_listings'] = false;
    333 		}
    334 
    335 		$data['url_saved_listings']  = $this->url->link('extension/openbay/amazon/savedListings', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id, true);
    336 
    337 		$data['user_token'] = $this->session->data['user_token'];
    338 
    339 		$data['text_edit_heading'] = $this->language->get('text_edit_heading');
    340 		$data['text_product_links'] = $this->language->get('text_product_links');
    341 		$data['text_has_saved_listings'] = $this->language->get('text_has_saved_listings');
    342 		$data['button_create_new_listing'] = $this->language->get('button_create_new_listing');
    343 		$data['button_remove_links'] = $this->language->get('button_remove_links');
    344 		$data['button_cancel'] = $this->language->get('button_cancel');
    345 		$data['button_saved_listings'] = $this->language->get('button_saved_listings');
    346 		$data['column_name'] = $this->language->get('column_name');
    347 		$data['column_model'] = $this->language->get('column_model');
    348 		$data['column_combination'] = $this->language->get('column_combination');
    349 		$data['column_sku'] = $this->language->get('column_sku');
    350 		$data['column_amazon_sku'] = $this->language->get('column_amazon_sku');
    351 		$data['column_sku_variant'] = $this->language->get('column_sku_variant');
    352 		$data['text_no_results'] = $this->language->get('text_no_results');
    353 
    354 		$data['header'] = $this->load->controller('common/header');
    355 		$data['column_left'] = $this->load->controller('common/column_left');
    356 		$data['footer'] = $this->load->controller('common/footer');
    357 
    358 		$this->response->setOutput($this->load->view('extension/openbay/amazon_listing_edit', $data));
    359 	}
    360 
    361 	public function createNew() {
    362 		$url = '';
    363 
    364 		if (isset($this->request->get['filter_name'])) {
    365 			$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
    366 		}
    367 
    368 		if (isset($this->request->get['filter_model'])) {
    369 			$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
    370 		}
    371 
    372 		if (isset($this->request->get['filter_price'])) {
    373 			$url .= '&filter_price=' . $this->request->get['filter_price'];
    374 		}
    375 
    376 		if (isset($this->request->get['filter_price_to'])) {
    377 			$url .= '&filter_price_to=' . $this->request->get['filter_price_to'];
    378 		}
    379 
    380 		if (isset($this->request->get['filter_quantity'])) {
    381 			$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
    382 		}
    383 
    384 		if (isset($this->request->get['filter_quantity_to'])) {
    385 			$url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to'];
    386 		}
    387 
    388 		if (isset($this->request->get['filter_status'])) {
    389 			$url .= '&filter_status=' . $this->request->get['filter_status'];
    390 		}
    391 
    392 		if (isset($this->request->get['filter_sku'])) {
    393 			$url .= '&filter_sku=' . $this->request->get['filter_sku'];
    394 		}
    395 
    396 		if (isset($this->request->get['filter_desc'])) {
    397 			$url .= '&filter_desc=' . $this->request->get['filter_desc'];
    398 		}
    399 
    400 		if (isset($this->request->get['filter_category'])) {
    401 			$url .= '&filter_category=' . $this->request->get['filter_category'];
    402 		}
    403 
    404 		if (isset($this->request->get['filter_manufacturer'])) {
    405 			$url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer'];
    406 		}
    407 
    408 		if (isset($this->request->get['sort'])) {
    409 			$url .= '&sort=' . $this->request->get['sort'];
    410 		}
    411 
    412 		if (isset($this->request->get['order'])) {
    413 			$url .= '&order=' . $this->request->get['order'];
    414 		}
    415 
    416 		if (isset($this->request->get['page'])) {
    417 			$url .= '&page=' . $this->request->get['page'];
    418 		}
    419 
    420 		if (isset($this->request->get['product_id'])) {
    421 			$product_id = $this->request->get['product_id'];
    422 		} else {
    423 			$this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true));
    424 		}
    425 		$this->load->model('extension/openbay/amazon');
    426 		$this->model_extension_openbay_amazon->deleteProduct($product_id);
    427 		$this->response->redirect($this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true));
    428 	}
    429 
    430 	public function deleteLinks() {
    431 		$this->load->language('extension/openbay/amazon_listing');
    432 
    433 		$url = '';
    434 
    435 		if (isset($this->request->get['filter_name'])) {
    436 			$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
    437 		}
    438 
    439 		if (isset($this->request->get['filter_model'])) {
    440 			$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
    441 		}
    442 
    443 		if (isset($this->request->get['filter_price'])) {
    444 			$url .= '&filter_price=' . $this->request->get['filter_price'];
    445 		}
    446 
    447 		if (isset($this->request->get['filter_price_to'])) {
    448 			$url .= '&filter_price_to=' . $this->request->get['filter_price_to'];
    449 		}
    450 
    451 		if (isset($this->request->get['filter_quantity'])) {
    452 			$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
    453 		}
    454 
    455 		if (isset($this->request->get['filter_quantity_to'])) {
    456 			$url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to'];
    457 		}
    458 
    459 		if (isset($this->request->get['filter_status'])) {
    460 			$url .= '&filter_status=' . $this->request->get['filter_status'];
    461 		}
    462 
    463 		if (isset($this->request->get['filter_sku'])) {
    464 			$url .= '&filter_sku=' . $this->request->get['filter_sku'];
    465 		}
    466 
    467 		if (isset($this->request->get['filter_desc'])) {
    468 			$url .= '&filter_desc=' . $this->request->get['filter_desc'];
    469 		}
    470 
    471 		if (isset($this->request->get['filter_category'])) {
    472 			$url .= '&filter_category=' . $this->request->get['filter_category'];
    473 		}
    474 
    475 		if (isset($this->request->get['filter_manufacturer'])) {
    476 			$url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer'];
    477 		}
    478 
    479 		if (isset($this->request->get['sort'])) {
    480 			$url .= '&sort=' . $this->request->get['sort'];
    481 		}
    482 
    483 		if (isset($this->request->get['order'])) {
    484 			$url .= '&order=' . $this->request->get['order'];
    485 		}
    486 
    487 		if (isset($this->request->get['page'])) {
    488 			$url .= '&page=' . $this->request->get['page'];
    489 		}
    490 
    491 		if (isset($this->request->get['product_id'])) {
    492 			$product_id = $this->request->get['product_id'];
    493 		} else {
    494 			$this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true));
    495 		}
    496 		$this->load->model('extension/openbay/amazon');
    497 
    498 		$links = $this->model_extension_openbay_amazon->getProductLinks($product_id);
    499 		foreach ($links as $link) {
    500 			$this->model_extension_openbay_amazon->removeProductLink($link['amazon_sku']);
    501 		}
    502 		$this->model_extension_openbay_amazon->deleteProduct($product_id);
    503 		$this->session->data['success'] = $this->language->get('text_links_removed');
    504 
    505 		$this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true));
    506 	}
    507 
    508 	public function search() {
    509 		$this->load->model('extension/openbay/amazon_listing');
    510 		$this->load->language('extension/openbay/amazon_listing');
    511 
    512 		$error = '';
    513 
    514 		if (empty($this->request->post['search_string'])) {
    515 			$error = $this->language->get('error_text_missing');
    516 		}
    517 
    518 		if (empty($this->request->post['marketplace'])) {
    519 			$error = $this->language->get('error_marketplace_missing');
    520 		}
    521 
    522 		if ($error) {
    523 			$json = array(
    524 				'data' => '',
    525 				'error' => $error,
    526 			);
    527 		} else {
    528 			$json = array(
    529 				'data' => $this->model_extension_openbay_amazon_listing->search($this->request->post['search_string'], $this->request->post['marketplace']),
    530 				'error' => '',
    531 			);
    532 		}
    533 
    534 		$this->response->addHeader('Content-Type: application/json');
    535 		$this->response->setOutput(json_encode($json));
    536 	}
    537 
    538 	public function bestPrice() {
    539 		$this->load->model('extension/openbay/amazon_listing');
    540 		$this->load->language('extension/openbay/amazon_listing');
    541 
    542 		$error = '';
    543 
    544 		if (empty($this->request->post['asin'])) {
    545 			$error = $this->language->get('error_missing_asin');
    546 		}
    547 
    548 		if (empty($this->request->post['marketplace'])) {
    549 			$error = $this->language->get('error_marketplace_missing');
    550 		}
    551 
    552 		if (empty($this->request->post['condition'])) {
    553 			$error = $this->language->get('error_condition_missing');
    554 		}
    555 
    556 		if ($error) {
    557 			$json = array(
    558 				'data' => '',
    559 				'error' => $error,
    560 			);
    561 		} else {
    562 			$best_price = $this->model_extension_openbay_amazon_listing->getBestPrice($this->request->post['asin'], $this->request->post['condition'], $this->request->post['marketplace']);
    563 
    564 			if ($best_price) {
    565 				$json = array(
    566 					'data' => $best_price,
    567 					'error' => '',
    568 				);
    569 			} else {
    570 				$json = array(
    571 					'data' => '',
    572 					'error' => $this->language->get('error_amazon_price'),
    573 				);
    574 			}
    575 		}
    576 
    577 		$this->response->addHeader('Content-Type: application/json');
    578 		$this->response->setOutput(json_encode($json));
    579 	}
    580 
    581 	public function getProductByAsin() {
    582 		$this->load->model('extension/openbay/amazon_listing');
    583 
    584 		$data = $this->model_extension_openbay_amazon_listing->getProductByAsin($this->request->post['asin'], $this->request->post['market']);
    585 
    586 		$json = array(
    587 			'title' => (string)$data['ItemAttributes']['Title'],
    588 			'img' => (!isset($data['ItemAttributes']['SmallImage']['URL']) ? '' : $data['ItemAttributes']['SmallImage']['URL'])
    589 		);
    590 
    591 		$this->response->addHeader('Content-Type: application/json');
    592 		$this->response->setOutput(json_encode($json));
    593 	}
    594 
    595 	public function getBrowseNodes() {
    596 		$this->load->model('extension/openbay/amazon_listing');
    597 
    598 		$data = array(
    599 			'marketplaceId' => $this->request->post['marketplaceId'],
    600 			'node' => (isset($this->request->post['node']) ? $this->request->post['node'] : ''),
    601 		);
    602 
    603 		$response = $this->model_extension_openbay_amazon_listing->getBrowseNodes($data);
    604 
    605 		$this->response->setOutput($response);
    606 	}
    607 }