Rev 137 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
include_once ('php/constants.php');
error_reporting(E_ALL);
// Get impact listings
function get_impact($query, $searchCondition) {
return []; // BUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUG
$vendors = Vendors::getInstance();
$config = $vendors->getVendor(Vendors::IMPACT);
$arr = [];
foreach ($config["accountSid"] as $key => $advertiser) {
$arrTemp = get_impactAdvertiser($config, $query, $searchCondition, $key);
$arr = array_merge($arr, $arrTemp);
}
return ($arr);
}
// Get linkshare listings by advertiser id
function get_impactAdvertiser($config, $query, $searchCondition, $advertiserName) {
// API request variables
$numResults = $config['numResults'];
$url = '[cached]';
//https://IRAXNu7Vjzc21914055r6UgVUrZSGH6Ne1:PtbZSaqgdZb3don5erDSPRzy._amwxzU@api.impact.com/Mediapartners/IRAXNu7Vjzc21914055r6UgVUrZSGH6Ne1/Catalogs/ItemSearch?Query=Category=%27Music%27%20AND%20Name=%27Elvis%20Presley%27&SortBy=CurrentPrice&SortOrder=ASC'
$result = getSearchCache($advertiserName, $query, $searchCondition);
if ($result === false) {
$params = [];
$params["Query"] = "Category='Music' AND Name='" . $query . "'";
$params["Query"] = "Name='" . $query . "'";
$params["SortBy"] = "CurrentPrice";
$params["SortOrder"] = "ASC";
$pairs = array();
foreach ($params as $key => $value) {
array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
}
$canonical_query_string = join("&", $pairs);
$url = "https://" . $config["accountSid"][$advertiserName] . ":" . $config["authToken"][$advertiserName] . "@api.impact.com/Mediapartners/" . $config["accountSid"][$advertiserName] . "/Catalogs/ItemSearch?" . $canonical_query_string;
$result = getUrl($url);
saveSearchCache($advertiserName, $query, $searchCondition, $result);
}
$result = utf8_encode($result);
$result = simplexml_load_string($result);
//echo "$url<br><pre>";print_r($result);echo "</pre>";
$arr = [];
// Check to see if the request found any results
if (!empty($result->Items->Item)) {
// If the response was loaded, parse it and store in array
foreach ($result->Items->Item as $item) {
$merchantName = (string)$item->CampaignName;
$barcode = "";
$barcodeType = clsLibGTIN::GTINCheck($barcode, false, 1);
$title = (string)$item->Name;
$pic = str_replace('http://', 'https://', (string)$item->ImageUrl);
if (empty($pic)) {
continue;
}
$url = str_replace('http://', 'https://', (string)$item->Url);
if (empty($url)) {
continue;
}
$country = 'US';
// bugbug
$condition = 'Used';
$detailCondition = "Used";
$mediaType = "CD";
$freeShippingCap = 0.00;
$handlingTime = -1;
$shippingEstimated = true;
$shippingCost = 0.00;
$shippingCurrency = 'USD';
$bestOffer = false;
$price = 0;
if (!empty($item->CurrentPrice) && !empty($item->OriginalPrice)) {
$price = minNotNull(array(
$item->CurrentPrice,
$item->OriginalPrice
));
}
else if (!empty($item->CurrentPrice)) {
$price = $item->CurrentPrice;
}
else if (!empty($item->OriginalPrice)) {
$price = $item->OriginalPrice;
}
$price = number_format(floatval($price) , 2, '.', '');
if ($price <= "0.00") {
continue;
}
$currency = (string)$item->Currency;
$timeLeft = 0;
$listingType = 'Fixed';
$location = 'US';
$zip = '';
$feedbackScore = - 1;
$feedbackPercent = - 1;
$sellerName = '';
$arr[] = array(
"Merchant" => $merchantName,
"Condition" => $condition,
"Title" => $title,
"Barcode" => $barcode,
"BarcodeType" => $barcodeType,
"Image" => $pic,
"URL" => $url,
"MediaType" => $mediaType,
"DetailCondition" => $detailCondition,
"Country" => $country,
"BestOffer" => $bestOffer,
"TimeLeft" => $timeLeft,
"Price" => $price,
"Currency" => $currency,
"ListingType" => $listingType,
"Location" => $location,
"Zip" => $zip,
"FeedbackScore" => $feedbackScore,
"FeedbackPercent" => $feedbackPercent,
"SellerName" => $sellerName,
"HandlingTime" => $handlingTime,
"ShippingCost" => $shippingCost,
"ShippingEstimated" => $shippingEstimated,
"ShippingCurrency" => $shippingCurrency,
"FreeShippingCap" => $freeShippingCap,
"Show" => true,
"Details" => ""
);
}
}
// If the response does not indicate 'Success,' log the error(s)
else {
echo "Empty Return:<br><pre>";print_r($result);echo "</pre>"; // bugbug
/*
if (!empty($result->Errors)) {
foreach ($result->Errors as $error) {
if ($error->ErrorID != "7186919") { // no product found, not an error
my_error_log($url);
my_error_log("$error->ErrorText ($error->ErrorId)");
}
}
} else {
my_error_log($url);
my_error_log("No result or error message.");
}
*/
}
return $arr;
}