magento 后台设定

在magento后台管理里,通过System->Web Services->SOAP/XML-RPC Roles设定你需要的权限和账户信息,如下:

Magento admin SOAP/XML-RPC Roles

调用方式

magento对应的node.js包为:https://github.com/MadisonReed/magentoapi

引用和环境设定

var MagentoAPI = require('magento');
var magento = new MagentoAPI({
host: 'www.mysite.com',
port: 80,
path: '/index.php/api/xmlrpc/',
login: 'myid',
pass: 'mypassword'
});

打印产品信息

magento.login(function(err, sessId) {
if (err) {
// deal with error
console.log(err);
return;
}
// use magento
magento.catalogProduct.info({
id: `aa-bb-cc`
}, function(err, product) {
if(err){
console.log(err);
}
else{
console.log(product);
}
});
});

更新库存

magento.catalogInventoryStockItem.update({
product: 'aa-bb-cc',
data: {
is_in_stock:1,
qty:10
}
}, function(err, data){
console.log(err, data)
});

更新产品信息

更新时,同样可以指定不同的view

magento.catalogProduct.update({
id: id,
storeView: '2',
data: {
name: 'name',
description: 'description',
short_description: 'short_description'
}
}, function (err, data) {
console.log(err, data);
});