Search: Price: low $ high :

[insert_php]
$url = “http://productsearch.linksynergy.com/productsearch”;
$token = “5f9b7dc2b01ad6ff1525a9e1945306c512412b16ecd81c48e88440399c1dc24b”;
$targeturl=”https://product-search.api.cj.com/v2/product-search?”;
$websiteid= “7308179”;
$CJ_DevKey= “00b08328e90aace06537324f30a1c96013fd5d6ea0d414d6a6251b7c380218e0062e5001614a0992167ea425e7591040be6e3246f83813fde7c40006f20a472373/5042d38f63f347f5be2b7a26baea3e6dd87f6b9665d933e1486e3f0598ae86ee86bd683f6436155f03287d005157e44838e831ff410aed1459cb7d81516da0c1″;
$currency=”USD”; $advs=”joined”;

$results = ”;
$resturl = $url.”?”.”token=”.$token;

$public_key = “AKIAJLUS43NIAXAPBCFA”;
$private_key = “IEwT2gnhJsxfm/8z7WKwzP8RbDjymkKYo/3XO64l”;
$method = “GET”;
$host = “ecs.amazonaws.com”;
$uri = “/onca/xml”;
$params[“AWSAccessKeyId”] = $public_key;
$params[“AssociateTag”] = “dtsearch-20″;

$targeturl.=”website-id=$websiteid”;
if (isset($_GET[“keyword”]))
{
$keywords = $_GET[“keyword”];
$keyword = preg_replace(“/[^a-zA-Z0-9]/”, ” “, $keyword);
$keywords = urlencode($keywords);

$resturl .= “&keyword=”.$keywords;
$resturl .= “&sort=retailprice”;
$resturl .= “&sorttype=asc”;

$targeturl.=”&keywords=$keywords”;
$params[“Keywords”] = $keywords;

$params[“Operation”] = “ItemSearch”;

if (isset($_GET[“cat”]))
{
$category = $_GET[“cat”];
$resturl .= “&cat=”.$category;
}

$targeturl.=”&advertiser-ids=$advs”;
$targeturl.=”&currency=$currency”;
if (isset($_GET[“max”]))
{
$maxresults = $_GET[“max”];
$targeturl.=”&records-per-page=”.$maxresults;
$resturl .= “&max=”.$maxresults;
}
else { $resturl .= “&max=”.”50″;
}

if (isset($_GET[“low”]))
{
$low = $_GET[“low”];
$targeturl.=”&low-price=”.$low;
//$params[“MaximumPrice”] = $low;
}

if (isset($_GET[“high”]))
{
$high = $_GET[“high”];
$targeturl.=”&high-price=”.$high;
//$params[“MinimumPrice”] = $high;
}
// end building targeturl

// amazon call
$params[“ResponseGroup”] = “Offers,Medium”;
$params[“SearchIndex”] = “Blended”;
$params[“Service”] = “AWSECommerceService”;
$params[“Timestamp”] = gmdate(“Y-m-d\TH:i:s\Z”);
$params[“ItemPage”] = “1”;
$params[“Version”] = “2011-08-01”;
ksort($params);
$canonicalized_query = array(); // build the canonical query
foreach ($params as $param=>$value)
{
$param = str_replace(“%7E”, “~”, rawurlencode($param));
$value = str_replace(“%7E”, “~”, rawurlencode($value));
$canonicalized_query[] = $param.”=”.$value;
}

$canonicalized_query = implode(“&”, $canonicalized_query);
$string_to_sign = $method.”\n”.$host.”\n”.$uri.”\n”.$canonicalized_query;
$signature = base64_encode(hash_hmac(“sha256”, $string_to_sign, $private_key, True)); // calculate
$signature = str_replace(“%7E”, “~”, rawurlencode($signature));
$request = “http://”.$host.$uri.”?”.$canonicalized_query.”&Signature=”.$signature;
$response = @file_get_contents($request);
$pxml = simplexml_load_string($response);

// Linkshare call
$SafeQuery = urlencode($resturl);
$xml = simplexml_load_file($SafeQuery);

// CJ call
$ch = curl_init($targeturl);
curl_setopt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Authorization: ‘.$CJ_DevKey)); // send development key
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
$xmlcj = new SimpleXMLElement($response);
curl_close($ch);

$alllist = array();

// amazon display
foreach($pxml->Items->Item as $current)
{
if($current->DetailPageURL != “”)
{
$title = mb_strimwidth($current->ItemAttributes->Title, 0, 75, “…”);

$alllist = array(“link”=>$current->DetailPageURL, “title”=>$title, “imgurl”=>$current->MediumImage->URL, “price”=>($current->OfferSummary->LowestNewPrice->Amount)/100, “mname”=>’Amazon’);

$all[] = $alllist;
}
}

//cj display
foreach ($xmlcj->products->product as $itemcj)
{
$link = $itemcj->xpath(‘buy-url’);$link = (string)$link[0];
$title = $itemcj->xpath(‘name’); $title = (string)$title[0];
$title = mb_strimwidth($title, 0, 75, “…”);
$imgURL = $itemcj->xpath(‘image-url’); $imgURL = (string)$imgURL[0];
$price = $itemcj->sale-price;
if($price == “”){
$price = $itemcj->price;
}
$merchantname = $itemcj->xpath(‘advertiser-name’);
$merchantname = (string)$merchantname[0];
$description = $itemcj->xpath(‘description’);
$description = (string)$description[0];

$alllist = array(“link”=>$link, “title”=>$title, “imgurl”=>$imgURL, “price”=>$price, “mname”=>$merchantname, “description”=>$description);

$all[] = $alllist;
}

// Linkshare display
foreach ($xml as $item) {
$alllist = array(“link”=>$item->linkurl, “title”=>mb_strimwidth($item->productname, 0, 75, “…”), “imgurl”=>$item->imageurl, “price”=>$item->saleprice, “mname”=>$item->merchantname, “description”=>$item->description->short);

$all[] = $alllist;
}

if (isset($_GET[“m”]))
{
$filter_value = $_GET[“m”];
$all_filter = array_filter($all, function($item) use($filter_value) {
return $item[‘mname’] === $filter_value;
});
}
else
{
$all_filter = $all;
}

echo ‘

‘;
// display data and filter
foreach ($all_filter as $each)
{
if($each[‘title’] != “”)
{
echo ‘

‘;
echo ““.$each[‘title’].” from “.”“.$each[‘mname’].”
“;
echo ‘'.$each['description'].'‘;echo ” “.
$each[‘price’].”
“;echo ‘

‘;
}}
echo ‘

‘;
}
[/insert_php]

Comments are closed.