!!! Listings zum Artikel "Jagd nach dem Schnäppchen"
!!! von Andreas Oesterhelt und Jan Seidler
!!! in iX 4/2008, S. 72
!!! Listing 1: Konfigurationsdaten
app-key-prod =
cert-id-prod =
site-id = 77 ; eBay.de
app-mode = 0 ; 1 => sandbox, 0 => production
[ebay-transaction-config]
use-http-compression = 1
*/
?>
!!! Listing 2: PHP-Feed (6 Abschnitte)
setParserOption('NO_UNSET_METADATA', true);
$proxy->setParserOption('NO_REDUCE', true);
// Abschnitt 3
$request = new FindItemsAdvancedRequestType();
$request->setQueryKeywords(utf8_decode($_REQUEST['query']));
$request->setEndTimeFrom(date('Y-m-d H:i:s', time() + 120));
$request->setEndTimeTo(date('Y-m-d H:i:s', time() + 86400));
$request->setItemType('AuctionItemsOnly');
$request->setBidCountMax(0);
// Abschnitt 4
$request->setItemSort('EndTime');
$request->setSortOrder('Ascending');
$request->setMaxEntries(5);
$request->setPageNumber(isset($_REQUEST['page']) ? $_REQUEST['page'] : 1);
// Abschnitt 5
$result = $proxy->FindItemsAdvanced($request);
if ($proxy->isGood($result)) {
$result->_elements['CurrentPage'] = array
(
'required' => false,
'type' => 'string',
'nsURI' => 'urn:ebay:apis:eBLBaseComponents',
'array' => false,
'cardinality' => '0..1'
);
$result->CurrentPage = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
// Abschnitt 6
header('Content-Type: text/xml');
echo('');
echo
(
$result->serialize
(
'ebaySearchResults', $result, null, true, null, new
EbatNs_DataConverterIso()
)
);
}
?>
!!! Listing 3: XSLT-Stylesheet
Bild
|
Artikelbezeichnung
|
Preis
|
ungerade
gerade
|
|
|
Zurück
|
Weiter
|
!!! Listing 4
Ebay-Suche per Ajax
Noch keine Ergebnisse.
!!! Listing 5
function findEbayItems(searchString, pageNo) {
var XSLTProc;
var XMLProc;
var haveXML = false;
var haveXSLT = false;
var XMLBuffer;
function fetchXSLTData() {
new Ajax.Request
(
'styles/ebaySearchResults.xsl',
{
onComplete: function(response)
{
handleResponse(response, 'XSLTData');
},
method: 'get',
asynchronous: true
}
);
}
function fetchXMLData() {
new Ajax.Request
(
'feed.php?',
{
onComplete: function(response)
{
handleResponse(response, 'XMLData');
},
method: 'get',
asynchronous: true,
parameters: 'page=' + pageNo + '&query='
+ encodeURIComponent(searchString)
}
);
}
!! Listing 6
function handleResponse(response, type)
{
switch (type)
{
case 'XSLTData':
if (response.status == 200)
{
if
(
document.implementation
&& document.implementation.createDocument
)
{
XSLTProc = new XSLTProcessor();
XSLTProc.importStylesheet(response.responseXML);
}
else if (window.ActiveXObject)
{
XSLTProc = new ActiveXObject('MSXML2.DOMDocument');
XSLTProc.loadXML(response.responseText);
}
haveXSLT = true;
}
break;
case 'XMLData':
if (response.status == 200)
{
if
(
document.implementation
&& document.implementation.createDocument
)
{
XMLBuffer = response.responseXML;
}
else if (window.ActiveXObject)
{
XMLProc = new ActiveXObject('MSXML2.DOMDocument');
XMLProc.loadXML(response.responseText);
}
haveXML = true;
}
break;
}
if (haveXML && haveXSLT)
{
if
(
document.implementation
&& document.implementation.createDocument
)
{
$('ebayItemsContainer').update
(
getOuterHTML
(
XSLTProc.transformToFragment(XMLBuffer, document)
)
);
}
else if (window.ActiveXObject)
{
$('ebayItemsContainer').update
(
XMLProc.transformNode(XSLTProc)
);
}
}
}
!!! Listing 7
var currentSearchString;
var currentPageNo;
if (!pageNo) pageNo = 1;
else if (pageNo == 'previous') pageNo = currentPageNo - 1;
else if (pageNo == 'next') pageNo = currentPageNo + 1;
currentPageNo = pageNo;
if (!searchString) searchString = currentSearchString;
currentSearchString = searchString;
fetchXSLTData();
fetchXMLData();