Hello guys if as a seller you want fetch the order details of your product using API then follow the steps:
1. You have to download Orders API ---- Link
There you can find orders API in different languages.
We will go specifically for PHP language.
2. Extract the file and go to the MarketplaceWebServiceOrders\Samples\.config.inc.php
Set the credential for your seller account.
3. Now you can fetch the data available at your seller id using ListOrdersSample.php file.
4. Here API will give you the array objects.
I know we want to get those information in proper array.
So, You can follow the steps:
You are getting the array in variable
$response
by the code
$response = $service->ListOrders($request);
Now, I know in default program they have given us DOM format
echo $dom->saveXML();
Here, We can convert this DOM to Multidimensional array To Associative array using following code:
echo $dom->saveXML();
##########################################
# XML to Level 1 multi dimensional array
##########################################
$i=0;
$mda = array(); // mda = Multi dimensional array
while(is_object($finance = $dom->getElementsByTagName("Order")->item($i)))
{
foreach($finance->childNodes as $nodename)
{
if($nodename->nodeName=='ShippingAddress' || $nodename->nodeName=='OrderTotal' || $nodename->nodeName=='PaymentMethodDetails')
{
foreach($nodename->childNodes as $subNodes)
{
$mda[$i][$subNodes->nodeName] = $subNodes->nodeValue;
}
}
else
{
$mda[$i][$nodename->nodeName] = $nodename->nodeValue;
}
}
$i++;
}
############################################
# Multi Dimension to Associative array
############################################
$asa = array(); // asa = Associative array
$keys = array_keys($mda);
for($i = 0; $i < count($mda); $i++)
{
$no = $keys[$i];
echo $no."\r\n" ;
foreach($mda[$keys[$i]] as $key => $value)
{
$asa[$key] = $value;
}
echo $col = implode(', ',array_keys($asa)). "\r\n";
echo $values = "'" .implode("','", array_values($asa)) . "'"." \r\n";
}
print_r($asa); // Will print Associative array
Copy past above code and you will get amazon order in Associative array format.
It will be easy and helpful to you make further operation.

No comments