COM WEB SERVICES 678
AMAZON_SEARCH_NODE,
'ResponseGroup' =>
AMAZON_RESPONSE_GROUPS,
'Sort' => 'salesrank'));
// Invoke the method
$result = $client->ItemSearch($request);
return $result;
}
catch (SoapFault $fault)
{
trigger_error('SOAP Fault: (faultcode: ' . $fault->faultcode . ', ' .
'faultstring: ' . $fault->faultstring . ')',
E_USER_ERROR);
}
}
/* Places an "image not available" picture for products with no image,
and saves the results in an array with a simple structure for easier
handling at the upper levels */
private function _DataFormat($result)
{
/* Variable k is the index of the $new_result array, which will
contain the Amazon products to be displayed in TShirtShop */
$k = 0;
$new_result = array ();
/* Analyze all products retrieved from A2S
and save them into the $new_result array */
for ($i = 0; $i < count($result->Items->Item); $i++)
{
// Make a temporary copy for product data
$temp = $result->Items->Item[$i];
/* Set product's image to images/not_available.jpg,
if image url is empty */
if (property_exists($temp, 'MediumImage') &&
((string) $temp->MediumImage->URL) != '')
$new_result[$k]['image'] = (string) $temp->MediumImage->URL;
else
$new_result[$k]['image'] = 'images/not_available.jpg';
// Save asin, brand, name, and price into the $new_result array
$new_result[$k]['asin'] = (string) $temp->ASIN;
$new_result[$k]['brand'] = (string) $temp->ItemAttributes->Brand;
$new_result[$k]['item_name'] = (string) $temp->ItemAttributes->Title;
CHAPTER 22 ?– USING AMAZON.
Pages:
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793