I'm making a software in vb.net for a client where he needs to fetch orders of perticular date from it's wordpress website I'm planning to make a datagrid view to display orders and a button to fetch data from woocommerce get oders api my ui looks like something this
But the problem is how should I make an api request and it will return me a json data so how to display it properly in datagrid view or is there any thing else or something better to display order or do this thing. Actully I'm not abe to find anything like this for sample is there anything available please let me know.
CodePudding user response:
You do something like this :-
You will have to use the REST API from woocommerce . . . Go to backend of woocommerce of the site click on woocommerce->settings->advance->rest api
This will get you the globle.key and global.secret.
Public Async Sub FillDGV() 'FillDGV
'any, pending, processing, on-hold, completed, cancelled, refunded, failed and trash
Dim dic As Dictionary(Of String, String) = New Dictionary(Of String, String)() From {{"status", SrcV}}
' Dim dic As Dictionary(Of String, String) = New Dictionary(Of String, String)()From {{"status", "pending"}}
dic.Add("per_page", "100")
Dim pageNumber As Integer = 1
dic.Add("page", pageNumber.ToString())
Dim rest As RestAPI = New RestAPI(Globle.BaseURL, Globle.Key, Globle.Secret, False)
Dim wc As WooCommerceNET.WooCommerce.v2.WCObject = New WooCommerceNET.WooCommerce.v2.WCObject(rest)
Dim orderList As New List(Of WooCommerce.v2.Order)
orderList = Await wc.Order.GetAll(dic) 'Get All order which status is SrcV
dgvlist.Rows.Clear()
For Each item In orderList 'Fill Grid
Dim Name As String = item.shipping.first_name " " item.shipping.last_name " " item.billing.phone
' CreateFile(item) 'Function call to create text file
Dim shippingtotal As String
Dim shippingmethod As String
If item.shipping_lines.Count > 0 Then
shippingtotal = item.shipping_lines.Item(0).total
shippingmethod = item.shipping_lines.Item(0).method_title
Else
shippingtotal = "0.00"
shippingmethod = ""
End If
If item.coupon_lines.Count > 0 Then
Try
dgvlist.Rows.Add(item.number, item.total, Name, item.billing.email, item.shipping.address_1, item.shipping.address_2, item.shipping.city, item.shipping.state, item.shipping.country, item.shipping.postcode, item.shipping.company, shippingmethod, shippingtotal, item.date_created, item.coupon_lines.Item(0).code, item.coupon_lines.Item(0).discount, item.payment_method, item.customer_note, item.total)
Catch ex As Exception
'MsgBox(ex.Message)
End Try
Else
Try
dgvlist.Rows.Add(item.number, item.total, Name, item.billing.email, item.shipping.address_1, item.shipping.address_2, item.shipping.city, item.shipping.state, item.shipping.country, item.shipping.postcode, item.shipping.company, shippingmethod, shippingtotal, item.date_created, 0, 0, item.payment_method, item.customer_note)
' dgvlist.Rows.Add(item.number, item.total, Name, item.billing.email, item.shipping.address_1, item.shipping.address_2, item.shipping.city, item.shipping.state, item.shipping.country, item.shipping.postcode, item.shipping.company, " ", " ", item.date_created, 0, 0, item.payment_method, item.customer_note)
Catch ex As Exception
'MsgBox(ex.Message)
End Try
End If
Next
End Sub