1

Hii im using Amazon MWS for submitting the product and getting the orders and getting the product information. Now when im working on product, im fetching all the products available in my amazon inventory, im getting the result and it is in XML format, since im using Yii2.0 php framework i want to parse this into an array and display it.

I have the amazon product API codes in seperate folder, im calling that in my project using the url to get the products in the xml. this im doing it in my controller..

This is under my controller

public function actionProducts()
{
$xml = Yii::$app->httpclient->get('http://localhost/MWSProducts/src/MarketplaceWebServiceProducts/Samples/GetMatchingProductSample.php');
      print_r($xml); 


      return $this->render('products',['items'=>$items]); 
}

Now that $xml has the all the xml which i get from the amazon server, i have to parse it into an array, kindly help to do this. This is an xml which i get

<?xml version="1.0"?>
<GetMatchingProductResult ASIN="0886467918" status="Success">
<Product>
  <Identifiers>
    <MarketplaceASIN>
      <MarketplaceId>***********</MarketplaceId>
      <ASIN>0886467918</ASIN>
    </MarketplaceASIN>
  </Identifiers>
  <AttributeSets>
    <ns2:ItemAttributes xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd" xml:lang="en-IN">
      <ns2:Author>Kipling, Rudyard</ns2:Author>
      <ns2:Binding>Hardcover</ns2:Binding>
      <ns2:Edition>Har/Cas</ns2:Edition>
      <ns2:Format>Import</ns2:Format>
      <ns2:Label>Imprint unknown</ns2:Label>
      <ns2:Languages>
        <ns2:Language>
          <ns2:Name>english</ns2:Name>
          <ns2:Type>Published</ns2:Type>
        </ns2:Language>
        <ns2:Language>
          <ns2:Name>english</ns2:Name>
          <ns2:Type>Original Language</ns2:Type>
        </ns2:Language>
        <ns2:Language>
          <ns2:Name>english</ns2:Name>
          <ns2:Type>Unknown</ns2:Type>
        </ns2:Language>
      </ns2:Languages>
      <ns2:Manufacturer>Imprint unknown</ns2:Manufacturer>
      <ns2:PackageDimensions>
        <ns2:Weight Units="pounds">1.74</ns2:Weight>
      </ns2:PackageDimensions>
      <ns2:ProductGroup>Book</ns2:ProductGroup>
      <ns2:ProductTypeName>ABIS_BOOK</ns2:ProductTypeName>
      <ns2:PublicationDate>1988-05-02</ns2:PublicationDate>
      <ns2:Publisher>Imprint unknown</ns2:Publisher>
      <ns2:SmallImage>
        <ns2:URL>http://ecx.images-amazon.com/images/I/412CsE6Mb8L._SL75_.jpg</ns2:URL>
        <ns2:Height Units="pixels">75</ns2:Height>
        <ns2:Width Units="pixels">50</ns2:Width>
      </ns2:SmallImage>
      <ns2:Studio>Imprint unknown</ns2:Studio>
      <ns2:Title>Jungle Book ("Read Along")</ns2:Title>
    </ns2:ItemAttributes>
  </AttributeSets>
  <Relationships/>
  <SalesRankings>
    <SalesRank>
      <ProductCategoryId>book_display_on_website</ProductCategoryId>
      <Rank>705528</Rank>
    </SalesRank>
    <SalesRank>
      <ProductCategoryId>1318084031</ProductCategoryId>
      <Rank>14177</Rank>
    </SalesRank>
    <SalesRank>
      <ProductCategoryId>1318083031</ProductCategoryId>
      <Rank>46620</Rank>
    </SalesRank>
  </SalesRankings>
</Product>

I have given below code in config file

'httpclient' => [
    'class' =>'understeam\httpclient\Client',
    'detectMimeType' => true, // automatically transform request to data according to response Content-Type header
    'requestOptions' => [
        // see guzzle request options documentation
    ],
    'requestHeaders' => [
        // specify global request headers (can be overrided with $options on making request)
    ],
    ],
Salman Riyaz
  • 808
  • 2
  • 14
  • 37

0 Answers0