Answer the question
In order to leave comments, you need to log in
How to build a module structure correctly?
The task is to export the module with its functions (treeCatalog, catalogCreate in the future there will be more of them), these functions must return some variables (cate, result) generated by internal functions.
I tried to create a session separately when calling the function: unsuccessfully.
I suppose that you need to modify the internal Callback functions, push in which direction to dig
var MagentoAPI = require('magento');
var fs = require('fs');
var magento = new MagentoAPI({
host: 'host.ru',
port: 80,
path: '/api/xmlrpc/',
login: 'login',
pass: 'pass'
});
// Открываем сессию получаем sessId
magento.login(function(err, sessId) {
if (err) {
console.log(err)
// deal with error
return;
}
//Получить список категорий
function treeCatalog (id){
magento.catalogCategory.tree({
parentId: id, /* optional */
//storeView: 1 /* optional */
}, function (err, result) {
if (err != null) {
console.log(err)}
else{
var cate = []
for (i = 0; i < result.children.length; i++){
var categor = {name:'', id:''}
categor.name = result.children[i].name
categor.id = result.children[i].category_id
cate.push (categor)
}
}
});
}
//создать категорию
function catalogCreate (opt){
var catalogData = {
name: opt.name,
include_in_menu: 1,
available_sort_by: [1],
is_active: 1,
position: 1,
default_sort_by: 1,
}
magento.catalogCategory.create({
categoryId: opt.id,
data: catalogData,
// storeView: val /* optional */
}, function (err, result) {
if (err != null) {
console.log(err)}
else{
console.log("Catalog --" + '\n'+ result)
};
});
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question