Skip to content

Instantly share code, notes, and snippets.

@Exeu
Last active June 20, 2017 16:15
Show Gist options
  • Save Exeu/4674423 to your computer and use it in GitHub Desktop.
Save Exeu/4674423 to your computer and use it in GitHub Desktop.
Amazon ECS Sample Page: http://amazonecs.pixel-web.org
$(document).ready(function() {
var globalRequest = 0;
$('#search').bind('keyup', function(event) {
if (event.keyCode == 13) {
searchAction();
}
});
$('#search-link').bind('click', function(event) {
searchAction();
});
var searchAction = function() {
var value = $('#search').val();
var cat = $('#category').val();
var country = $('#country').val();
var page = $('#page').val();
var track = value + " - " + cat + " - " + country;
var resultContainer = $('#results');
if (value.length < 3 && globalRequest == 1) {
return;
}
//_gaq.push(['_trackEvent', 'Search', track]);
globalRequest = 1;
$.ajax({
url: "search.php",
dataType: 'json',
type: 'GET',
data: "q="+value+"&category="+cat+"&country="+country+"&page="+page,
success: function(data){
globalRequest = 0;
resultContainer.fadeOut('fast', function() {
resultContainer.html('');
for (var x in data) {
if (!data[x].price)
data[x].price = 'kA';
if (!data[x].img)
data[x].img = 'assets/images/no.gif';
var html = '<div class="res-container">';
html += '<h2><a href="'+data[x].url+'" target="_blank">'+data[x].Title+'</a></h2>';
html += '<img src="'+data[x].img+'">';
html += '<h3>Price: '+data[x].price+'</h3>';
html += '</div>';
resultContainer.append(html);
}
resultContainer.fadeIn('fast');
});
}
});
};
});
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Amazon ECS Demo - Product Search</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/ama_functions.js"></script>
<style>
body {
font-family: Arial, Tahoma, Verdana;
padding: 0px;
margin: 0px;
}
.res-container {
width: 165px;
height: 350px;
border: 1px solid #cfcfcf;
padding: 10px;
text-align: center;
float: left;
margin-left: 10px;
margin-top: 10px;
}
.res-container h2 {
padding: 0px;
margin: 0 0 10px 0;
height: 115px;
}
.res-container h2 a {
color: #000;
}
#search-bar {
width: 100%;
background: #d3d3d3;
border-bottom: 1px solid #000;
margin-bottom: 30px;
height: 70px;
}
#search-bar input, select {
width: 300px;
font-size: 15px;
font-weight: bold;
border: 0px dashed #000;
padding: 10px;
}
#search-bar select {
width: 100px !important;
}
#page {
width: 20px !important;
}
#results, #search-bar {
padding-top: 20px;
padding-left: 30px;
}
#search-link {
font-size: 25px;
font-weight: bold;
margin-left: 10px;
}
span.caption {
margin-left: 30px;
font-size: 15px;
font-weight: bold;
}
</style>
</head>
<body>
<div id="search-bar">
<span class="caption" style="margin-left: 2px !important">Search:</span>
<input type="text" name="search" id="search">
<span class="caption">Category:</span>
<select name="category" id="category">
<option value="Blended">ALL</option>
<option value="Books">Books</option>
<option value="DVD">DVD</option>
<option value="Apparel">Apparel</option>
<option value="Automotive">Automotive</option>
<option value="Electronics">Electronics</option>
<option value="GourmetFood">GourmetFood</option>
<option value="Kitchen">Kitchen</option>
<option value="Music">Music</option>
<option value="PCHardware">PCHardware</option>
<option value="PetSupplies">PetSupplies</option>
<option value="Software">Software</option>
<option value="SoftwareVideoGames">SoftwareVideoGames</option>
<option value="SportingGoods">SportingGoods</option>
<option value="Tools">Tools</option>
<option value="Toys">Toys</option>
<option value="VHS">VHS</option>
<option value="VideoGames">VideoGames</option>
</select>
<span class="caption">Country:</span>
<select name="country" id="country">
<option value="de">DE</option>
<option value="com">USA</option>
<option value="co.uk">ENG</option>
<option value="ca">CA</option>
<option value="fr">FR</option>
<option value="co.jp">JP</option>
<option value="it">IT</option>
<option value="cn">CN</option>
<option value="es">ES</option>
</select>
<span class="caption">Browse page:</span>
<input type="text" name="page" id="page" value="1">
<a href="#" id="search-link">Search</a>
</div>
<div id="results"></div>
</body>
</html>
<?php
require_once "include/sampleSettings.php";
require_once "vendor/lib/AmazonECS.class.php";
$amazonEcs = new AmazonECS(AWS_API_KEY, AWS_API_SECRET_KEY, 'DE', AWS_ASSOCIATE_TAG);
$amazonEcs->category($_GET['category']);
$amazonEcs->responseGroup('Large');
$amazonEcs->returnType(AmazonECS::RETURN_TYPE_ARRAY);
$amazonEcs->country($_GET['country']);
$page = (!empty($_GET['page'])) ? (int) $_GET['page'] : 1;
if ($page === 0)
$page = 1;
$output = array();
$amazonEcs->page($page);
$response_final = $amazonEcs->search($_GET['q']);
foreach ($response_final['Items']['Item'] as $singleItem)
{
$data = array();
$title = $singleItem['ItemAttributes']['Title'];
if (mb_strlen($title) > 30)
{
$title = substr($title,0, 30);
}
$data['Title'] = $title;
$data['url'] = $singleItem['DetailPageURL'];
$data['img'] = $singleItem['MediumImage']['URL'];
$data['price'] = $singleItem['ItemAttributes']['ListPrice']['FormattedPrice'];
$output[] = $data;
}
echo json_encode($output);
@Karthick-Sugumar
Copy link

Is it possible to do advance search filters?
Like searching Dress-> mens wear -> t shirts -> size, brand, color etc...

@raj-IV
Copy link

raj-IV commented Nov 18, 2014

This is really a nice code to use. Can anybody please tell me from where i can pick the
AWS_API_KEY, AWS_API_SECRET_KEY and AWS_ASSOCIATE_TAG.

Thank You

@rupeshgandhi
Copy link

@Exeu thanks for sharing this tutorial but bro i am facing an error.your given code it does not work. so please if it possible to u send me the whole code on my email id.

@vikky401
Copy link

vikky401 commented Apr 7, 2015

Thanks this code is working perfectly but displaying only ten pages how can i display more please give me solution

@mathesh
Copy link

mathesh commented Feb 24, 2016

It's Working Good.

@sekhar15
Copy link

sekhar15 commented May 12, 2016

Its working properly. But i need number of customer reviews like 238 reviews, but i not get that particular number please help me solution. I get the customer reviews link but not getting that particular number

@zeeshanjamil786
Copy link

this code not run on wamp server.
when i click on search button not show anything.
i run this code on local wamp server.
please help

@zeeshanjamil786
Copy link

exeu please help i request you

@zeeshanjamil786
Copy link

Please reply
i request you.
Associate_tag necessary required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment