Subversion Repositories cheapmusic

Rev

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