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 50
|
<?php
function dowload_products() {
$response = "";
$url="https://api.cin7.com/api/v1/Products?where=(stockControl=%27FIFO%27)and(status=%27Public%27)&order=&rows=250&fields=category,productType,customfields(products_1000,products_1001,products_1002,products_1003,products_1004,products_1005,products_1006,products_1007,products_1011,products_1013,products_1014),name,styleCode,brand,productType,description,stockControl,productOptions(code,option1,option2,priceColumns(frbareurincleur,frtradeeurexcleur,frretaileurhteur,frretaileureur,hkbarhkdhkd,hkptfhkdhkd,sgbarsgdincsgd,costEUR,hkonlinehkdhkd,hkretailhkdhkd,sgptfsgdincsgd,sgtradesgdisgd,sgonlineexclsgd,sgretailsgdsgd,hkaghkdhkd,hkwholhkdhkd,hktradehkdhkd))";
$usr="login";
$pwd="psw";
$data = [];
$to_sort=[];
for ($i = 1;$response !== "[]"; $i++) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_USERPWD, $usr . ":" . $pwd);
curl_setopt($ch, CURLOPT_URL, "".$url."&page=".$i."");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$response = curl_exec($ch);
$data[$i - 1] = json_decode($response, true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
foreach ($data[$i - 1] as $line => $key0) {
foreach($key0 as $elements => $key1) {
if (gettype($key1) == 'array') {
foreach($key1 as $element => $key2)
if (gettype($key2) == 'array')
foreach($key2 as $key3 => $key4) {
if (gettype($key4) == 'array')
foreach($key4 as $key5 => $key)
$to_sort[$key5] = $key;
else
$to_sort[$key3] = $key4;
}
else
$to_sort[$element] = $key2;
}
else
$to_sort[$elements] = $key1;
}
$data[$i - 1][$line] = $to_sort;
}
}
sleep(1);
return $data;
}
print_r(dowload_products());
?> |
Partager