Merge branch 'erp-sync-products' of gitlab.antadis.fr:dev-antadis/roykin into erp-sync-products

This commit is contained in:
Thibault UBUNTU 2016-03-22 10:37:34 +01:00
commit 273c5089f7

72
erp/erp_add_product.php Normal file
View File

@ -0,0 +1,72 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Vendors
require_once 'ripcord/ripcord.php';
require '../config/config.inc.php';
require 'ErpTools.php';
// load config Odoo
require 'config.php';
$models = ripcord::client("$url/xmlrpc/2/object");
// get all salable products ids
$ids_product = $models->execute_kw($db, $uid, $password,
'product.template', 'search', [[['sale_ok', '=', true]]]
);
foreach ($ids_product as $key => $id) {
// get product's information
$record = $models->execute_kw($db, $uid, $password,
'product.template', 'read', array($id)
);
$variants = $models->execute_kw($db, $uid, $password,
'product.product', 'read', [$record['product_variant_ids']]
);
$db = Db::getInstance();
try {
// set in ps_product
$sql = 'INSERT INTO '._DB_PREFIX_.'product (id_category_default, id_shop_default, id_tax_rules_group, ean13, quantity, price, reference, weight, active, redirect_type, erp_id) VALUES (18, 1, 0, '.pSQL($record['ean13']).', '.pSQL($record['qty_available']).', '.pSQL($record['lst_price']).', "'.pSQL($record['default_code']).'", '.pSQL($record['weight_net']).', 1, "404", '.pSQL($id).')';
$db->execute($sql);
// set in ps_product_lang
$product_id = $db->Insert_ID();
$sql = 'INSERT INTO '._DB_PREFIX_.'product_lang (id_product, id_shop, id_lang, description_short, link_rewrite, name) VALUES('.$product_id.', 1, 1, "<p>'.pSQL($record['description_sale']).'</p>", "'.pSQL(Tools::link_rewrite($record['name'])).'", "'.pSQL($record['name']).'")';
$db->execute($sql);
// set variant
foreach ($variants as $key => $variant) {
$attr = $models->execute_kw($db, $uid, $password,
'product.attribute.line', 'read', [$variant['attribute_line_ids']]
);
var_dump($attr); die;
$sql = 'INSERT INTO '._DB_PREFIX_.'product_attribute (id_product, ean13, price, quantity, weight, reference) VALUE('.pSQL(product_id).', '.pSQL($variant['ean13']).', '.pSQL($variant['lst_price']).', '.pSQL($variant['qty_available']).', '.pSQL($variant['weight_net']).', '.pSQL($variant['default_code']).')';
$db->execute($sql);
$last_variant_id = $db->Insert_ID();
}
} catch (Exception $e) {
d($e->getMessage());
}
die;
}