如何调用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)
答案 0 :(得分:1)
日期格式必须符合以下条件才能使过滤器正常工作。
YYYY-MM-DD
我只发现了这一点,因为这就是Magento SOAP "v2" XML Request example中的情况。在文档或响应中指定它会很好,但 se la vie 。如果有人感兴趣,这里是代码。
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)
应注意,在这种情况下,from
和to
过滤器等同于lteq
和gteq
。我发现from
和to
在这种情况下更有意义,但结果是相同的。
答案 1 :(得分: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