roykin/erp/erp_update_stock.php
2017-06-14 11:41:31 +02:00

41 lines
1.1 KiB
PHP
Executable File

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(0);
// Vendors
require_once 'ripcord/ripcord.php';
require '../config/config.inc.php';
require 'ErpTools.php';
require 'config.php';
if (empty($_GET['token']) || $_GET['token'] !== ERP_SCRIPT_TOKEN) {
die;
}
$models = ripcord::client("$url/xmlrpc/2/object");
$d = Db::getInstance();
$sql = 'SELECT `id_erp` FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_erp` IS NOT NULL';
$ids_erp = $d->executeS($sql);
$ids = array();
foreach ($ids_erp as $key => $value) {
if ($value['id_erp']) {
$ids[] = (int)$value['id_erp'];
}
}
$variants = $models->execute_kw($db, $uid, $password,
'product.product', 'read', [$ids] , array('fields' => array('qty_available', 'id'))
);
foreach ($variants as $key => $variant) {
$sql = 'UPDATE `'._DB_PREFIX_.'product_attribute` pa, `'._DB_PREFIX_.'stock_available` sa
SET sa.`quantity` = '.(int)$variant['qty_available'].'
WHERE pa.`id_erp` = '.(int)$variant['id'].'
AND pa.`id_product_attribute` = sa.`id_product_attribute`';
$d->execute($sql);
}