view xml/amazonBookSearch.php @ 44:38d209611508

change includes to assume (contra previos ASSUMES) that we have .user.ini which adds /var/test to include_path
author Charlie Root
date Sun, 06 Jan 2019 07:17:03 -0500
parents dbc006408d2b
children da133c130c1d
line wrap: on
line source

<?php

include_once "ywww/dlog.php";

include_once "doAmazonRequest.php";

$Adefault=array(
  'language'           =>'en',           //what language to render the page in
  'locale'             =>'us',           //which server's products? available: ca,de,fr,jp,uk,us
  'page'               =>1,              //first page to show (we are counting from 1 not 0)
  'operation'          =>'ItemSearch',   //what to do?	//ItemSearch
  'searchindex'        =>'Books',        //what product category for search?
  'searchparameter'    =>'Keywords',       //what kind of search?
  'searchparameterdata'=>'Machiavelli',  //what to search for?
  //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true'
  'show_url'           =>false,          //debug: show XML request url to be send to Amazon?
);

//for all parameters see if the user has overruled it or use the default
foreach ($Adefault as $i=>$d) {
  $$i=isset($_GET[$i])?$_GET[$i]:$d;
}
//this is the data that is used to form the request for AWS
//this is the part that is search specific

  $parameters=array(
    'Operation'       =>$operation              ,
    //'Keywords'        =>urlencode($search)      ,
    'SearchIndex'     =>$searchindex            ,  //Books for example.
    "$searchparameter"=>stripslashes($searchparameterdata),
    'ItemPage'        =>$page                   ,  //which page?
    'AssociateTag'    =>$Aassociates_id[$locale],
	'MerchantId'	  =>'All',
	'Availability'	  =>'Available',
	'Condition'		  =>'All',
    'ResponseGroup'   =>'Images,ItemAttributes'                ,  //Small, Medium, Large or SellerListing
  );


try {
  $ret=doAmazonRequest($Aserver[$locale]['ext'],$parameters,3,'s',False);
}
catch (Exception $e) {
  if ($e->getMessage()=='AWS.ECommerceService.NoExactMatches') {
    // Seems to be an 'OK' thing...
    $ret='<?xml version="1.0" ?><ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"><OperationRequest><RequestId>0e41c74c-eeff-4f24-a761-9537cfebea21</RequestId></OperationRequest><Items><Request><IsValid>True</IsValid></Request><TotalResults>0</TotalResults><TotalPages>0</TotalPages></Items></ItemSearchResponse>';
  }
  else {
    $ret='<?xml version="1.0" ?><ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"><OperationRequest><RequestId>0e41c74c-eeff-4f24-a761-9537cfebea21</RequestId></OperationRequest><Items><Request><IsValid>True</IsValid><Errors><Error><Code>'.$code.'</Code><Message>[lost]</Message></Error></Errors></Request><TotalResults>0</TotalResults><TotalPages>0</TotalPages></Items></ItemSearchResponse>';
  }
}
echo $ret;