在客户端调用的Meteor方法中调用Magento SOAP

时间:2016-07-29 15:22:31

标签: javascript magento meteor soap

我在Meteor中使用zardak:soap包来连接Magento SOAP v2 API。我在'服务器内创建了一个文件。我在Meteor.startup上创建soap连接的文件夹。然后我运行一个每隔30秒调用随机肥皂方法的自动收报机,以保持连接。

let soapConnection;

Meteor.startup(() => {
    soapConnection = createAPIConnection('http://magento.site.com/api/v2_soap/?wsdl=1', {username: 'user', apiKey: 'password'});
});

function createAPIConnection(url, credentials) {
    try {
        let client = Soap.createClient(url);

        let loginResult = client.login(credentials);
        let sessionId = loginResult.loginReturn.$value;

        return {
            conn: client,
            sessionId: sessionId
        };

    } catch (e) {
        if (e.error === 'soap-creation') {
            console.log('SOAP Client creation failed');
        }

        return null;
    }
}

function tick() {
    try {
        soapConnection.conn.catalogCategoryInfo({
            sessionId: soapConnection.sessionId,
            categoryId: 1
        }, (err, result) => { });

    } catch (e) { }
}

然后我有一个从客户端调用的Meteor方法。当它被调用时,肥皂方法调用失败,我得到一个肥皂错误'控制台中的消息。

Meteor.methods({
'createMagentoCustomer'(customer) {
        try {
            soapConnection.conn.customerCustomerCreate({
                sessionId: soapConnection.sessionId,
                customerData: customer
            }, (err, res) => {
                if (err)
                    console.log('soap error');
                else
                    console.log(res);
            });

        } catch (e) {
            console.log('SOAP Method <customerCustomerCreate> call failed');
        }
    },
});

所以,自动收报机运行良好没有任何问题,但是当我尝试通过Meteor方法调用soap时,它会失败。请注意,soapConnection方法不为null,并且我确实在soap方法回调中收到错误。

有什么建议吗?

Meteor版本1.3.4.1

0 个答案:

没有答案
相关问题