$response = $this->call('setup/getEbayDetails/', array(), array(), 'json', true);
$this->log('Getting eBay settings / sync');
if ($this->lasterror === false) {
if (isset($response['urls']['ViewItemURL'])) {
$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `key` = 'openbaypro_ebay_itm_link' LIMIT 1");
$this->db->query("INSERT INTO `" . DB_PREFIX . "setting` SET `value` = '" . $this->db->escape((string)$response['urls']['ViewItemURL']) . "', `key` = 'openbaypro_ebay_itm_link', `group` = 'openbay'");
$this->log('Updated eBay item link');
} else {
$this->log('Item link URL not set!');
}
//ebay payment methods
if(isset($response['payment_options'])) {
$this->db->query("TRUNCATE TABLE `" . DB_PREFIX . "ebay_payment_method`");
$this->log('Emptied ebay_payment_method table');
foreach ($response['payment_options'] as $child) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "ebay_payment_method` SET `ebay_name` = '" . $this->db->escape((string)$child['PaymentOption']) . "', `local_name` = '" . $this->db->escape((string)$child['Description']) . "'");
}
$this->log('Populated ebay_payment_method table');
}else{
$this->log('No payment options set!');
}
//ebay shipping
if (isset($response['shipping_service'])) {
$this->db->query("TRUNCATE TABLE `" . DB_PREFIX . "ebay_shipping`");
$this->log('Emptied ebay_shipping table');
foreach ($response['shipping_service'] as $service) {
if (!empty($service['InternationalService'])) {
$service['InternationalService'] = 1;
} else {
$service['InternationalService'] = 0;
}
if (!empty($service['ValidForSellingFlow'])) {
$service['ValidForSellingFlow'] = 1;
} else {
$service['ValidForSellingFlow'] = 0;
}
if (!empty($service['ShippingTimeMin'])) {
$min = (int)$service['ShippingTimeMin'];
} else {
$min = 1;
}
if (!empty($service['ShippingTimeMax'])) {
$max = (int)$service['ShippingTimeMax'];
} else {
$max = 21;
}
$this->db->query("
INSERT INTO `" . DB_PREFIX . "ebay_shipping` SET
`description` = '" . $this->db->escape((string)$service['Description']) . "',
`InternationalService` = '" . $this->db->escape($service['InternationalService']) . "',
`ShippingService` = '" . $this->db->escape((string)$service['ShippingService']) . "' ,
`ShippingServiceID` = '" . (int)$service['ShippingServiceID'] . "',
`ServiceType` = '" . $this->db->escape((string)$service['ServiceType']) . "' ,
`ValidForSellingFlow` = '" . $this->db->escape((string)$service['ValidForSellingFlow']) . "',
`ShippingCategory` = '" . $this->db->escape((string)$service['ShippingCategory']) . "' ,
`ShippingTimeMin` = '" . $min . "',
`ShippingTimeMax` = '" . $max . "',
`site` = '3'
");
}
$this->log('Populated ebay_shipping table');
} else {
$this->log('No shiopping details set!');
}
//shipping locations
if (isset($response['shipping_location'])) {
$this->db->query("TRUNCATE TABLE `" . DB_PREFIX . "ebay_shipping_location`");
$this->log('Emptied ebay_shipping_location table');
foreach ($response['shipping_location'] as $service) {
$this->db->query("
INSERT INTO `" . DB_PREFIX . "ebay_shipping_location`
SET
`description` = '" . $this->db->escape((string)$service['Description']) . "',
`detail_version` = '" . $this->db->escape($service['DetailVersion']) . "',
`shipping_location` = '" . $this->db->escape((string)$service['ShippingLocation']) . "' ,
`update_time` = '" . (int)$service['UpdateTime'] . "'
");
}
$this->log('Populated ebay_shipping_location table');
} else {
$this->log('No shipping locations set!');
}
//shipping locations exclude
if (isset($response['exclude_shipping_location'])) {
$this->db->query("TRUNCATE TABLE `" . DB_PREFIX . "ebay_shipping_location_exclude`");
$this->log('Emptied ebay_shipping_location_exclude table');
foreach ($response['exclude_shipping_location'] as $service) {
$this->db->query("
INSERT INTO `" . DB_PREFIX . "ebay_shipping_location_exclude`
SET
`description` = '" . $this->db->escape((string)$service['Description']) . "',
`location` = '" . $this->db->escape((string)$service['Location']) . "',
`region` = '" . $this->db->escape((string)$service['Region']) . "'
");
}
$this->log('Populated exclude_shipping_location table');
} else {
$this->log('No shipping exclude locations set!');
}
//max dispatch times
if (isset($response['dispatch_time_max'])) {
$qry = $this->db->query("SELECT * FROM `" . DB_PREFIX . "ebay_setting_option` WHERE `key` = 'dispatch_time_max' LIMIT 1");
if ($qry->num_rows > 0) {
$this->db->query("UPDATE `" . DB_PREFIX . "ebay_setting_option` SET `data` = '" . $this->db->escape(serialize($response['dispatch_time_max'])) . "', `last_updated` = now() WHERE `key` = 'dispatch_time_max' LIMIT 1");
$this->log('Updated dispatch_time_max into ebay_setting_option table');
} else {
$this->db->query("INSERT INTO `" . DB_PREFIX . "ebay_setting_option` SET `key` = 'dispatch_time_max', `data` = '" . $this->db->escape(serialize($response['dispatch_time_max'])) . "', `last_updated` = now()");
$this->log('Inserted dispatch_time_max into ebay_setting_option table');
}
} else {
$this->log('No dispatch_time_max set!');
}
//countries
if (isset($response['countries'])) {
$qry = $this->db->query("SELECT * FROM `" . DB_PREFIX . "ebay_setting_option` WHERE `key` = 'countries' LIMIT 1");
if ($qry->num_rows > 0) {
$this->db->query("UPDATE `" . DB_PREFIX . "ebay_setting_option` SET `data` = '" . $this->db->escape(serialize($response['countries'])) . "', `last_updated` = now() WHERE `key` = 'countries' LIMIT 1");
$this->log('Updated countries into ebay_setting_option table');
} else {
$this->db->query("INSERT INTO `" . DB_PREFIX . "ebay_setting_option` SET `key` = 'countries', `data` = '" . $this->db->escape(serialize($response['countries'])) . "', `last_updated` = now()");
$this->log('Inserted countries into ebay_setting_option table');
}
} else {
$this->log('No countries set!');
}
//returns
if (isset($response['returns'])) {
$qry = $this->db->query("SELECT * FROM `" . DB_PREFIX . "ebay_setting_option` WHERE `key` = 'returns' LIMIT 1");
if ($qry->num_rows > 0) {
$this->db->query("UPDATE `" . DB_PREFIX . "ebay_setting_option` SET `data` = '" . $this->db->escape(serialize($response['returns'])) . "', `last_updated` = now() WHERE `key` = 'returns' LIMIT 1");
$this->log('Updated returns info in to ebay_setting_option table');
} else {
$this->db->query("INSERT INTO `" . DB_PREFIX . "ebay_setting_option` SET `key` = 'returns', `data` = '" . $this->db->escape(serialize($response['returns'])) . "', `last_updated` = now()");
$this->log('Inserted returns info in to ebay_setting_option table');
}
} else {
$this->log('No returns set!');
}
}
return array('msg' => $this->lastmsg, 'error' => $this->lasterror);