Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FulfillmentService function not working after update to latest version ! #948

Open
BasitBulbulia opened this issue Oct 25, 2023 · 3 comments
Labels
fulfillments Questions and issues dealing with Shopify's fulfillment and fulfillment orders systems. question

Comments

@BasitBulbulia
Copy link

This is my code !


'' <summary>
'' Set an existing Shopify Order to be complete
'' </summary>
'' <param name="orderId">The id of the Order to complete</param>
'' <returns>True if successful</returns>
Public Async Function SetOrderAsComplete(orderId As Long) As Threading.Tasks.Task(Of Boolean)
    Try
        Dim locationService = New LocationService(urlFromUser, shopAccessToken)
        'set the RetryExecutionPolicy to handle the API limits
        locationService.SetExecutionPolicy(New LeakyBucketExecutionPolicy())
        Dim locations = Await locationService.ListAsync()

        Dim fulfillmentService = New FulfillmentService(urlFromUser, shopAccessToken)
        'set the RetryExecutionPolicy to handle the API limits
        fulfillmentService.SetExecutionPolicy(New LeakyBucketExecutionPolicy())

        'update the orderId to be complete
        Dim result = Await fulfillmentService.CreateAsync(orderId, New ShopifySharp.Fulfillment With {.LocationId = locations(0).Id})

        Return True
    Catch ex As Exception
        If DoAllStockUpdate = False Then MsgBox("SetOrdersAsComplete--->" & ex.Message)
        Return False
    End Try
End Function

The error is :-
ListResult(Of Location)' cannot be indexed because it has no default property.

The error location is @ locations(0).Id

I am totally lost as to how I could fix this code

error-ordercomplete

@BasitBulbulia BasitBulbulia changed the title Fullfillment fuction not working after update to latest version ! FulfillmentService function not working after update to latest version ! Oct 25, 2023
@nozzlegear
Copy link
Owner

Hey @BasitBulbulia! I think the problem is the LocationService.ListAsync does not return a list directly, instead it returns this ListResult<Location> object, so you can't do locations(0).Id.

You should be able to fix that error by using locations.Items(0).Id.

@BasitBulbulia
Copy link
Author

I tried that this is the errors in IDE
error-two

@nozzlegear
Copy link
Owner

Oh I see, which version were you using before @BasitBulbulia? It looks like you're using the older method for creating fulfillments that Shopify has deprecated and removed. They require apps to use a new "Fulfillment Order" based approach for fulfilling line items and entire orders, we're not allowed to create fulfillments with the old API anymore.

I don't know much VB unfortunately, so this may not be entirely correct. I think you want something like this:

Try
    Dim fulfillmentOrderService As New FulfillmentOrderService(domain, accessToken)
    Dim fulfillmentService As New FulfillmentService(domain, accessToken)

    Dim policy As New LeakyBucketExecutionPolicy()

    fulfillmentOrderService.SetExecutionPolicy(policy)
    fulfillmentService.SetExecutionPolicy(policy)

    ' Find open fulfillment orders for this order
    Dim openFulfillmentOrders = Await fulfillmentOrderService.ListAsync(orderId)
    openFulfillmentOrders = openFulfillmentOrders.Where(Function(f) f.Status = "open").ToList()

    ' Fulfill all line items across all open fulfillment orders in this Shopify order
    Dim lineItems = openFulfillmentOrders.Select(Function(o) New LineItemsByFulfillmentOrder With {
        .FulfillmentOrderId = o.Id.Value
        ' Optionally specify a list of line items if you're doing a partial fulfillment
        ' .FulfillmentRequestOrderLineItems = ...
    })

    ' Fulfill the line items
    Dim fulfillment = Await fulfillmentService.CreateAsync(New FulfillmentShipping With {
        .Message = "items are shipping!",
        ' Set to true to send an email to the customer that their items have shipped
        .NotifyCustomer = False,
        ' You can leave the tracking info out if you have no tracking info
        .TrackingInfo = New TrackingInfo With {
            .Company = "UPS",
            .Url = "...",
            .Number = "..."
        }
    })
Catch ex As Exception
    If DoAllStockUpdate = False Then MsgBox("SetOrdersAsComplete-->" & ex.Message)
    Return False
End Try

Check this thread here for more info on the Fulfillment Orders workflow: #828

@nozzlegear nozzlegear added the fulfillments Questions and issues dealing with Shopify's fulfillment and fulfillment orders systems. label Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fulfillments Questions and issues dealing with Shopify's fulfillment and fulfillment orders systems. question
Projects
None yet
Development

No branches or pull requests

2 participants