-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetAllBrands.php
49 lines (36 loc) · 1.25 KB
/
getAllBrands.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
require_once 'inc/config.php';
$brandList = array();
echo "<h1>Brands</h1>";
for($i = 0; $i < 99; $i++){
$result = readProductCategories($i, $url, $accessToken)["brands"];
if($result !== null){
$brandList = array_merge($result, $brandList);
}
else{
break;
}
}
echo "<pre>";
var_dump($brandList);
echo "</pre>";
$file = 'inc/brands.json';
//Write upload id to file
file_put_contents($file, json_encode($brandList));
//Use https://www.convertcsv.com/json-to-csv.htm to convert brand list to csv
function readProductCategories($page, $url, $accessToken){
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . '/v3/products/brands?page='.$page.'&limit=1000');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array();
$headers[] = 'Authorization: Bearer ' . $accessToken;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return json_decode($result, true);
}