将Magento API与MSSQL连接的最佳方法是什么?

时间:2018-06-21 06:23:14

标签: sql-server node.js rest magento soap

我正在将Magento V1.82升级到Magento 2.2。 目前,我将Magento SOAP API接口与MSSQL结合使用,这是一种过时的方法,并且希望探索最新的方法。因此,我想知道在Magento与MSSQL之间进行交互的最佳方法是什么。

我在node.js上有经验,想探索是否有人建议。

当前SOAP API接口伪代码:

  1. soapMagentoCall.exe-用VB.net编码
  2. 使用Windows Scheduler调度此可执行文件。
  3. Magento API Web服务在_ListOfOrd.txt中可用
  4. SOAP调用的输出放置在Output目录中
  5. 计划将SQL Job从Output目录中选择xml文件以加载到相应的MSSQL表中。

Module1.vb

模块Module1

Public sOutputPath As String = AppDomain.CurrentDomain.BaseDirectory & "Output\"
Public sArcPath As String = AppDomain.CurrentDomain.BaseDirectory & "Arc\"

Public sInputPath As String = AppDomain.CurrentDomain.BaseDirectory

Public URL As String  = "https://www.example.com/store/index.php/api/v2_soap/index/"

获取会话ID

    Function getSessionID() As String
    Dim sRequestFileName As String = sInputPath & "login.txt"
    Dim sRequestContent As String = GetFileContent(sRequestFileName)
    Dim sOutputFileName As String = "sessionID.txt"

    Dim fPost As Boolean = False

    fPost = PostRequest(sRequestContent, URL, sOutputFileName)

    If fPost Then

        sRequestContent = GetFileContent(sOutputPath & sOutputFileName)
        Dim xmldoc As System.Xml.XmlDocument = New System.Xml.XmlDocument

        Try
            xmldoc.LoadXml(sRequestContent)
        Catch ex As Exception
            Return ""
        End Try


        Dim nsMgr As System.Xml.XmlNamespaceManager = New System.Xml.XmlNamespaceManager(xmldoc.NameTable)
        nsMgr.AddNamespace("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/")
        nsMgr.AddNamespace("ns1", "urn:Magento")
        nsMgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
        nsMgr.AddNamespace("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/")


        getSessionID = xmldoc.SelectSingleNode("/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:loginResponse/result", nsMgr).InnerText

获取订单列表:

    getListOfOrd = False

    Dim sRequestFileName As String = sInputPath & "req_ListOfOrd_Processing.txt"
    Dim sRequestContent As String = GetFileContent(sRequestFileName)
    Dim sOutputFileName As String = "_ListOfOrd.txt"

    sRequestContent = Replace(sRequestContent, "**sessionID**", sSessionID)

    Debug.Print(sRequestContent)

    Dim fPost As Boolean = False

    fPost = PostRequest(sRequestContent, URL, sOutputFileName)

    If fPost Then

        sRequestContent = GetFileContent(sOutputPath & sOutputFileName)
        Dim xmldoc As System.Xml.XmlDocument = New System.Xml.XmlDocument

        Try
            xmldoc.LoadXml(sRequestContent)
        Catch ex As Exception
            Return ""
        End Try

        Dim nsMgr As System.Xml.XmlNamespaceManager = New System.Xml.XmlNamespaceManager(xmldoc.NameTable)
        nsMgr.AddNamespace("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/")
        nsMgr.AddNamespace("ns1", "urn:Magento")
        nsMgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
        nsMgr.AddNamespace("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/")

        getSessionID = xmldoc.SelectSingleNode("/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:loginResponse/loginReturn", nsMgr).InnerText

        Dim nl As System.Xml.XmlNodeList
        Dim sOrderNumber As String
        Dim iArrLen As Integer

        nl = xmldoc.SelectNodes("/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:salesListOfOrdResponseParam/result/complexObjectArray/increment_id", nsMgr)

        If nl.Count > 0 Then 
        .
        .
        .
        Get the order...    

0 个答案:

没有答案