2016-03-25 11:57:28 +01:00
|
|
|
<?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';
|
|
|
|
|
2016-04-22 11:48:07 +02:00
|
|
|
if (empty($_GET['token']) || $_GET['token'] !== ERP_SCRIPT_TOKEN) {
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
2016-03-25 11:57:28 +01:00
|
|
|
$models = ripcord::client("$url/xmlrpc/2/object");
|
|
|
|
|
|
|
|
$d = Db::getInstance();
|
|
|
|
|
2016-03-31 16:27:50 +02:00
|
|
|
$sql = 'SELECT `id_erp` FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_erp` IS NOT NULL';
|
2016-03-31 16:11:33 +02:00
|
|
|
$ids_erp = $d->executeS($sql);
|
2016-03-25 11:57:28 +01:00
|
|
|
|
2016-03-31 16:11:33 +02:00
|
|
|
$ids = array();
|
|
|
|
foreach ($ids_erp as $key => $value) {
|
|
|
|
if ($value['id_erp']) {
|
|
|
|
$ids[] = (int)$value['id_erp'];
|
2016-03-25 11:57:28 +01:00
|
|
|
}
|
2016-03-31 16:11:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$variants = $models->execute_kw($db, $uid, $password,
|
2016-03-31 16:27:50 +02:00
|
|
|
'product.product', 'read', [$ids] , array('fields' => array('qty_available', 'id'))
|
2016-03-31 16:11:33 +02:00
|
|
|
);
|
2016-03-25 11:57:28 +01:00
|
|
|
|
2016-03-31 16:11:33 +02:00
|
|
|
foreach ($variants as $key => $variant) {
|
2016-03-31 16:27:50 +02:00
|
|
|
$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`';
|
2016-03-31 16:11:33 +02:00
|
|
|
$d->execute($sql);
|
2016-03-31 16:27:50 +02:00
|
|
|
}
|