Subversion Repositories cheapmusic

Rev

Rev 137 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
84 - 1
<?php
2
include_once ('php/constants.php');
3
 
4
error_reporting(E_ALL);
5
// Get impact listings
6
function get_impact($query, $searchCondition) {
7
 
8
 
9
 
10
return []; // BUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUG
11
 
12
 
13
 
14
    $vendors = Vendors::getInstance();
15
    $config = $vendors->getVendor(Vendors::IMPACT);
16
 
17
    $arr = [];
18
    foreach ($config["accountSid"] as $key => $advertiser) {
19
        $arrTemp = get_impactAdvertiser($config, $query, $searchCondition, $key);
20
        $arr = array_merge($arr, $arrTemp);
21
    }
22
 
23
    return ($arr);
24
}
25
 
26
// Get linkshare listings by advertiser id
27
function get_impactAdvertiser($config, $query, $searchCondition, $advertiserName) {
28
    // API request variables
29
    $numResults = $config['numResults'];
137 - 30
    $url = '[cached]';
84 - 31
 
32
//https://IRAXNu7Vjzc21914055r6UgVUrZSGH6Ne1:PtbZSaqgdZb3don5erDSPRzy._amwxzU@api.impact.com/Mediapartners/IRAXNu7Vjzc21914055r6UgVUrZSGH6Ne1/Catalogs/ItemSearch?Query=Category=%27Music%27%20AND%20Name=%27Elvis%20Presley%27&SortBy=CurrentPrice&SortOrder=ASC'
33
 
99 - 34
    $result = getSearchCache($advertiserName, $query, $searchCondition);
35
    if ($result === false) {
36
        $params = [];
37
        $params["Query"] = "Category='Music' AND Name='" . $query . "'";
38
        $params["Query"] = "Name='" . $query . "'";
39
        $params["SortBy"] = "CurrentPrice";
40
        $params["SortOrder"] = "ASC";
84 - 41
 
99 - 42
        $pairs = array();
43
        foreach ($params as $key => $value) {
44
            array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
45
        }
46
        $canonical_query_string = join("&", $pairs);
84 - 47
 
99 - 48
        $url = "https://" . $config["accountSid"][$advertiserName] . ":" . $config["authToken"][$advertiserName] . "@api.impact.com/Mediapartners/" . $config["accountSid"][$advertiserName] . "/Catalogs/ItemSearch?" . $canonical_query_string;
84 - 49
 
99 - 50
        $result = getUrl($url);
84 - 51
 
99 - 52
        saveSearchCache($advertiserName, $query, $searchCondition, $result);
53
    }
54
 
84 - 55
    $result = utf8_encode($result);
56
    $result = simplexml_load_string($result);
57
 
58
    //echo "$url<br><pre>";print_r($result);echo "</pre>";
59
    $arr = [];
60
 
61
 
62
    // Check to see if the request found any results
63
    if (!empty($result->Items->Item)) {
64
        // If the response was loaded, parse it and store in array
65
        foreach ($result->Items->Item as $item) {
66
            $merchantName = (string)$item->CampaignName;
67
            $barcode = "";
68
            $barcodeType = clsLibGTIN::GTINCheck($barcode, false, 1);
69
 
70
            $title = (string)$item->Name;
71
            $pic = str_replace('http://', 'https://', (string)$item->ImageUrl);
72
            if (empty($pic)) {
73
                continue;
74
            }
75
            $url = str_replace('http://', 'https://', (string)$item->Url);
76
            if (empty($url)) {
77
                continue;
78
            }
79
 
80
            $country = 'US';
81
 
82
// bugbug
83
            $condition = 'Used';
84
            $detailCondition = "Used";
85
            $mediaType = "CD";
86
            $freeShippingCap = 0.00;
87
            $handlingTime = -1;
88
            $shippingEstimated = true;
89
            $shippingCost = 0.00;
90
            $shippingCurrency = 'USD';
91
 
92
            $bestOffer = false;
93
 
94
            $price = 0;
95
            if (!empty($item->CurrentPrice) && !empty($item->OriginalPrice)) {
96
                $price = minNotNull(array(
97
                    $item->CurrentPrice,
98
                    $item->OriginalPrice
99
                ));
100
            }
101
            else if (!empty($item->CurrentPrice)) {
102
                $price = $item->CurrentPrice;
103
            }
104
            else if (!empty($item->OriginalPrice)) {
105
                $price = $item->OriginalPrice;
106
            }
107
            $price = number_format(floatval($price) , 2, '.', '');
108
            if ($price <= "0.00") {
109
                continue;
110
            }
111
 
112
            $currency = (string)$item->Currency;
113
            $timeLeft = 0;
114
            $listingType = 'Fixed';
115
            $location = 'US';
116
            $zip = '';
117
            $feedbackScore = - 1;
118
            $feedbackPercent = - 1;
119
            $sellerName = '';
120
 
121
            $arr[] = array(
122
                "Merchant" => $merchantName,
123
                "Condition" => $condition,
124
                "Title" => $title,
125
                "Barcode" => $barcode,
126
                "BarcodeType" => $barcodeType,
127
                "Image" => $pic,
128
                "URL" => $url,
129
                "MediaType" => $mediaType,
130
                "DetailCondition" => $detailCondition,
131
                "Country" => $country,
132
                "BestOffer" => $bestOffer,
133
                "TimeLeft" => $timeLeft,
134
                "Price" => $price,
135
                "Currency" => $currency,
136
                "ListingType" => $listingType,
137
                "Location" => $location,
138
                "Zip" => $zip,
139
                "FeedbackScore" => $feedbackScore,
140
                "FeedbackPercent" => $feedbackPercent,
141
                "SellerName" => $sellerName,
142
                "HandlingTime" => $handlingTime,
143
                "ShippingCost" => $shippingCost,
144
                "ShippingEstimated" => $shippingEstimated,
145
                "ShippingCurrency" => $shippingCurrency,
146
                "FreeShippingCap" => $freeShippingCap,
143 - 147
                "Show" => true,
148
                "Details" => ""
84 - 149
            );
150
        }
151
    }
152
    // If the response does not indicate 'Success,' log the error(s)
153
    else {
154
echo "Empty Return:<br><pre>";print_r($result);echo "</pre>"; // bugbug
155
/*
156
        if (!empty($result->Errors)) {
157
            foreach ($result->Errors as $error) {
158
                if ($error->ErrorID != "7186919") { // no product found, not an error
96 - 159
                    my_error_log($url);
160
                    my_error_log("$error->ErrorText ($error->ErrorId)");
84 - 161
                }
162
            }
163
        } else {
96 - 164
            my_error_log($url);
165
            my_error_log("No result or error message.");
84 - 166
        }
167
    */
168
    }
169
 
170
    return $arr;
171
}