* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 1.4 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class eBayRequest
{
public $response;
public $token;
public $expiration;
public $runame;
public $username;
public $session;
public $itemID;
public $fees;
public $error;
public $errorCode;
private $devID;
private $appID;
private $certID;
private $siteID;
private $apiUrl;
private $apiCall;
private $loginUrl;
private $findingUrl;
private $findingVersion;
private $compatibilityLevel;
/******************************************************************/
/** Constructor And Request Methods *******************************/
/******************************************************************/
public function __construct($apiCall = '')
{
/*** SAND BOX PARAMS ***/
/*
$this->devID = '1db92af1-2824-4c45-8343-dfe68faa0280';
$this->appID = 'Prestash-2629-4880-ba43-368352aecc86';
$this->certID = '6bd3f4bd-3e21-41e8-8164-7ac733218122';
$this->siteID = 71;
$this->apiUrl = 'https://api.sandbox.ebay.com/ws/api.dll';
$this->apiCall = $apiCall;
$this->compatibilityLevel = 719;
$this->runame = 'Prestashop-Prestash-2629-4-hpehxegu';
$this->loginURL = 'https://signin.sandbox.ebay.com/ws/eBayISAPI.dll';
*/
$this->devID = '1db92af1-2824-4c45-8343-dfe68faa0280';
$this->appID = 'Prestash-70a5-419b-ae96-f03295c4581d';
$this->certID = '71d26dc9-b36b-4568-9bdb-7cb8af16ac9b';
$this->siteID = 71;
$this->apiUrl = 'https://api.ebay.com/ws/api.dll';
$this->apiCall = $apiCall;
$this->compatibilityLevel = 719;
$this->runame = 'Prestashop-Prestash-70a5-4-pepwa';
$this->loginURL = 'https://signin.ebay.com/ws/eBayISAPI.dll';
}
public function makeRequest($request)
{
// Init
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $this->apiUrl);
// Stop CURL from verifying the peer's certificate
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
// Set the headers
curl_setopt($connection, CURLOPT_HTTPHEADER, $this->buildHeaders());
// Set method as POST
curl_setopt($connection, CURLOPT_POST, 1);
// Set the XML body of the request
curl_setopt($connection, CURLOPT_POSTFIELDS, $request);
// Set it to return the transfer as a string from curl_exec
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
// Send the Request
$response = curl_exec($connection);
// Close the connection
curl_close($connection);
// Return the response
return $response;
}
private function buildHeaders()
{
$headers = array (
// Regulates versioning of the XML interface for the API
'X-EBAY-API-COMPATIBILITY-LEVEL: '.$this->compatibilityLevel,
// Set the keys
'X-EBAY-API-DEV-NAME: '.$this->devID,
'X-EBAY-API-APP-NAME: '.$this->appID,
'X-EBAY-API-CERT-NAME: '.$this->certID,
// The name of the call we are requesting
'X-EBAY-API-CALL-NAME: '.$this->apiCall,
//SiteID must also be set in the Request's XML
//SiteID = 0 (US) - UK = 3, Canada = 2, Australia = 15, ....
//SiteID Indicates the eBay site to associate the call with
'X-EBAY-API-SITEID: '.$this->siteID,
);
return $headers;
}
/******************************************************************/
/** Authentication Methods ****************************************/
/******************************************************************/
function fetchToken()
{
// Set Api Call
$this->apiCall = 'FetchToken';
$requestXml = '';
$requestXml .= '';
$requestXml .= ''.$this->username.'';
$requestXml .= ''.$this->session.'';
$requestXml .= '';
// Send the request and get response
$responseXml = $this->makeRequest($requestXml);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
{
$this->error = 'Error sending '.$this->apiCall.' request';
return false;
}
// Saving Datas // Need to cast token var to string (not SimpleXML element) to persist in SESSION
$this->response = simplexml_load_string($responseXml);
$this->token = (string)$this->response->eBayAuthToken;
$this->expiration = $this->response->HardExpirationTime;
}
function getLoginUrl()
{
return $this->loginURL;
}
function login()
{
// Set Api Call
$this->apiCall = 'GetSessionID';
///Build the request Xml string
$requestXml = '';
$requestXml .= '';
$requestXml .= ''.$this->compatibilityLevel.'';
$requestXml .= ''.$this->runame.'';
$requestXml .= '';
// Send the request and get response
$responseXml = $this->makeRequest($requestXml);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
{
$this->error = 'Error sending '.$this->apiCall.' request';
return false;
}
$this->response = simplexml_load_string($responseXml);
$this->session = (string)$this->response->SessionID;
}
/******************************************************************/
/** Retrieve Categories Methods ***********************************/
/******************************************************************/
function saveCategories()
{
// Set Api Call
$this->apiCall = 'GetCategories';
///Build the request Xml string
$requestXml = '';
$requestXml .= '';
$requestXml .= ''.$this->compatibilityLevel.'';
$requestXml .= '';
$requestXml .= ''.Configuration::get('EBAY_API_TOKEN').'';
$requestXml .= '';
$requestXml .= ''.$this->siteID.'';
$requestXml .= 'ReturnAll';
$requestXml .= '5';
$requestXml .= 'true';
$requestXml .= '';
// Send the request and get response
$responseXml = $this->makeRequest($requestXml);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
{
$this->error = 'Error sending '.$this->apiCall.' request';
return false;
}
// Load xml in array
$this->response = simplexml_load_string($responseXml);
// Load categories multi sku compliant
$categoriesMultiSkuCompliant = $this->GetCategoryFeatures('VariationsEnabled');
// Save categories
foreach ($this->response->CategoryArray->Category as $cat)
{
$category = array();
foreach ($cat as $key => $value)
$category[(string)$key] = (string)$value;
$category['IsMultiSku'] = 0;
if (isset($categoriesMultiSkuCompliant[$category['CategoryID']]))
$category['IsMultiSku'] = 1;
Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_category', array('id_category_ref' => pSQL($category['CategoryID']), 'id_category_ref_parent' => pSQL($category['CategoryParentID']), 'id_country' => '8', 'level' => pSQL($category['CategoryLevel']), 'is_multi_sku' => pSQL($category['IsMultiSku']), 'name' => pSQL($category['CategoryName'])), 'INSERT');
}
// Return
return true;
}
function GetCategoryFeatures($featureID)
{
// Set Api Call
$this->apiCall = 'GetCategoryFeatures';
///Build the request Xml string
$requestXml = ''."\n";
$requestXml .= ''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.Configuration::get('EBAY_API_TOKEN').''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' ReturnAll'."\n";
$requestXml .= ' '.$featureID.''."\n";
$requestXml .= ' fr_FR'."\n";
$requestXml .= ' '.$this->compatibilityLevel.''."\n";
$requestXml .= ' High'."\n";
$requestXml .= ' true'."\n";
$requestXml .= ''."\n";
// Send the request and get response
$responseXml = $this->makeRequest($requestXml);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
{
$this->error = 'Error sending '.$this->apiCall.' request';
return false;
}
// Load xml in array
$categoriesFeatures = array();
$response = simplexml_load_string($responseXml);
if ($featureID == 'VariationsEnabled')
{
foreach ($response->Category as $cat)
if ($cat->VariationsEnabled == true)
$categoriesFeatures[(string)$cat->CategoryID] = true;
}
else
return array();
return $categoriesFeatures;
}
function getSuggestedCategories($query)
{
// Set Api Call
$this->apiCall = 'GetSuggestedCategories';
///Build the request Xml string
$requestXml = ''."\n";
$requestXml .= ''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.Configuration::get('EBAY_API_TOKEN').''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' fr_FR'."\n";
$requestXml .= ' '.$this->compatibilityLevel.''."\n";
$requestXml .= ' High'."\n";
$requestXml .= ' '.substr(strtolower($query), 0, 350).''."\n";
$requestXml .= ''."\n";
// Send the request and get response
$responseXml = $this->makeRequest($requestXml);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
{
$this->error = 'Error sending '.$this->apiCall.' request';
return false;
}
// Load xml in array
$response = simplexml_load_string($responseXml);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
{
$this->error = 'Error sending '.$this->apiCall.' request';
return false;
}
if (isset($response->SuggestedCategoryArray->SuggestedCategory[0]->Category->CategoryID))
return (int)$response->SuggestedCategoryArray->SuggestedCategory[0]->Category->CategoryID;
return 0;
}
/******************************************************************/
/** Add Product Methods *******************************************/
/******************************************************************/
function addFixedPriceItem($datas = array())
{
// Check data
if (!$datas)
return false;
// Set Api Call
$this->apiCall = 'AddFixedPriceItem';
// Without variations
$requestXml = ''."\n";
$requestXml .= ''."\n";
$requestXml .= ' fr_FR'."\n";
$requestXml .= ' High'."\n";
$requestXml .= ' - '."\n";
$requestXml .= ' prestashop-'.$datas['id_product'].'';
$requestXml .= ' '.substr($datas['name'], 0, 55).''."\n";
if (isset($datas['pictures']))
{
$requestXml .= ' '."\n";
$requestXml .= ' Gallery'."\n";
foreach ($datas['pictures'] as $picture)
$requestXml .= ' '.$picture.''."\n";
$requestXml .= ' '."\n";
}
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.$datas['categoryId'].''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' 1000'."\n";
$requestXml .= ' '.$datas['price'].''."\n";
$requestXml .= ' true'."\n";
$requestXml .= ' FR'."\n";
$requestXml .= ' EUR'."\n";
$requestXml .= ' 3'."\n";
$requestXml .= ' GTC'."\n";
$requestXml .= ' FixedPriceItem'."\n";
$requestXml .= ' PayPal'."\n";
$requestXml .= ' '.Configuration::get('EBAY_PAYPAL_EMAIL').''."\n";
$requestXml .= ' '.Configuration::get('EBAY_SHOP_POSTALCODE').''."\n";
$requestXml .= ' '.$datas['quantity'].''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' Etat'."\n";
$requestXml .= ' Neuf'."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' Marque'."\n";
$requestXml .= ' '.$datas['brand'].''."\n";
$requestXml .= ' '."\n";
if (isset($datas['attributes']))
foreach ($datas['attributes'] as $name => $value)
{
$requestXml .= ' '."\n";
$requestXml .= ' '.$name.''."\n";
$requestXml .= ' '.$value.''."\n";
$requestXml .= ' '."\n";
}
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' 1'."\n";
$requestXml .= ' '.$datas['shippingService'].''."\n";
$requestXml .= ' false'."\n";
$requestXml .= ' '.$datas['shippingCost'].''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' France'."\n";
$requestXml .= '
'."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.Configuration::get('EBAY_API_TOKEN').''."\n";
$requestXml .= ' '."\n";
$requestXml .= ''."\n";
// Send the request and get response
$responseXml = $this->makeRequest($requestXml);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
{
$this->error = 'Error sending '.$this->apiCall.' request';
return false;
}
// Loading XML tree in array
$this->response = simplexml_load_string($responseXml);
// Checking Errors
$this->error = '';
$this->errorCode = '';
if (isset($this->response->Errors) && isset($this->response->Ack) && (string)$this->response->Ack != 'Success' && (string)$this->response->Ack != 'Warning')
foreach ($this->response->Errors as $e)
{
// if product no longer on eBay, we log the error code
if ((int)$e->ErrorCode == 291)
$this->errorCode = (int)$e->ErrorCode;
// We log error message
if ($e->SeverityCode == 'Error')
{
if ($this->error != '')
$this->error .= '
';
$this->error .= (string)$e->LongMessage;
if (isset($e->ErrorParameters->Value))
$this->error .= '
'.(string)$e->ErrorParameters->Value;
}
}
// Checking Success
$this->itemID = 0;
if (isset($this->response->Ack) && ((string)$this->response->Ack == 'Success' || (string)$this->response->Ack == 'Warning'))
{
$this->fees = 0;
$this->itemID = (string)$this->response->ItemID;
if (isset($this->response->Fees->Fee))
foreach ($this->response->Fees->Fee as $f)
$this->fees += (float)$f->Fee;
}
elseif ($this->error == '')
$this->error = 'Sorry, technical problem, try again later.';
if (!empty($this->error))
return false;
return true;
}
function reviseFixedPriceItem($datas = array())
{
// Check data
if (!$datas)
return false;
// Set Api Call
$this->apiCall = 'ReviseFixedPriceItem';
// Build the request Xml string
$requestXml = ''."\n";
$requestXml .= ''."\n";
$requestXml .= ' fr_FR'."\n";
$requestXml .= ' High'."\n";
$requestXml .= ' - '."\n";
$requestXml .= ' '.$datas['itemID'].''."\n";
$requestXml .= ' prestashop-'.$datas['id_product'].'';
$requestXml .= ' '.$datas['quantity'].''."\n";
$requestXml .= ' '.$datas['price'].''."\n";
if (Configuration::get('EBAY_SYNC_OPTION_RESYNC') != 1)
{
$requestXml .= ' '.substr($datas['name'], 0, 55).''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' 1'."\n";
$requestXml .= ' '.$datas['shippingService'].''."\n";
$requestXml .= ' false'."\n";
$requestXml .= ' '.$datas['shippingCost'].''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
}
$requestXml .= '
'."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.Configuration::get('EBAY_API_TOKEN').''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' High'."\n";
$requestXml .= ''."\n";
// Send the request and get response
$responseXml = $this->makeRequest($requestXml);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
{
$this->error = 'Error sending '.$this->apiCall.' request';
return false;
}
// Loading XML tree in array
$this->response = simplexml_load_string($responseXml);
// Checking Errors
$this->error = '';
$this->errorCode = '';
if (isset($this->response->Errors) && isset($this->response->Ack) && (string)$this->response->Ack != 'Success' && (string)$this->response->Ack != 'Warning')
foreach ($this->response->Errors as $e)
{
// if product no longer on eBay, we log the error code
if ((int)$e->ErrorCode == 291)
$this->errorCode = (int)$e->ErrorCode;
// We log error message
if ($e->SeverityCode == 'Error')
{
if ($this->error != '')
$this->error .= '
';
$this->error .= (string)$e->LongMessage;
if (isset($e->ErrorParameters->Value))
$this->error .= '
'.(string)$e->ErrorParameters->Value;
}
}
// Checking Success
$this->itemID = 0;
if (isset($this->response->Ack) && ((string)$this->response->Ack == 'Success' || (string)$this->response->Ack == 'Warning'))
{
$this->fees = 0;
$this->itemID = (string)$this->response->ItemID;
if (isset($this->response->Fees->Fee))
foreach ($this->response->Fees->Fee as $f)
$this->fees += (float)$f->Fee;
}
elseif ($this->error == '')
$this->error = 'Sorry, technical problem, try again later.';
if (!empty($this->error))
return false;
return true;
}
function addFixedPriceItemMultiSku($datas = array())
{
// Check data
if (!$datas)
return false;
// Set Api Call
$this->apiCall = 'AddFixedPriceItem';
// Build the request Xml string
$requestXml = ''."\n";
$requestXml .= ''."\n";
$requestXml .= ' fr_FR'."\n";
$requestXml .= ' High'."\n";
$requestXml .= ' - '."\n";
$requestXml .= ' FR'."\n";
$requestXml .= ' EUR'."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' 1000'."\n";
$requestXml .= ' 3'."\n";
$requestXml .= ' GTC'."\n";
$requestXml .= ' FixedPriceItem'."\n";
$requestXml .= ' PayPal'."\n";
$requestXml .= ' '.Configuration::get('EBAY_PAYPAL_EMAIL').''."\n";
$requestXml .= ' '.Configuration::get('EBAY_SHOP_POSTALCODE').''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.$datas['categoryId'].''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.substr($datas['name'], 0, 55).''."\n";
if (isset($datas['pictures']))
{
$requestXml .= '';
foreach ($datas['pictures'] as $picture)
$requestXml .= ''.$picture.''."\n";
$requestXml .= '';
}
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' Etat'."\n";
$requestXml .= ' Neuf'."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' Marque'."\n";
$requestXml .= ' '.$datas['brand'].''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
if (isset($datas['variations']))
{
// Generate Variations Set
$requestXml .= ' '."\n";
foreach ($datas['variationsList'] as $group => $v)
{
$requestXml .= ' '."\n";
$requestXml .= ' '.$group.''."\n";
foreach ($v as $attr => $val)
$requestXml .= ' '.$attr.''."\n";
$requestXml .= ' '."\n";
}
$requestXml .= ' '."\n";
// Generate Variations
foreach ($datas['variations'] as $key => $variation)
{
$requestXml .= ' '."\n";
$requestXml .= ' prestashop-'.$key.''."\n";
$requestXml .= ' '.$variation['price'].''."\n";
$requestXml .= ' '.$variation['quantity'].''."\n";
$requestXml .= ' '."\n";
foreach ($variation['variations'] as $v)
{
$requestXml .= ' '."\n";
$requestXml .= ' '.$v['name'].''."\n";
$requestXml .= ' '.$v['value'].''."\n";
$requestXml .= ' '."\n";
}
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
}
// Generate Pictures Variations
$lastSpecificName = '';
$attributeUsed = array();
$requestXml .= ' '."\n";
foreach ($datas['variations'] as $key => $variation)
foreach ($variation['variations'] as $kv => $v)
if (!isset($attributeUsed[md5($v['name'].$v['value'])]) && isset($variation['pictures'][$kv]))
{
if ($lastSpecificName != $v['name'])
$requestXml .= ' '.$v['name'].''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.$v['value'].''."\n";
$requestXml .= ' '.$variation['pictures'][$kv].''."\n";
$requestXml .= ' '."\n";
$attributeUsed[md5($v['name'].$v['value'])] = true;
$lastSpecificName = $v['name'];
}
$requestXml .= ' '."\n";
}
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' 1'."\n";
$requestXml .= ' '.$datas['shippingService'].''."\n";
$requestXml .= ' false'."\n";
$requestXml .= ' '.$datas['shippingCost'].''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' France'."\n";
$requestXml .= '
'."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.Configuration::get('EBAY_API_TOKEN').''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' High'."\n";
$requestXml .= ''."\n";
// Send the request and get response
$responseXml = $this->makeRequest($requestXml);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
{
$this->error = 'Error sending '.$this->apiCall.' request';
return false;
}
// Loading XML tree in array
$this->response = simplexml_load_string($responseXml);
// Checking Errors
$this->error = '';
$this->errorCode = '';
if (isset($this->response->Errors) && isset($this->response->Ack) && (string)$this->response->Ack != 'Success' && (string)$this->response->Ack != 'Warning')
foreach ($this->response->Errors as $e)
{
// if product no longer on eBay, we log the error code
if ((int)$e->ErrorCode == 291)
$this->errorCode = (int)$e->ErrorCode;
// We log error message
if ($e->SeverityCode == 'Error')
{
if ($this->error != '')
$this->error .= '
';
$this->error .= (string)$e->LongMessage;
if (isset($e->ErrorParameters->Value))
$this->error .= '
'.(string)$e->ErrorParameters->Value;
}
}
// Checking Success
$this->itemID = 0;
if (isset($this->response->Ack) && ((string)$this->response->Ack == 'Success' || (string)$this->response->Ack == 'Warning'))
{
$this->fees = 0;
$this->itemID = (string)$this->response->ItemID;
if (isset($this->response->Fees->Fee))
foreach ($this->response->Fees->Fee as $f)
$this->fees += (float)$f->Fee;
}
elseif ($this->error == '')
$this->error = 'Sorry, technical problem, try again later.';
if (!empty($this->error))
return false;
return true;
}
function reviseFixedPriceItemMultiSku($datas = array())
{
// Check data
if (!$datas)
return false;
// Set Api Call
$this->apiCall = 'ReviseFixedPriceItem';
// Build the request Xml string
$requestXml = ''."\n";
$requestXml .= ''."\n";
$requestXml .= ' fr_FR'."\n";
$requestXml .= ' High'."\n";
$requestXml .= ' - '."\n";
$requestXml .= ' '.$datas['itemID'].''."\n";
$requestXml .= ' FR'."\n";
$requestXml .= ' EUR'."\n";
$requestXml .= ' 1000'."\n";
$requestXml .= ' 3'."\n";
$requestXml .= ' GTC'."\n";
$requestXml .= ' FixedPriceItem'."\n";
$requestXml .= ' PayPal'."\n";
$requestXml .= ' '.Configuration::get('EBAY_PAYPAL_EMAIL').''."\n";
$requestXml .= ' '.Configuration::get('EBAY_SHOP_POSTALCODE').''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.$datas['categoryId'].''."\n";
$requestXml .= ' '."\n";
if (isset($datas['pictures']))
{
$requestXml .= '';
foreach ($datas['pictures'] as $picture)
$requestXml .= ''.$picture.''."\n";
$requestXml .= '';
}
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' Etat'."\n";
$requestXml .= ' Neuf'."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' Marque'."\n";
$requestXml .= ' '.$datas['brand'].''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
if (isset($datas['variations']))
{
// Generate Variations Set
$requestXml .= ' '."\n";
foreach ($datas['variationsList'] as $group => $v)
{
$requestXml .= ' '."\n";
$requestXml .= ' '.$group.''."\n";
foreach ($v as $attr => $val)
$requestXml .= ' '.$attr.''."\n";
$requestXml .= ' '."\n";
}
$requestXml .= ' '."\n";
// Generate Variations
foreach ($datas['variations'] as $key => $variation)
{
$requestXml .= ' '."\n";
$requestXml .= ' prestashop-'.$key.''."\n";
$requestXml .= ' '.$variation['price'].''."\n";
$requestXml .= ' '.$variation['quantity'].''."\n";
$requestXml .= ' '."\n";
foreach ($variation['variations'] as $v)
{
$requestXml .= ' '."\n";
$requestXml .= ' '.$v['name'].''."\n";
$requestXml .= ' '.$v['value'].''."\n";
$requestXml .= ' '."\n";
}
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
}
// Generate Pictures Variations
$lastSpecificName = '';
$attributeUsed = array();
$requestXml .= ' '."\n";
foreach ($datas['variations'] as $key => $variation)
foreach ($variation['variations'] as $kv => $v)
if (!isset($attributeUsed[md5($v['name'].$v['value'])]) && isset($variation['pictures'][$kv]))
{
if ($lastSpecificName != $v['name'])
$requestXml .= ' '.$v['name'].''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.$v['value'].''."\n";
$requestXml .= ' '.$variation['pictures'][$kv].''."\n";
$requestXml .= ' '."\n";
$attributeUsed[md5($v['name'].$v['value'])] = true;
$lastSpecificName = $v['name'];
}
$requestXml .= ' '."\n";
}
$requestXml .= ' '."\n";
if (Configuration::get('EBAY_SYNC_OPTION_RESYNC') != 1)
{
$requestXml .= ' '.substr($datas['name'], 0, 55).''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
$requestXml .= ' 1'."\n";
$requestXml .= ' '.$datas['shippingService'].''."\n";
$requestXml .= ' false'."\n";
$requestXml .= ' '.$datas['shippingCost'].''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '."\n";
}
$requestXml .= ' France'."\n";
$requestXml .= '
'."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.Configuration::get('EBAY_API_TOKEN').''."\n";
$requestXml .= ' '."\n";
$requestXml .= ' High'."\n";
$requestXml .= ''."\n";
// Send the request and get response
$responseXml = $this->makeRequest($requestXml);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
{
$this->error = 'Error sending '.$this->apiCall.' request';
return false;
}
// Loading XML tree in array
$this->response = simplexml_load_string($responseXml);
// Checking Errors
$this->error = '';
$this->errorCode = '';
if (isset($this->response->Errors) && isset($this->response->Ack) && (string)$this->response->Ack != 'Success' && (string)$this->response->Ack != 'Warning')
foreach ($this->response->Errors as $e)
{
// if product no longer on eBay, we log the error code
if ((int)$e->ErrorCode == 291)
$this->errorCode = (int)$e->ErrorCode;
// We log error message
if ($e->SeverityCode == 'Error')
{
if ($this->error != '')
$this->error .= '
';
$this->error .= (string)$e->LongMessage;
if (isset($e->ErrorParameters->Value))
$this->error .= '
'.(string)$e->ErrorParameters->Value;
}
}
// Checking Success
$this->itemID = 0;
if (isset($this->response->Ack) && ((string)$this->response->Ack == 'Success' || (string)$this->response->Ack == 'Warning'))
{
$this->fees = 0;
$this->itemID = (string)$this->response->ItemID;
if (isset($this->response->Fees->Fee))
foreach ($this->response->Fees->Fee as $f)
$this->fees += (float)$f->Fee;
}
elseif ($this->error == '')
$this->error = 'Sorry, technical problem, try again later.';
if (!empty($this->error))
return false;
return true;
}
/******************************************************************/
/** Order Methods *************************************************/
/******************************************************************/
function getOrders($CreateTimeFrom, $CreateTimeTo)
{
// Check data
if (!$CreateTimeFrom || !$CreateTimeTo)
return false;
// Set Api Call
$this->apiCall = 'GetOrders';
// Without variations
$requestXml = ''."\n";
$requestXml .= ''."\n";
$requestXml .= ' ReturnAll'."\n";
$requestXml .= ' fr_FR'."\n";
$requestXml .= ' High'."\n";
$requestXml .= ' '.$CreateTimeFrom.''."\n";
$requestXml .= ' '.$CreateTimeTo.''."\n";
$requestXml .= ' Seller'."\n";
$requestXml .= ' '."\n";
$requestXml .= ' '.Configuration::get('EBAY_API_TOKEN').''."\n";
$requestXml .= ' '."\n";
$requestXml .= ''."\n";
// Send the request and get response
$responseXml = $this->makeRequest($requestXml);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
{
$this->error = 'Error sending '.$this->apiCall.' request';
return false;
}
// Loading XML tree in array
$this->response = simplexml_load_string($responseXml);
// Checking Errors
$this->error = '';
if (isset($this->response->Errors) && isset($this->response->Ack) && (string)$this->response->Ack != 'Success' && (string)$this->response->Ack != 'Warning')
foreach ($this->response->Errors as $e)
{
if ($this->error != '')
$this->error .= '
';
$this->error .= (string)$e->LongMessage;
}
// Checking Success
$orderList = array();
if (isset($this->response->OrderArray))
foreach ($this->response->OrderArray->Order as $order)
{
$name = explode(' ', (string)$order->ShippingAddress->Name);
$itemList = array();
foreach ($order->TransactionArray->Transaction as $transaction)
{
$id_product = 0;
$id_attribute = 0;
$quantity = (string)$transaction->QuantityPurchased;
if (isset($transaction->item->SKU))
{
$tmp = explode('-', (string)$transaction->item->SKU);
$id_product = $tmp[1];
}
if (isset($transaction->Variation->SKU))
{
$tmp = explode('-', (string)$transaction->Variation->SKU);
$id_product = $tmp[1];
$id_product_attribute = $tmp[2];
}
if ($id_product > 0)
$itemList[] = array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $quantity, 'price' => (string)$transaction->TransactionPrice);
}
$orderList[] = array(
'id_order_ref' => (string)$order->OrderID,
'amount' => (string)$order->AmountPaid,
'status' => (string)$order->CheckoutStatus->Status,
'date' => substr((string)$order->CreatedTime, 0, 10).' '.substr((string)$order->CreatedTime, 11, 8),
'name' => (string)$order->ShippingAddress->Name,
'firstname' => $name[0],
'familyname' => $name[1],
'address1' => (string)$order->ShippingAddress->Street1,
'address2' => (string)$order->ShippingAddress->Street2,
'city' => (string)$order->ShippingAddress->CityName,
'state' => (string)$order->ShippingAddress->StateOrProvince,
'country_iso_code' => (string)$order->ShippingAddress->Country,
'country_name' => (string)$order->ShippingAddress->CountryName,
'phone' => (string)$order->ShippingAddress->Phone,
'postalcode' => (string)$order->ShippingAddress->PostalCode,
'shippingService' => (string)$order->ShippingServiceSelected->ShippingService,
'shippingServiceCost' => (string)$order->ShippingServiceSelected->ShippingServiceCost,
'email' => (string)$order->TransactionArray->Transaction[0]->Buyer->Email,
'product_list' => $itemList,
'object' => $order
);
}
return $orderList;
}
}
class eBayPayment extends PaymentModule
{
}