PDF='MAIN' { ATTRIBUTES='*' { PLATFORM='php.txt'; REPTYPE='1'; ATTACHED='0'; PROJECT='36'; OBJECTNAME='soapamazon.php'; LIBLOBJ='*FILES'; TITLE='Amazon Web Service (SOAP)'; WEBPATH='http://esdi.excelsystems.com/webtest/'; TARGETPATH='/www/zendcore/htdocs/examples/'; FTPSITE='examples'; SET='149'; VERSION='4.00'; CRTBNUM='Revision 1576'; CRTTEMPLT='C:\\Program Files\\ESDI\\WebSmart\\Temp\\PHP-Record Listing.tpl'; SAVBNUM='Revision 1811'; LASTLOC='3'; VHTML='N'; LASTSAVE='12/13/2007 10:22:20'; OBJLIBRARY='WEBTEST'; SOURCELIBR='WEBTEST'; SOURCEFILE='QRPGLESRC'; } FTPREFINFO='*' { URL='192.168.0.100'; INITIALDIR='/www/zendcore/htdocs/examples/'; FTPPORT='21'; PASSIVEMODE='1'; WEBPATH='http://esdi.excelsystems.com/webtest/'; } FILES='*' { FILE='MU_CUSTF' { LIBRARY='XL_WEBDEMO'; ALIAS=''; RCDFORMAT='R_CUSTF '; LEVELID='1070921111624'; RFLEVELID='403ABD661EC5A'; EXTDS='0'; } } PANELS='*' { PANEL='ListHeader' { DESC='Page header'; DETAILS=' Example 139: Link to an Amazon.com Web Service Using SOAP (PHP)

Example 139: Link to an Amazon.com Web Service Using SOAP (PHP)

Description: This WebSmart PHP example uses Amazon\'s AWI APIs to retrieve book information.
For more information about Amazon\'s APIs please visit www.Amazon.com.

Search for author/book:  
Search displays first 10 items.

'; } PANEL='ListDetails' { DESC='Page body'; ITERATIONS='10'; DETAILS=' '; } PANEL='ListFooter' { DESC='Page footer'; DETAILS='
$prodName
Authors:

List Price: $prodListPrice
Used Price: $prodUsedPrice
book cover
 
  1. Start with a "PHP Record Listing" template.


  2. In the program\'s ListHeader HTML segment, find the line
    <div id="contents">
    and add the following HTML code immediately afterwards:
         <form name="srchform" action="" method="POST">
            <input type="hidden" name="task" value="search">
            <table>
              <tr>
                <td>Search for author/book:</td>            
                <td> </td>
                <td><input type="text" name="book" value=""></td>
                <td><input type="Submit" value="Search"></td>
              </tr>
              <tr>
              	<td colspan="4" align="center"><b>Search displays first 10 items.</b></td>
              </tr>
             </table> 
            </form>
            <br>
            <table border="1">        
        
  3. Replace the HTML code on the \'ListDetails\' segment with the following:
    	<tr>
    	  <td class="text" width="300">
    	    <a href="\\$prodURL">\\$prodName</a>    
    	    <br>
    	    <strong>Authors:</strong> <?php echo(implode(", ", \\$prodAuthors)); ?>
    	    <br><br>
    	    <strong>List Price: $prodListPrice</strong>
    	    <br>
    	    <span style="color: red;">Used Price: \\$prodUsedPrice</span>    
    	  </td>
    	  <td class="text" valign="middle" align="center">  	
    	    <img border="1" src="\\$prodImgURLsm" border="0" alt="book cover">
    	  </td>
    	</tr>
    	<tr>
    	  <td colspan="2"> </td>
    	</tr>
        
  4. Replace the PHP source code with the following:
    // Global variables
    global \\$prodName;
    global \\$prodURL;
    global \\$prodImgURLsm;
    global \\$prodImgURLlg;
    global \\$prodListPrice;
    global \\$prodUsedPrice;
    global \\$prodAuthors;
    
    
    
    // Do the task
    \\$pf_task = strtolower(\\$pf_task);
    switch(\\$pf_task)
    {
    	case \'default\':
    	mySOAPClient();
    	break;
    	
    	case \'search\':
    	mySOAPClient();
    	break;
    }
    
    // Implement a simple SOAP client to connect to Amazon.com 
    function mySOAPClient()
    {
    	// Retrieve global variables
    	foreach(\\$GLOBALS as \\$arraykey=>\\$arrayvalue) 
    	{
    		if (\\$arraykey[0]!=\'_\' && \\$arraykey != "GLOBALS")
    			global \\$\\$arraykey;
    	}
    	
    	// Retrieve search parameter
    	if (isset(\\$_REQUEST[\'book\']))
    		\\$keyword = \\$_REQUEST[\'book\'];
    	else 
    		\\$keyword = \'\';
    	
    	
    	if(\\$keyword == \'\')
    	{
    		wrtseg(\'ListHeader\');
    		wrtseg(\'ListFooter\');
    		return;	
    	}
    	else
    	{
    		// Create SoapClient objects in WSDL mode.
    		\\$client = 
    		new SoapClient("http://soap.amazon.com/schemas2/AmazonWebServices.wsdl");
    		\\$params = array(
    		\'keyword\'    => \\$keyword,
    		\'page\'       => 1,
    		\'mode\'       => \'books\',
    		\'tag\'        => \'preinheimerco-20\',
    		\'type\'       => \'lite\',
    		\'devtag\'     => \'1MV0BNXEHBAQ0BJTBQR2\'
    		);
    		
    		wrtseg(\'ListHeader\');
    		
    		// Utilize Amazon\'s AWS API method calls to retrieve the information
    		// For more information refer to http://www.amazon.com/webservices
    		// Here is a brief list:
    		// BrowseNodeSearchRequest() - retrieve a list of catalog items attached
    		//                             to a particular node in the Amazon database;
    		// ASINSearchRequest()       - retrieve detailed information for a given 
    		//                             product code;
    		// KeywordSearchRequest()    - perform a keyword search on the Amazon database;
    		// SellerSearchRequest()     - perform a search for products listed by 
    		//                             third-party sellers;
    		// PowerSearchRequest()      - perform an advanced search on the Amazon 
    		//                             database;
    		// SimilaritySearchRequest() - perform a search for similar items, given a  
    		//                             specific product code.
    		
    		try{
    			
    			\\$result = \\$client->KeywordSearchRequest(\\$params);
    		}
    		catch(Exception \\$e)
    		{
    			echo(\'Message: \' . \\$e->getMessage());
    			exit;	
    		}
    		
    		// The resulting array will contain the following elements:		
    		//
    		// [Url]
    		// [Asin]
    		// [ProductName]
    		// [Catalog]
    		// [Authors]
    		// [ReleaseDate]
    		// [Manufacturer]
    		// [ImageUrlSmall]
    		// [ImageUrlMedium]
    		// [ImageUrlLarge]
    		// [ListPrice]
    		// [UsedPrice]
    		// [Availability]
    		//
    		foreach (\\$result->Details as \\$product)
    		{
    			\\$prodName = \\$product->ProductName;
    			\\$prodURL = \\$product->Url;
    			\\$prodImgURLsm = \\$product->ImageUrlSmall;
    			\\$prodImgURLlg = \\$product->ImageUrlLarge;
    			\\$prodListPrice = \\$product->ListPrice;
    			\\$prodUsedPrice = \\$product->UsedPrice;
    			\\$prodAuthors = \\$product->Authors;			
    			
    			wrtseg(\'ListDetails\');
    		} 
    		wrtseg(\'ListFooter\');
    	}
    }
    --------------------------------------------------------------------------------
    Notice the bolded text above. You will have to create a key for your own development purposes.
    Please visit \'http://www.amazon.com/webservices\' for more information.	
    	
  5. Compile and run your program.

Program Definition:   soapamazon.pdw

Rate This Example

Did this knowledge base article help you to achieve your goal?  Yes  No  Don\'t Know

Enter additional comments below.   If you want to hear back from us, include your contact information.

'; } } PREVIEWS='*' { PREVIEW='Main List' { SEG='ListHeader'; SEG='ListDetails' { REPEAT='10'; } SEG='ListFooter'; } } ACTIONS=' // Program Name: test.php // Program Title: test // Created by: oscarg // Template family: Idaho // Template name: List All Records in File // Purpose: // Program Modifications: // DB Connection code require(\'/esdi/websmart/v6.6/include/xl_functions001.php\'); $options = array(\'i5_naming\' => DB2_I5_NAMING_ON); global $db2conn; $db2conn = xl_db2_connect($options); if(!$db2conn) { die(\'Failed to connect to database!\'); } // Global variables global $wsnum; global $prodName; global $prodURL; global $prodImgURLsm; global $prodImgURLlg; global $prodListPrice; global $prodUsedPrice; global $prodAuthors; // This code is for the Rate this page section if (isset($_REQUEST[\'wsnum\'])) { $wsnum = $_REQUEST[\'wsnum\']; } // Check the cookie if(isset($_COOKIE[\'wsnumbc\'])) { $wsnum = $_COOKIE[\'wsnumbc\']; } else { setcookie(\'wsnumbc\', $wsnum); } // As a default task for this program, execute the display function $pf_task = strtolower($pf_task); switch($pf_task) { case \'default\': mySOAPClient(); break; case \'search\': mySOAPClient(); break; } /******************** End of mainline code ********************/ function display() { // Make all global variables available here foreach($GLOBALS as $arraykey=>$arrayvalue) { global $$arraykey; } $query = "select CMCUST from XL_WEBDEMO/MU_CUSTF"; // Fetch rows for page: relative to initial cursor if (!($stmt = db2_exec($db2conn, $query))) { echo "Error ".db2_stmt_error() .":".db2_stmt_errormsg(). ""; die; } // Output header wrtseg("ListHeader"); while ($row = db2_fetch_assoc($stmt)) { // set color of the line xl_set_row_color(\'altcol1\', \'altcol2\'); $CMCUST = $row["CMCUST"]; wrtseg("ListDetails"); } // closet the database connection db2_close($db2conn); wrtseg("ListFooter"); } // Implement a simple SOAP client to connect to Amazon.com function mySOAPClient() { // Retrieve global variables foreach($GLOBALS as $arraykey=>$arrayvalue) { if ($arraykey[0]!=\'_\' && $arraykey != "GLOBALS") global $$arraykey; } // Retrieve search parameter if (isset($_REQUEST[\'book\'])) $keyword = $_REQUEST[\'book\']; else $keyword = NULL; if(is_null($keyword)) { wrtseg(\'ListHeader\'); wrtseg(\'ListFooter\'); return; } else { // Create SoapClient objects in WSDL mode. $client = new SoapClient("http://soap.amazon.com/schemas2/AmazonWebServices.wsdl"); $params = array( \'keyword\' => $keyword, \'page\' => 1, \'mode\' => \'books\', \'tag\' => \'preinheimerco-20\', \'type\' => \'lite\', \'devtag\' => \'1MV0BNXEHBAQ0BJTBQR2\' ); wrtseg(\'ListHeader\'); // Utilize Amazon\'s AWS API method calls to retrieve the information // For more information refer to http://www.amazon.com/webservices // Here is a brief list: // BrowseNodeSearchRequest() - retrieve a list of catalog items attached // to a particular node in the Amazon database; // ASINSearchRequest() - retrieve detailed information for a given product code; // KeywordSearchRequest() - perform a keyword search on the Amazon database; // SellerSearchRequest() - perform a search for products listed by third-party sellers; // PowerSearchRequest() - perform an advanced search on the Amazon database; // SimilaritySearchRequest() - perform a search for similar items, given a specific // product code. try{ $result = $client->KeywordSearchRequest($params); } catch(Exception $e) { echo(\'Message: \' . $e->getMessage()); exit; } // The resulting array will contain the following elements: // // [Url] // [Asin] // [ProductName] // [Catalog] // [Authors] // [ReleaseDate] // [Manufacturer] // [ImageUrlSmall] // [ImageUrlMedium] // [ImageUrlLarge] // [ListPrice] // [UsedPrice] // [Availability] // foreach ($result->Details as $product) { $prodName = $product->ProductName; $prodURL = $product->Url; $prodImgURLsm = $product->ImageUrlSmall; $prodImgURLlg = $product->ImageUrlLarge; $prodListPrice = $product->ListPrice; $prodUsedPrice = $product->UsedPrice; if(array_key_exists("Authors", $product)) { $prodAuthors = $product->Authors; } else { $prodAuthors = array(\'Authors\' => null); } wrtseg(\'ListDetails\'); } wrtseg(\'ListFooter\'); } } '; }