1

I have created a page using GetReport with a Settlement ID.

So far I'm able to get a data from Amazon Seller, but i am trying to figure out how to turn the report into a tidy table.

Here is my code:

function invokeGetReport(MarketplaceWebService_Interface $service, $request)  {
  try {
      $response = $service->getReport($request);
        echo ("<table class='table table-bordered table-striped table-hover table-condensed table-responsive'>\n");
        echo ("<thead>");
        echo ("<tr> ");
        echo ("<th >Settlement ID</th> ");
        echo ("<td>");
        echo ("Settlement ID Report display here");
        echo ("</td></tr>");
        echo ("<tr> ");
        echo ("<th>GetReportResponse\n</th> ");
        echo ("<td>");
        if ($response->isSetGetReportResult()) {
          $getReportResult = $response->getGetReportResult(); 
          echo ("            GetReport");
        echo ("</td></tr>");
      }
        //Report Content
        echo ("<tr> ");
        echo ("<th>Settlement ID</th> ");
        echo ("<td>");
        echo (stream_get_contents($request->getReport()) . "\n");
        echo ("</td></tr>");    
      } catch (MarketplaceWebService_Exception $ex) {
        echo("Caught Exception: " . $ex->getMessage() . "\n");
        echo("Response Status Code: " . $ex->getStatusCode() . "\n");
        echo("Error Code: " . $ex->getErrorCode() . "\n");
        echo("Error Type: " . $ex->getErrorType() . "\n");
        echo("Request ID: " . $ex->getRequestId() . "\n");
        echo("XML: " . $ex->getXML() . "\n");
        echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
        echo ("</td></tr>"); 
        echo ("</table>\n");
  }

}

As you can see:

stream_get_contents($request->getReport())

is where I pull the Settlement Report, however, I want getReport() to breakdown into more details in a tidy table, at the moment it looks like this

enter image description here

I was hoping for more like this

enter image description here

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Steven Smith
  • 406
  • 5
  • 19

1 Answers1

1

Per Amazon MWS Documentation for getReport here

Your function call to $request->getReport() returns a tab seperated file, you can turn this into an array pretty easily, and then loop over it and print them as a table, try using the PHP str-getcsv or fgetcsv function and using tab as the delimiter

If you need the headers and want to use it as an associative array, there are plenty of guides on doing that for csv, but not many that are specific to tsv, as I can't tell much from your code as i'm unfamiliar with your specific library you're using, I can't point you to one solution that will do that for you, but there are a few for CSV that with some tweaking you could get to work, for example:

this(stackoverflow.com), this(stackoverflow.com), and this(php.net)

Zachary Craig
  • 2,192
  • 4
  • 23
  • 34
  • First of all, Thank you for your answer. Sorry for not get back to you asap. – Steven Smith Apr 25 '18 at 08:31
  • This page was I was using on GetReportSample.php in the PHP files that I download it from Amazon MWS. You can see more on a code in the https://github.com/jedistev/Amazon-MWS-API. I will read about using the PHP str-getcsv or fgetcsv. – Steven Smith Apr 25 '18 at 08:42