-
Notifications
You must be signed in to change notification settings - Fork 4
/
bol_force_upload.php
66 lines (57 loc) · 1.77 KB
/
bol_force_upload.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
*/
require __DIR__ . "/core/init.php";
require __DIR__ . "/core/db.php";
require __DIR__ . "/core/bol.php";
$arg_ean = null;
if (count($_SERVER["argv"]) === 2) {
$arg_ean = $_SERVER["argv"][1];
if (! is_numeric($arg_ean)) {
exit("ERR: argument should be exportid");
}
}
if (count($_SERVER["argv"]) > 2) {
exit("ERR: argument should be ean");
}
$db = new core\Db(sprintf("sqlite:%s/db.sqlite", CACHE), "", "");
$now = time();
$del = 0;
$added = 0;
// Push everything we can
$update = 0;
foreach ($db->getAll("select bol_id, id, ean, title, calc_price_bol, stock from prods where bol_id is not null", []) as $prod) {
$bol_id = $prod["bol_id"];
if (intval($prod["stock"]) >= 1000) {
$prod["stock"] = "999"; // limit to 999
}
// Always lower stock by 5 so we are on the save side
$prod["stock"] = bcsub($prod["stock"], "5", 0);
if ($prod["stock"] < 0) $prod["stock"] = "0";
list($res, $head) = bol_http("PUT", "/offers/$bol_id/stock", [
"amount" => $prod["stock"],
"managedByRetailer" => true
]);
ratelimit($head);
if ($head["status"] !== 202) {
var_dump($res);
continue;
}
$bundle = [[
"quantity" => 1,
"price" => $prod["calc_price_bol"]
]];
list($res, $head) = bol_http("PUT", "/offers/$bol_id/price", [
"pricing" => ["bundlePrices" => $bundle]
]);
$stmt = $db->exec("update prods set bol_pending=? where id=?", [$res["id"], $prod["id"]]);
if ($stmt->rowCount() !== 1) {
user_error("ERR: Failed updating DB with ean=" . $prod["ean"]);
}
echo sprintf("bol_update %s price=%s\n", $prod["ean"], $prod["calc_price_bol"]);
$update++;
ratelimit($head);
}
echo "del=$del\n";
echo "added=$added\n";
echo "update=$update\n";