| 20 |
- |
1 |
<?php
|
| 65 |
- |
2 |
include_once ('php/constants.php');
|
| 20 |
- |
3 |
|
|
|
4 |
error_reporting(E_ALL);
|
|
|
5 |
|
|
|
6 |
// Get Walmart listings
|
| 66 |
- |
7 |
function get_walmart($query, $searchCondition) {
|
| 20 |
- |
8 |
$vendors = Vendors::getInstance();
|
|
|
9 |
$config = $vendors->getVendor(Vendors::WALMART);
|
| 65 |
- |
10 |
$safequery = urlencode($query);
|
| 20 |
- |
11 |
|
|
|
12 |
// Music
|
| 66 |
- |
13 |
$arrMusic = get_walmartCategory($config, $safequery, $searchCondition, $config["musicCategory"]);
|
| 20 |
- |
14 |
|
|
|
15 |
// Books
|
| 66 |
- |
16 |
$arrBooks = get_walmartCategory($config, $safequery, $searchCondition, $config["bookCategory"], $config["bookSubCategory"]);
|
| 20 |
- |
17 |
|
| 65 |
- |
18 |
return (array_merge($arrMusic, $arrBooks));
|
| 20 |
- |
19 |
}
|
|
|
20 |
|
|
|
21 |
// Get linkshare listings by advertiser id
|
| 66 |
- |
22 |
function get_walmartCategory($config, $safequery, $searchCondition, $categoryId, $subCategories = []) {
|
| 65 |
- |
23 |
// API request variables
|
|
|
24 |
$numResults = $config['numResults'];
|
| 20 |
- |
25 |
|
| 65 |
- |
26 |
// Construct the findItemsByKeywords HTTP GET call
|
| 20 |
- |
27 |
$url = "https://api.walmartlabs.com/v1/search";
|
|
|
28 |
$url .= "?apiKey=" . $config["apiKey"];
|
|
|
29 |
$url .= "&lsPublisherId=" . $config["publisherId"];
|
|
|
30 |
$url .= "&numItems=" . $numResults;
|
|
|
31 |
$url .= "&start=1";
|
|
|
32 |
$url .= "&sort=price";
|
|
|
33 |
$url .= "&order=asc";
|
|
|
34 |
$url .= "&categoryId=" . $categoryId;
|
|
|
35 |
$url .= "&query=" . $safequery;
|
|
|
36 |
|
| 65 |
- |
37 |
$result = getUrl($url);
|
|
|
38 |
$result = utf8_encode($result);
|
|
|
39 |
$result = json_decode($result);
|
| 20 |
- |
40 |
|
| 65 |
- |
41 |
$arr = [];
|
| 20 |
- |
42 |
|
| 65 |
- |
43 |
//echo "$url<pre>";print_r($result);echo "</pre>";
|
|
|
44 |
// Check to see if the request found any results
|
|
|
45 |
if (isset($result->totalResults)) {
|
| 21 |
- |
46 |
if ($result->totalResults <= 0) {
|
|
|
47 |
return [];
|
|
|
48 |
}
|
|
|
49 |
|
| 65 |
- |
50 |
// If the response was loaded, parse it and store in array
|
|
|
51 |
foreach ($result->items as $item) {
|
| 73 |
- |
52 |
if (!empty($subCategories) && !empty($item->categoryNode) && !in_array($item->categoryNode, $subCategories)) {
|
| 65 |
- |
53 |
continue;
|
|
|
54 |
}
|
|
|
55 |
$merchantName = "Walmart";
|
|
|
56 |
if (isset($item->marketplace) && $item->marketplace) {
|
| 20 |
- |
57 |
$merchantName .= " Marketplace";
|
| 65 |
- |
58 |
}
|
|
|
59 |
$barcode = (!empty($item->upc) ? $item->upc : "");
|
|
|
60 |
$barcodeType = clsLibGTIN::GTINCheck($barcode, false, 1);
|
| 20 |
- |
61 |
|
| 65 |
- |
62 |
$title = (string)$item->name;
|
|
|
63 |
$pic = str_replace('http://', 'https://', (string)$item->thumbnailImage);
|
|
|
64 |
if (empty($pic)) {
|
|
|
65 |
continue;
|
|
|
66 |
}
|
| 27 |
- |
67 |
|
|
|
68 |
if (!isset($item->productTrackingUrl)) {
|
|
|
69 |
continue;
|
|
|
70 |
}
|
| 65 |
- |
71 |
$url = str_replace('http://', 'https://', (string)$item->productUrl);
|
|
|
72 |
if (empty($url)) {
|
|
|
73 |
continue;
|
|
|
74 |
}
|
| 20 |
- |
75 |
|
| 65 |
- |
76 |
if ((string)$result->categoryId == $config["musicCategory"]) {
|
| 80 |
- |
77 |
if (!empty($item->categoryPath) && strpos((string)$item->categoryPath, "Vinyl Records") !== false) {
|
| 66 |
- |
78 |
$mediaType = "Record";
|
| 65 |
- |
79 |
}
|
| 80 |
- |
80 |
else if (!empty($item->categoryPath) && strpos((string)$item->categoryPath, "Cassette Tapes") !== false) {
|
| 65 |
- |
81 |
continue;
|
|
|
82 |
}
|
| 66 |
- |
83 |
else { // mediaType "...on CD or Vinyl"
|
| 65 |
- |
84 |
if (strpos($title, "Vinyl") !== false) {
|
| 66 |
- |
85 |
$mediaType = "Record";
|
| 65 |
- |
86 |
}
|
|
|
87 |
else {
|
| 66 |
- |
88 |
$mediaType = "CD";
|
| 65 |
- |
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
else {
|
| 66 |
- |
93 |
$mediaType = "Book";
|
| 65 |
- |
94 |
}
|
| 20 |
- |
95 |
|
| 66 |
- |
96 |
$condition = 'New';
|
|
|
97 |
$detailCondition = 'Brand New';
|
| 65 |
- |
98 |
$country = 'US';
|
|
|
99 |
$bestOffer = false;
|
| 20 |
- |
100 |
|
| 65 |
- |
101 |
$price = number_format(floatval(empty($item->salePrice) ? 0 : $item->salePrice) , 2, '.', '');
|
|
|
102 |
if ($price <= "0.00") {
|
|
|
103 |
continue;
|
|
|
104 |
}
|
| 20 |
- |
105 |
|
| 65 |
- |
106 |
$currency = 'USD';
|
|
|
107 |
$timeLeft = 0;
|
|
|
108 |
$listingType = 'Fixed';
|
|
|
109 |
$location = 'US';
|
|
|
110 |
$zip = '';
|
|
|
111 |
$feedbackScore = - 1;
|
|
|
112 |
$feedbackPercent = - 1;
|
|
|
113 |
$sellerName = (!empty($item->sellerInfo) ? (string)$item->sellerInfo : "");
|
|
|
114 |
$handlingTime = - 1;
|
| 24 |
- |
115 |
if (!(isset($item->marketplace) && $item->marketplace)) {
|
| 65 |
- |
116 |
$handlingTime = 1;
|
|
|
117 |
}
|
|
|
118 |
$shippingCost = 0.00;
|
|
|
119 |
if (isset($item->standardShipRate)) {
|
|
|
120 |
$shippingCost = number_format(floatval($item->standardShipRate) , 2, '.', '');
|
|
|
121 |
}
|
|
|
122 |
$shippingCurrency = 'USD';
|
| 24 |
- |
123 |
$freeShippingCap = 0;
|
| 65 |
- |
124 |
// if ($item->isTwoDayShippingEligible == "1" || $item->freeShippingOver35Dollars == "1") {
|
| 24 |
- |
125 |
if (!(isset($item->marketplace) && $item->marketplace)) {
|
| 65 |
- |
126 |
$freeShippingCap = 35.00;
|
|
|
127 |
}
|
| 20 |
- |
128 |
|
| 65 |
- |
129 |
$arr[] = array(
|
|
|
130 |
"Merchant" => $merchantName,
|
| 66 |
- |
131 |
"Condition" => "$condition",
|
| 65 |
- |
132 |
"Title" => "$title",
|
|
|
133 |
"Barcode" => "$barcode",
|
|
|
134 |
"BarcodeType" => "$barcodeType",
|
|
|
135 |
"Image" => "$pic",
|
|
|
136 |
"URL" => "$url",
|
| 66 |
- |
137 |
"MediaType" => "$mediaType",
|
|
|
138 |
"DetailCondition" => "$detailCondition",
|
| 65 |
- |
139 |
"Country" => "$country",
|
|
|
140 |
"BestOffer" => "$bestOffer",
|
|
|
141 |
"TimeLeft" => "$timeLeft",
|
|
|
142 |
"Price" => "$price",
|
|
|
143 |
"Currency" => "$currency",
|
|
|
144 |
"ListingType" => "$listingType",
|
|
|
145 |
"Location" => "$location",
|
|
|
146 |
"Zip" => "$zip",
|
|
|
147 |
"FeedbackScore" => "$feedbackScore",
|
|
|
148 |
"FeedbackPercent" => "$feedbackPercent",
|
|
|
149 |
"SellerName" => "$sellerName",
|
|
|
150 |
"HandlingTime" => "$handlingTime",
|
|
|
151 |
"ShippingCost" => "$shippingCost",
|
|
|
152 |
"ShippingCurrency" => "$shippingCurrency",
|
|
|
153 |
"FreeShippingCap" => "$freeShippingCap",
|
|
|
154 |
"Show" => true
|
|
|
155 |
);
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
// If the response does not indicate 'Success,' log the error(s)
|
|
|
159 |
else {
|
|
|
160 |
if (!empty($result->errors)) {
|
|
|
161 |
foreach ($result->errors as $error) {
|
|
|
162 |
error_log($url);
|
|
|
163 |
error_log("$error->message ($error->code)");
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
}
|
| 20 |
- |
167 |
|
| 65 |
- |
168 |
return $arr;
|
| 20 |
- |
169 |
}
|