1

如何调用 Magento SOAP API v2 以获取 vb.net 中一组日期之间的所有销售订单?

到目前为止,这是我尝试过的,但0尽管存在销售订单,但它仍会返回销售订单。

Dim ae As associativeEntity = New associativeEntity()
ae.key = "status"
ae.value = "processing"
Dim params As filters = New filters

Dim dateFilter As complexFilter
dateFilter = New complexFilter()
dateFilter.key = "created_at"
Dim nestedFilterFrom As associativeMultiEntity = New associativeMultiEntity()
nestedFilterFrom.key = "gteq"
nestedFilterFrom.value = New String() {DateTime.Parse(fromDate).ToUniversalTime.ToString()}
dateFilter.value = nestedFilterFrom
Dim dateToFilter As complexFilter = New complexFilter()
Dim nestedFilterTo As associativeMultiEntity = New associativeMultiEntity()
nestedFilterTo.key = "lteq"
nestedFilterTo.value = New String() {DateTime.Parse(toDate).ToUniversalTime.ToString()}
dateToFilter.key = "created_at"
dateToFilter.value = nestedFilterTo

params.complex_filter = New complexFilter() {dateFilter, dateToFilter}    
magentoWS.salesOrderList(sessionID, params)

我已经能够获得相同的代码来匹配状态,如下所示。

Dim ae As associativeEntity = New associativeEntity
Dim params As filters = New filters()
ae.key = "status"
ae.value = "processing"
params.filter = New associativeEntity() {ae}
magentoWS.salesOrderList(sessionID, params)
4

2 回答 2

1

日期格式必须如下,过滤器才能工作。

YYYY-MM-DD

我只发现了这一点,因为这就是 Magento 的SOAP "v2" XML Request example中的情况。在文档或他们的回复中指定这一点会很好,但请务必如此。如果有人感兴趣,这里是代码。

Dim ae As associativeEntity = New associativeEntity With { .key = "status", .value = "processing" }
Dim params As filters = New filters

Const createdAt As String = "created_at"
Const magentoDateTimeFormat As String = "yyyy-MM-dd"

Dim nestedFilterFrom As associativeMultiEntity =
    New associativeMultiEntity With {.key = "from", .value = New String() {fromDate.ToString(magentoDateTimeFormat)}}
Dim dateFromFilter As complexFilter = New complexFilter With {.key = createdAt, .value = nestedFilterFrom}

Dim nestedFilterTo As associativeMultiEntity =
    New associativeMultiEntity With {.key = "to", .value = New String() {toDate.ToString(magentoDateTimeFormat)}}
Dim dateToFilter As complexFilter = New complexFilter With {.key = createdAt, .value = nestedFilterFrom}

params.complex_filter = New complexFilter() {dateFromFilter, dateToFilter}    
magentoWS.salesOrderList(sessionID, params)

需要注意的是,在这种情况下,fromandto过滤器等同于lteqand gteq。我发现from并且to在这种情况下更有意义,但结果是一样的。

于 2013-08-08T15:02:06.613 回答
0
Public Function getMageOrdersListByFilter(ByVal fromDate As DateTime, ByVal toDate As DateTime) As MagentoService.salesOrderListEntity()
    GetMageSessionId()

    Dim f As MagentoService.filters = New MagentoService.filters

    Const createdAt As String = "created_at"
    Dim magentoDateTimeFormat As String = "yyyy-MM-dd"
    magentoDateTimeFormat = "yyyy-MM-dd HH:mm:ss"

    Dim cpf(2) As MagentoService.complexFilter
    cpf(0) = New MagentoService.complexFilter With {.key = createdAt, .value = New MagentoService.associativeEntity With {.key = "from", .value = New String(fromDate.ToString(magentoDateTimeFormat))}}
    'HACK FIX: http://www.magentocommerce.com/bug-tracking/issue?issue=8073
    cpf(1) = New MagentoService.complexFilter With {.key = "/*fake*/created_at", .value = New MagentoService.associativeEntity With {.key = "to", .value = New String(toDate.ToString(magentoDateTimeFormat))}}

    f.complex_filter = cpf

    Dim oList() As MagentoService.salesOrderListEntity = Nothing

    Try
        oList = mage.salesOrderList(sessionId, f)
    Catch ex As Exception

    End Try

    Return oList

End Function
于 2013-10-18T15:12:17.593 回答