Items->Item->ItemAttributes->Title)) { return ($response); } else { throw new Exception("Invalid xml response."); } } } /** * Query Amazon with the issued parameters * * @param array $parameters parameters to query around * @return simpleXmlObject xml query response */ private function queryAmazon($parameters) { return aws_signed_request("com", $parameters, $this->public_key, $this->private_key, $this->associate_tag); } /** * Return details of products searched by various types * * @param string $search search term * @param string $category search category * @param string $searchType type of search * @return mixed simpleXML object */ public function searchProducts($search, $category, $searchType = "UPC") { $allowedTypes = array("UPC", "TITLE", "ARTIST", "KEYWORD"); $allowedCategories = array("Music", "DVD", "VideoGames"); switch($searchType) { case "UPC" : $parameters = array("Operation" => "ItemLookup", "ItemId" => $search, "SearchIndex" => $category, "IdType" => "UPC", "ResponseGroup" => "Medium"); break; case "TITLE" : $parameters = array("Operation" => "ItemSearch", "Title" => 'Shirt', "SearchIndex" => 'Apparel', // "ItemPage" => "3", "ResponseGroup" => "Medium"); break; } $xml_response = $this->queryAmazon($parameters); // echo "
";
//            print_r($xml_response);exit;
            
            return $this->verifyXmlResponse($xml_response);

        }
        
        
        /**
         * Return details of a product searched by UPC
         * 
         * @param int $upc_code UPC code of the product to search
         * @param string $product_type type of the product
         * @return mixed simpleXML object
         */
        public function getItemByUpc($upc_code, $product_type)
        {
            $parameters = array("Operation"     => "ItemLookup",
                                "ItemId"        => $upc_code,
                                "SearchIndex"   => $product_type,
                                "IdType"        => "UPC",
                                "ResponseGroup" => "Medium");
                                
            $xml_response = $this->queryAmazon($parameters);
            
            return $this->verifyXmlResponse($xml_response);

        }
        
        
        /**
         * Return details of a product searched by ASIN
         * 
         * @param int $asin_code ASIN code of the product to search
         * @return mixed simpleXML object
         */
        public function getItemByAsin($asin_code)
        {
            $parameters = array("Operation"     => "ItemLookup",
                                "ItemId"        => $asin_code,
                                "ResponseGroup" => "Medium");
                                
            $xml_response = $this->queryAmazon($parameters);
            
            
            return $this->verifyXmlResponse($xml_response);
        }
        
        
        /**
         * Return details of a product searched by keyword
         * 
         * @param string $keyword keyword to search
         * @param string $product_type type of the product
         * @return mixed simpleXML object
         */
        public function getItemByKeyword($keyword, $product_type)
        {
            $parameters = array("Operation"   => "ItemSearch",
                                "Keywords"    => $keyword,
                                "SearchIndex" => $product_type);
                                
            $xml_response = $this->queryAmazon($parameters);
            
            return $this->verifyXmlResponse($xml_response);
        }

    }

?>