Subversion Repositories cheapmusic

Rev

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