Thursday, 16 February 2017

Amazon Product Advertising API Integration Advance - Fetch Top Seller Products


Amazon Product Advertising API Integration Advance - Fetch Top Seller Products



Hopefully you are ready with all prerequisite for integrating Amazon Product Advertising API as per our Amazon Product Advertising API integration Basics

We are now going to demonstrate how you can implement functionality to get/fetch the top seller Items/Products from Amazon Product Base as per your specified parameters for country, category, browse node

/*
* This function will give you first 10 top seller items of specific category
*/


function getTopSellerItems( $catType = "" ) {

    global $amazonEcs;
    $allTopSellerASINs = array();

    // Where AWS_CAT_NODE_ALL_MOBILES is specific category node id
    $topSellerFor[AWS_CAT_NODE_ALL_MOBILES] = 'mobile';
  
   
    try {
        foreach ($topSellerFor as $topSeller => $typeKey) {
               


                // Call to fetch top sellers
                // BrowseNodeLookup responseGroup may have many different possible options like : MostGifted NewReleases
                $responseTopSellers = $amazonEcs->responseGroup('TopSellers')->browseNodeLookup($topSeller);

                // Loop to get all top seller ASINs
                $allTopSellerASINs = array();
                foreach ($responseTopSellers->BrowseNodes->BrowseNode->TopItemSet->TopItem as $responseTopSellersItems) {
                    $allTopSellerASINs[] = $responseTopSellersItems->ASIN;
                }

                $allTopSellerASINsStr = implode(",", $allTopSellerASINs);
               

                // CAll for all asins data
                // lookup may have different possible variations like : large, small, Images, OfferSummary and more
                $responseASINs = $amazonEcs->responseGroup('Medium,OfferSummary,VariationSummary')->lookup($allTopSellerASINsStr);

                if (!empty($responseASINs->Items->Item)) {

                  
                   
                    foreach ($responseASINs->Items->Item as $item) {

                        $asin = !empty($item->ASIN) ? $item->ASIN : "";
                        $title = !empty($item->ItemAttributes->Title) ? $item->ItemAttributes->Title : "";
                       
                        // Fetch more relevant data
                       
                        if(is_array($item->ImageSets->ImageSet)){
                           
                            // Fetch images as per your requirement

                        }

                           
                        // Write to top seller CSV
                        if (!empty($features) && !empty($title) && !empty($imageset_1) && ( $list_price !== "N/A" || $offer_price !== "N/A"  )  ) {
                           
                            // Do something with this data
                           
                        }
                       
                    }
                 
                }
           
        }// listing loop

    } catch (Exception $e) {


    }
}





Note: Amazon Product Advertising API has threshold limit over request so avoid quick requests. You may add some delay at your side to make request after some delay.





Thanks for your valuable comments and suggestion.

No comments:

Post a Comment

YouTube TV | Know All About Features, Subscription & Access

YouTube TV is Live | Know All About YouTube TV YouTube TV is finally live and available to Big US cities only. Now you ...