Amazon Shopping – Just a Phone Call Away! February 9, 2009
How often you’ve had the need to check an item from an online vendor while shopping in a store? e.g. lets say you were in a bookshop and a novel looks interesting to you. Before purchasing it you want to go over reviews and maybe even want to do a comparative price search and possibly buy it online if it is priced better. In the ever connected world we live in, this isn’t anything new.
Being able to access information when I want it and where I want it is becoming more and more of a necessity than a luxury. Whatever ‘it’ is, the idea is to access all the information about that item at that particular moment.
In this application, we demonstrate how easy it is to use VoicePHP to build a complete voice accessible shopping experience. In particular, the application does the following:
- It allows users to type in an ISBN number. For e.g. (ISBN-10: 0375826726 or ISBN-13: 978-0375826726 for “Breaking Dawn”, ISBN-10: 1416562605 or ISBN-13: 978-1416562603 for “White Tiger”)
- Hear reviews, price and other information
- Provides skeleton code to implement the payment and shipping logic.
So next time you are in a bookstore, feel free to call 15672449576 to get more information on any book. This code can be easily extended to integrate other products offered by Amazonn or a completely different seller.
Disclaimer: Credit card number and shipping information is only being asked for demonstration purposes. We do not store any of that information and will not be sending that to Amazon (as you can see in the code). Please use your judgement when providing that information.
<?php
define('KEYID','*********');
define('AssocTag','******');
echo "Welcome to Voice PHP Demo of Amazon Book Look Up";
setvoiceoption("autospellnumbers",3);
setvoiceoption("interdigittimeout", 3000);
while(1) {
$isbn = prompt ("Please Enter the I S B N code of the book you would like to search. Press star key instead of X",1,30);
$len = strlen($isbn);
if((13 != $len) && (10 != $len)) {
echo "Invalid I S B N number";
continue;
}
elseif($len==10) {
$isbn = str_replace('*','x',$isbn);
}
break;
}
//Create request to amazon to search for book
$request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=ItemSearch&ResponseGroup=Medium,Offers&SearchIndex=Books&Keywords=".$isbn."&ItemPage=1";
$response = Fetch($request);
$parsed_xml = simplexml_load_string($response);
$numOfItems = $parsed_xml->Items->TotalResults;
$totalPages = $parsed_xml->Items->TotalPages;
if($numOfItems<0){
echo "No matches found for I S B N $isbn";
echo "Thank you for trying Voice PHP Demo";
return;
}
foreach($parsed_xml->Items->Item as $current) {
$offerlist = $current->Offers->Offer->OfferListing;
$content = $current->EditorialReviews->EditorialReview->Content;
if(isset($offerlist->OfferListingId)){
echo "Book Title : " . $current->ItemAttributes->Title;
}
if(isset($current->ItemAttributes->Author)) {
print("Author : ".$current->ItemAttributes->Author);
}
print("Amazon Offer Price: ".$offerlist->Price->FormattedPrice);
$content = strip_tags($content);
$len = strlen($content);
$read = prompt("Press 1 to hear the review or 2 to add to cart",1,5,"dtmf:1");
for($i=0;$i<$len && $read=="1";$i+=200) {
$review = substr($content,$i,200);
prompt($review, 1);
if($i==0) {
$read = prompt("Press 1 to hear more or 2 to add to cart",1,2,"dtmf:1");
}
}
if($read == "2") {
$cartId = add_cart($offerlist->OfferListingId);
}
}
if($cartId) {
$card = prompt("Enter your credit card number now",1,20);
//Perform the Credit Card check or Subscription processing etc...
echo "Credit card number entered is $card";
echo "Speak your postal address now, press hash when done.";
$address = record('#',5, 60);
echo "Your address has been recorded for shipping";
//Perform the shipping process...
}
echo "Thank you for trying out Voice PHP demo.";
function add_cart($offerListingId) {
$request="http://code.voicephp.com/samples/create_cart.php?Id=$offerListingId";
$response = Fetch($request);
if(empty($response)) {
echo "Could not add to cart";
return 0;
}
echo "Book added to cart";
$res = explode(' ',$response);
$cartId = $res[0];
return $cartId;
}
?>
Try It Now!
Click the button below or call +15672449576 to run the application.
Does'nt it look easy? Try VoicePHP for yourself and feel free to modify the above script. VoicePHP is easy and accessible from your free TringMe account. More details at http://voicephp.com/howitworks.html
Leave a Comment
If you would like to make a comment, please fill out the form below.





