Amazon MWS GetReport display in Bootstrap PHP

550 views Asked by At

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

1

There are 1 answers

2
Zachary Craig On

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)