Simple Example Of Shopping.Com Api For Drupal And A Related Product Search
This is a simple example of how to use the Shopping.com API on a Drupal page. There is a more and better version coming. But if you can't wait, here you go! I put this on an PHP enabled page: http://www.churchofeee.com/product_search, rather than spring for .NET product that costs $250 (why-- I couldn't use it on a PHP site, and why not spend the time DIY coding it)?
<form action="product_search">
<input type="text" name="search" value="<? echo htmlentities($_GET['search']); ?>"/>
<input type="submit" value="Search"/>
</form>
<?
$search_items = urlencode($_GET['search']);
// $search_items = 'eee';
$items = simplexml_load_file('http://api.shopping.com/dsp/linkin_id-8005272/keyword-'.$search_items);
if (($items) && (strlen($search_items) > 1)) {
print "<pre>\n";
foreach ($items->result->domain->{domain-listing} as $item) {
print l($item->title, $item->url)."<br/>";
}
print '</pre>';
}
else {
?>
Search for products-- computers, eee pcs, sub-notebooks, and all that great stuff!
<?
}
?>
And this is how to do a related product search:
Here is a block is a nice concise chunk of functionality that doesn't pack on the weight or limitations that come with a whole module.
<?
$tids = explode(',',arg(2));
foreach ($tids as $tid) {
$term_info = taxonomy_get_term($tid);
$search_items = urlencode($term_info->name);
$items = simplexml_load_file('http://publisher.api.shopping.com/publisher/3.0/rest/GeneralSearch?identity.apiKey=[API KEY]&tr.trackingId=[LINKIN ID]&nf.keyword='.$search_items);
if (($items) && (strlen($search_items) > 1)) {
foreach ($items->categories->category->items->offer as $item) {
print '<div style="float: left; width: 120px; padding: 10px; overflow: auto; display: block;">';
print '<a href="'.$item->offerURL.'"><img src="'.$item->imageList->image[0]->sourceURL.'" width="100"></a>';
print "<br/>".l($item->name, $item->offerURL, array(), NULL, NULL, TRUE);
print '</div>';
}
}
}
?>
Here is an example it in action (scroll to the bottom).
About the Author:
Article Source: ArticlesBase.com - Simple Example Of Shopping.Com Api For Drupal And A Related Product Search