shop.balmet.com

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

ebay_product.php (4979B)


      1 <?php
      2 class ModelExtensionOpenBayEbayProduct extends Model {
      3 	public function getTaxRate($class_id) {
      4 		return $this->openbay->getTaxRate($class_id);
      5 	}
      6 
      7 	public function countImportImages() {
      8 		$qry = $this->db->query("SELECT * FROM `" . DB_PREFIX . "ebay_image_import`");
      9 
     10 		return $qry->num_rows;
     11 	}
     12 
     13 	public function getProductOptions($product_id) {
     14 		$product_option_data = array();
     15 
     16 		$product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN " . DB_PREFIX . "option_description od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.sort_order");
     17 
     18 		foreach ($product_option_query->rows as $product_option) {
     19 			if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'image') {
     20 				$product_option_value_data = array();
     21 
     22 				$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.sort_order");
     23 
     24 				foreach ($product_option_value_query->rows as $product_option_value) {
     25 					$product_option_value_data[] = array(
     26 						'product_option_value_id'   => $product_option_value['product_option_value_id'],
     27 						'option_value_id'           => $product_option_value['option_value_id'],
     28 						'name'                      => $product_option_value['name'],
     29 						'image'                     => $product_option_value['image'],
     30 						'image_thumb'               => (!empty($product_option_value['image'])) ? $this->model_tool_image->resize($product_option_value['image'], 100, 100) : '',
     31 						'quantity'                  => $product_option_value['quantity'],
     32 						'subtract'                  => $product_option_value['subtract'],
     33 						'price'                     => $product_option_value['price'],
     34 						'price_prefix'              => $product_option_value['price_prefix'],
     35 						'points'                    => $product_option_value['points'],
     36 						'points_prefix'             => $product_option_value['points_prefix'],
     37 						'weight'                    => $product_option_value['weight'],
     38 						'weight_prefix'             => $product_option_value['weight_prefix']
     39 					);
     40 				}
     41 
     42 				$product_option_data[] = array(
     43 					'product_option_id'     => $product_option['product_option_id'],
     44 					'option_id'             => $product_option['option_id'],
     45 					'name'                  => $product_option['name'],
     46 					'type'                  => $product_option['type'],
     47 					'product_option_value'  => $product_option_value_data,
     48 					'required'              => $product_option['required']
     49 				);
     50 			}
     51 		}
     52 
     53 		return $product_option_data;
     54 	}
     55 
     56 	public function repairLinks() {
     57 		//get distinct product id's where they are active
     58 		$sql = $this->db->query("
     59 			SELECT DISTINCT `product_id`
     60 			FROM `" . DB_PREFIX . "ebay_listing`
     61 			WHERE `status` = '1'");
     62 
     63 		//loop over products and if count is more than 1, update all older entries to 0
     64 		foreach($sql->rows as $row) {
     65 			$sql2 = $this->db->query("SELECT * FROM `" . DB_PREFIX . "ebay_listing` WHERE `product_id` = '" . (int)$row['product_id'] . "' AND `status` = 1 ORDER BY `ebay_listing_id` DESC");
     66 
     67 			if ($sql2->num_rows > 1) {
     68 				$this->db->query("UPDATE `" . DB_PREFIX . "ebay_listing` SET `status` = 0  WHERE `product_id` = '" . (int)$row['product_id'] . "'");
     69 				$this->db->query("UPDATE `" . DB_PREFIX . "ebay_listing` SET `status` = 1  WHERE `ebay_listing_id` = '" . (int)$sql2->row['ebay_listing_id'] . "'");
     70 			}
     71 		}
     72 	}
     73 
     74 	public function searchEbayCatalog($search, $category_id, $page = 1) {
     75 		$response = $this->openbay->ebay->call('listing/searchCatalog/', array('page' => (int)$page, 'categoryId' => $category_id, 'search' => $search));
     76 
     77 		return $response;
     78 	}
     79 
     80 	public function getPartsCompatibilityOptions($category_id) {
     81 		$response = $this->openbay->ebay->call('partscompatibility/getOptions/', array('category_id' => $category_id));
     82 
     83 		return $response;
     84 	}
     85 
     86 	public function getPartsCompatibilityValues($filters) {
     87 		$response = $this->openbay->ebay->call('partscompatibility/getValues/', $filters);
     88 
     89 		return $response;
     90 	}
     91 
     92 	public function getItemRecommendations($filters) {
     93 		$response = $this->openbay->ebay->call('listingrecommendation/recommendations/', $filters);
     94 
     95 		return array(
     96 			'error' => $this->openbay->ebay->lasterror,
     97 			'error_message' => $this->openbay->ebay->lastmsg,
     98 			'data' => $response
     99 		);
    100 	}
    101 }