diff --git a/erp/erp_add_product.php b/erp/erp_add_product.php new file mode 100644 index 0000000..5d711fe --- /dev/null +++ b/erp/erp_add_product.php @@ -0,0 +1,72 @@ +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, "
'.pSQL($record['description_sale']).'
", "'.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; + +} \ No newline at end of file