shop.balmet.com

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

amazonus_listing.php (24560B)


      1 <?php
      2 class ControllerExtensionOpenbayAmazonusListing extends Controller{
      3 	public function create() {
      4 		$this->load->language('extension/openbay/amazonus_listing');
      5 		$this->load->model('extension/openbay/amazonus_listing');
      6 		$this->load->model('extension/openbay/amazonus');
      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_amazonus_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/amazonus_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_amazonus->getProductStatus($this->request->get['product_id']);
     98 
     99 			if ($listing_status === 'processing' || $listing_status === 'ok') {
    100 				$this->response->redirect($this->url->link('extension/openbay/amazonus_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/amazonus_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/amazonus_listing/search', 'user_token=' . $this->session->data['user_token'], true);
    110 		$data['url_advanced']  = $this->url->link('extension/openbay/amazonus_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/amazonus_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_amazonus_listing_tax_added')) {
    154 			$data['price'] = $product_info['price'] * (1 + $this->config->get('openbay_amazonus_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_amazonus->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['default_condition'] = $this->config->get('openbay_amazonus_listing_default_condition');
    183 
    184 		$data['user_token'] = $this->session->data['user_token'];
    185 
    186 		$data['breadcrumbs'] = array();
    187 
    188 		$data['breadcrumbs'][] = array(
    189 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true),
    190 			'text' => $this->language->get('text_home'),
    191 		);
    192 
    193 		$data['breadcrumbs'][] = array(
    194 			'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true),
    195 			'text' => $this->language->get('text_openbay'),
    196 		);
    197 
    198 		$data['breadcrumbs'][] = array(
    199 			'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true),
    200 			'text' => $this->language->get('text_amazon'),
    201 		);
    202 
    203 		$data['breadcrumbs'][] = array(
    204 			'href' => $this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . $url, true),
    205 			'text' => $this->language->get('heading_title'),
    206 		);
    207 
    208 		$data['header'] = $this->load->controller('common/header');
    209 		$data['column_left'] = $this->load->controller('common/column_left');
    210 		$data['footer'] = $this->load->controller('common/footer');
    211 
    212 		$this->response->setOutput($this->load->view('extension/openbay/amazonus_listing', $data));
    213 	}
    214 
    215 	public function edit() {
    216 		$this->load->model('extension/openbay/amazonus_listing');
    217 		$this->load->model('extension/openbay/amazonus');
    218 		$this->load->language('extension/openbay/amazonus_listing');
    219 
    220 		$this->document->setTitle($this->language->get('text_edit_heading'));
    221 		$this->document->addScript('view/javascript/openbay/js/faq.js');
    222 
    223 		$url = '';
    224 
    225 		if (isset($this->request->get['filter_name'])) {
    226 			$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
    227 		}
    228 
    229 		if (isset($this->request->get['filter_model'])) {
    230 			$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
    231 		}
    232 
    233 		if (isset($this->request->get['filter_price'])) {
    234 			$url .= '&filter_price=' . $this->request->get['filter_price'];
    235 		}
    236 
    237 		if (isset($this->request->get['filter_price_to'])) {
    238 			$url .= '&filter_price_to=' . $this->request->get['filter_price_to'];
    239 		}
    240 
    241 		if (isset($this->request->get['filter_quantity'])) {
    242 			$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
    243 		}
    244 
    245 		if (isset($this->request->get['filter_quantity_to'])) {
    246 			$url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to'];
    247 		}
    248 
    249 		if (isset($this->request->get['filter_status'])) {
    250 			$url .= '&filter_status=' . $this->request->get['filter_status'];
    251 		}
    252 
    253 		if (isset($this->request->get['filter_sku'])) {
    254 			$url .= '&filter_sku=' . $this->request->get['filter_sku'];
    255 		}
    256 
    257 		if (isset($this->request->get['filter_desc'])) {
    258 			$url .= '&filter_desc=' . $this->request->get['filter_desc'];
    259 		}
    260 
    261 		if (isset($this->request->get['filter_category'])) {
    262 			$url .= '&filter_category=' . $this->request->get['filter_category'];
    263 		}
    264 
    265 		if (isset($this->request->get['filter_manufacturer'])) {
    266 			$url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer'];
    267 		}
    268 
    269 		if (isset($this->request->get['sort'])) {
    270 			$url .= '&sort=' . $this->request->get['sort'];
    271 		}
    272 
    273 		if (isset($this->request->get['order'])) {
    274 			$url .= '&order=' . $this->request->get['order'];
    275 		}
    276 
    277 		if (isset($this->request->get['page'])) {
    278 			$url .= '&page=' . $this->request->get['page'];
    279 		}
    280 
    281 		if (isset($this->request->get['product_id'])) {
    282 			$product_id = $this->request->get['product_id'];
    283 		} else {
    284 			$this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true));
    285 		}
    286 
    287 		$data['breadcrumbs'] = array();
    288 
    289 		$data['breadcrumbs'][] = array(
    290 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true),
    291 			'text' => $this->language->get('text_home'),
    292 		);
    293 
    294 		$data['breadcrumbs'][] = array(
    295 			'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true),
    296 			'text' => $this->language->get('text_openbay'),
    297 		);
    298 
    299 		$data['breadcrumbs'][] = array(
    300 			'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true),
    301 			'text' => $this->language->get('text_amazon'),
    302 		);
    303 
    304 		$data['breadcrumbs'][] = array(
    305 			'href' => $this->url->link('extension/openbay/amazonus_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true),
    306 			'text' => $this->language->get('text_edit_heading'),
    307 		);
    308 
    309 		$status = $this->model_extension_openbay_amazonus->getProductStatus($product_id);
    310 
    311 		if ($status === false) {
    312 			$this->response->redirect($this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true));
    313 			return;
    314 		}
    315 
    316 		$data['product_links'] = $this->model_extension_openbay_amazonus->getProductLinks($product_id);
    317 		$data['url_return']  = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true);
    318 		if ($status == 'ok' || $status == 'linked') {
    319 			$data['url_create_new']  = $this->url->link('extension/openbay/amazonus_listing/createNew', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true);
    320 			$data['url_delete_links']  = $this->url->link('extension/openbay/amazonus_listing/deleteLinks', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true);
    321 		}
    322 
    323 		if ($status == 'saved') {
    324 			$data['has_saved_listings'] = true;
    325 		} else {
    326 			$data['has_saved_listings'] = false;
    327 		}
    328 
    329 		$data['url_saved_listings']  = $this->url->link('extension/openbay/amazonus/savedListings', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id, true);
    330 
    331 		$data['user_token'] = $this->session->data['user_token'];
    332 
    333 		$data['text_edit_heading'] = $this->language->get('text_edit_heading');
    334 		$data['text_product_links'] = $this->language->get('text_product_links');
    335 		$data['text_has_saved_listings'] = $this->language->get('text_has_saved_listings');
    336 		$data['button_create_new_listing'] = $this->language->get('button_create_new_listing');
    337 		$data['button_remove_links'] = $this->language->get('button_remove_links');
    338 		$data['button_cancel'] = $this->language->get('button_cancel');
    339 		$data['button_saved_listings'] = $this->language->get('button_saved_listings');
    340 		$data['column_name'] = $this->language->get('column_name');
    341 		$data['column_model'] = $this->language->get('column_model');
    342 		$data['column_combination'] = $this->language->get('column_combination');
    343 		$data['column_sku'] = $this->language->get('column_sku');
    344 		$data['column_amazon_sku'] = $this->language->get('column_amazon_sku');
    345 		$data['column_sku_variant'] = $this->language->get('column_sku_variant');
    346 
    347 		$data['header'] = $this->load->controller('common/header');
    348 		$data['column_left'] = $this->load->controller('common/column_left');
    349 		$data['footer'] = $this->load->controller('common/footer');
    350 
    351 		$this->response->setOutput($this->load->view('extension/openbay/amazonus_listing_edit', $data));
    352 	}
    353 
    354 	public function createNew() {
    355 		$url = '';
    356 
    357 		if (isset($this->request->get['filter_name'])) {
    358 			$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
    359 		}
    360 
    361 		if (isset($this->request->get['filter_model'])) {
    362 			$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
    363 		}
    364 
    365 		if (isset($this->request->get['filter_price'])) {
    366 			$url .= '&filter_price=' . $this->request->get['filter_price'];
    367 		}
    368 
    369 		if (isset($this->request->get['filter_price_to'])) {
    370 			$url .= '&filter_price_to=' . $this->request->get['filter_price_to'];
    371 		}
    372 
    373 		if (isset($this->request->get['filter_quantity'])) {
    374 			$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
    375 		}
    376 
    377 		if (isset($this->request->get['filter_quantity_to'])) {
    378 			$url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to'];
    379 		}
    380 
    381 		if (isset($this->request->get['filter_status'])) {
    382 			$url .= '&filter_status=' . $this->request->get['filter_status'];
    383 		}
    384 
    385 		if (isset($this->request->get['filter_sku'])) {
    386 			$url .= '&filter_sku=' . $this->request->get['filter_sku'];
    387 		}
    388 
    389 		if (isset($this->request->get['filter_desc'])) {
    390 			$url .= '&filter_desc=' . $this->request->get['filter_desc'];
    391 		}
    392 
    393 		if (isset($this->request->get['filter_category'])) {
    394 			$url .= '&filter_category=' . $this->request->get['filter_category'];
    395 		}
    396 
    397 		if (isset($this->request->get['filter_manufacturer'])) {
    398 			$url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer'];
    399 		}
    400 
    401 		if (isset($this->request->get['sort'])) {
    402 			$url .= '&sort=' . $this->request->get['sort'];
    403 		}
    404 
    405 		if (isset($this->request->get['order'])) {
    406 			$url .= '&order=' . $this->request->get['order'];
    407 		}
    408 
    409 		if (isset($this->request->get['page'])) {
    410 			$url .= '&page=' . $this->request->get['page'];
    411 		}
    412 
    413 		if (isset($this->request->get['product_id'])) {
    414 			$product_id = $this->request->get['product_id'];
    415 		} else {
    416 			$this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true));
    417 		}
    418 		$this->load->model('extension/openbay/amazonus');
    419 		$this->model_extension_openbay_amazonus->deleteProduct($product_id);
    420 		$this->response->redirect($this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true));
    421 	}
    422 
    423 	public function deleteLinks() {
    424 		$this->load->language('extension/openbay/amazonus_listing');
    425 		$url = '';
    426 
    427 		if (isset($this->request->get['filter_name'])) {
    428 			$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
    429 		}
    430 
    431 		if (isset($this->request->get['filter_model'])) {
    432 			$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
    433 		}
    434 
    435 		if (isset($this->request->get['filter_price'])) {
    436 			$url .= '&filter_price=' . $this->request->get['filter_price'];
    437 		}
    438 
    439 		if (isset($this->request->get['filter_price_to'])) {
    440 			$url .= '&filter_price_to=' . $this->request->get['filter_price_to'];
    441 		}
    442 
    443 		if (isset($this->request->get['filter_quantity'])) {
    444 			$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
    445 		}
    446 
    447 		if (isset($this->request->get['filter_quantity_to'])) {
    448 			$url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to'];
    449 		}
    450 
    451 		if (isset($this->request->get['filter_status'])) {
    452 			$url .= '&filter_status=' . $this->request->get['filter_status'];
    453 		}
    454 
    455 		if (isset($this->request->get['filter_sku'])) {
    456 			$url .= '&filter_sku=' . $this->request->get['filter_sku'];
    457 		}
    458 
    459 		if (isset($this->request->get['filter_desc'])) {
    460 			$url .= '&filter_desc=' . $this->request->get['filter_desc'];
    461 		}
    462 
    463 		if (isset($this->request->get['filter_category'])) {
    464 			$url .= '&filter_category=' . $this->request->get['filter_category'];
    465 		}
    466 
    467 		if (isset($this->request->get['filter_manufacturer'])) {
    468 			$url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer'];
    469 		}
    470 
    471 		if (isset($this->request->get['sort'])) {
    472 			$url .= '&sort=' . $this->request->get['sort'];
    473 		}
    474 
    475 		if (isset($this->request->get['order'])) {
    476 			$url .= '&order=' . $this->request->get['order'];
    477 		}
    478 
    479 		if (isset($this->request->get['page'])) {
    480 			$url .= '&page=' . $this->request->get['page'];
    481 		}
    482 
    483 		if (isset($this->request->get['product_id'])) {
    484 			$product_id = $this->request->get['product_id'];
    485 		} else {
    486 			$this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true));
    487 		}
    488 
    489 		$this->load->model('extension/openbay/amazonus');
    490 
    491 		$links = $this->model_extension_openbay_amazonus->getProductLinks($product_id);
    492 		foreach ($links as $link) {
    493 			$this->model_extension_openbay_amazonus->removeProductLink($link['amazonus_sku']);
    494 		}
    495 
    496 		$this->model_extension_openbay_amazonus->deleteProduct($product_id);
    497 		$this->session->data['success'] = $this->language->get('text_links_removed');
    498 
    499 		$this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true));
    500 	}
    501 
    502 	public function search() {
    503 		$this->load->model('extension/openbay/amazonus_listing');
    504 		$this->load->language('extension/openbay/amazonus_listing');
    505 
    506 		$error = '';
    507 
    508 		if (empty($this->request->post['search_string'])) {
    509 			$error = $this->language->get('error_text_missing');
    510 		}
    511 
    512 		if ($error) {
    513 			$response = array(
    514 				'data' => '',
    515 				'error' => $error,
    516 			);
    517 		} else {
    518 			$response = array(
    519 				'data' => $this->model_extension_openbay_amazonus_listing->search($this->request->post['search_string']),
    520 				'error' => '',
    521 			);
    522 		}
    523 
    524 		$this->response->addHeader('Content-Type: application/json');
    525 		$this->response->setOutput(json_encode($response));
    526 	}
    527 
    528 	public function bestPrice() {
    529 		$this->load->model('extension/openbay/amazonus_listing');
    530 		$this->load->language('extension/openbay/amazonus_listing');
    531 
    532 		$error = '';
    533 
    534 		if (empty($this->request->post['asin'])) {
    535 			$error = $this->language->get('error_missing_asin');
    536 		}
    537 
    538 		if (empty($this->request->post['condition'])) {
    539 			$error = $this->language->get('error_condition_missing');
    540 		}
    541 
    542 		if ($error) {
    543 			$response = array(
    544 				'data' => '',
    545 				'error' => $error,
    546 			);
    547 		} else {
    548 			$best_price = $this->model_extension_openbay_amazonus_listing->getBestPrice($this->request->post['asin'], $this->request->post['condition']);
    549 
    550 			if ($best_price) {
    551 				$response = array(
    552 					'data' => $best_price,
    553 					'error' => '',
    554 				);
    555 			} else {
    556 				$response = array(
    557 					'data' => '',
    558 					'error' => $this->language->get('error_amazonus_price'),
    559 				);
    560 			}
    561 		}
    562 
    563 		$this->response->addHeader('Content-Type: application/json');
    564 		$this->response->setOutput(json_encode($response));
    565 	}
    566 
    567 	public function getProductByAsin() {
    568 		$this->load->model('extension/openbay/amazonus_listing');
    569 
    570 		$data = $this->model_extension_openbay_amazonus_listing->getProductByAsin($this->request->post['asin']);
    571 
    572 		$response = array(
    573 			'title' => (string)$data['ItemAttributes']['Title'],
    574 			'img' => (!isset($data['ItemAttributes']['SmallImage']['URL']) ? '' : $data['ItemAttributes']['SmallImage']['URL'])
    575 		);
    576 
    577 		$this->response->addHeader('Content-Type: application/json');
    578 		$this->response->setOutput(json_encode($response));
    579 	}
    580 
    581 	public function getBrowseNodes() {
    582 		$this->load->model('extension/openbay/amazonus_listing');
    583 
    584 		$data = array(
    585 			'node' => (isset($this->request->post['node']) ? $this->request->post['node'] : ''),
    586 		);
    587 
    588 		$response = $this->model_extension_openbay_amazonus_listing->getBrowseNodes($data);
    589 
    590 		$this->response->setOutput($response);
    591 	}
    592 }