Migrating createFulfillment from wixStoresBackend to wixEcomBackend

Question:
I saw that wixEcomBackend seems to be out of developer preview and have noticed that the Velo docs are advising users to migrate to wixEcomBackend before Sep 2024. However, the new createFulfillment appears to work differently than before.

The only immediately obvious difference in the createFulfillment input parameters that I could see was the change in lineItems, which require id now instead of index.

Yet after having made the change, the createFulfillment function does not work as it did before and I am constantly getting a NON_MATCHING_FULFILLER_IDS_WITH_APP_DEF error.

I have a few contacts who are handling delivery of products to my warehouse and I have set them up as my fulfillers. After assigning the relevant fulfillers to my products, I have set up a collection in CMS that has a boolean field, “active”, that when updated to True, triggers a Backend collection_afterUpdate code to do an orderFullfilments.createFulfillment to automatically assign a Tracking Number and the relevant fulfillers as the Shipping provider.

However, the problem arises here: If I have a fulfiller assigned, the order’s lineItems appear to have a fulfillerId already assigned and as such, I cannot createFulfillment. Yet when I check the order CMS or listFulfillmentsForSingleOrder(), there are no fulfillments listed for the order, so I cannot updateFulfillment nor deleteFulfillment to recreate it.

Product:
Wix Stores, Wix Editor, Velo

What are you trying to achieve:
I am trying to update tracking numbers using the new orderFulfilments.createFulfilments and upon creation, I expect that my orders become “Marked as fulfilled” and a confirmation email be sent to the fulfillers I have assigned my products to.

What have you already tried:
I have tried setting the products to self-fulfilled, which does allow createFulfillment but I will have to manually forward the order from my email to my fulfillers, which defeats the purpose of automating this whole process, so thats a no.

I have tried not catching the errors, hoping that they are being handled differently by Velo since I couldn’t find anything on the docs about this error but unfortunately that is not the case.

I have tried obtaining the fulfillerId from the lineItems but via createFulfillment, I have nowhere to assign it to so Velo continues to whine about NON_MATCHING_FULFILLER_IDS_WITH_APP_DEF.

The APP_DEF tipped me off that I might have to actually implement a 3rd party app to allow createFulfillment to find the correct fulfillerId from the shippingProvider string that I provided in the trackingInfo parameter, since regarding custom shipping providers the only thing we can do is just create a name and do not have any access to any of the underlying information that might assist us users in using them in Velo.

The alternative to using trackingInfo as a parameter is to use customInfo, which has no documentation whatsoever yet only accepts specific, unknown fields and so I have no idea what I’m supposed to put in there.

Additional information:
Relevant code:

const trackingInfo = {
                    trackingNumber: item.title, // A uuid4
                    shippingProvider: item.carrier, // A "custom" shipping carrier
                    trackingLink: "https://www.testsite.com" + item["link-order-tracking-title"], // A dynamic page on my Wix site
                }
const lineItems = order.lineItems.map((item, idx) => {
                    console.log(item)
                    return { _id: item._id }
                })
const elevatedCreateFulfillment = elevate(orderFulfillments.createFulfillment)

                // Automatically fulfilling orders with stock delivery option
                // Tentatively using wixStoresBackend, nearer to 30th June 2024 must change to ordersFulfillment from wix-ecom-backend
await elevatedCreateFulfillment(order._id, { lineItems, trackingInfo })
                    .then((createdItem) => {
                        console.log("Fulfillment created")
                    })
                    .catch((error) => {
                        console.log("Error creating fulfillment:", error)
                    })

Error log:
"message: 'INVALID_ARGUMENT: \"61e29eec-bb63-461a-a77c-cf64f36bfe21\" Order [61e29eec-bb63-461a-a77c-cf64f36bfe21] - Non matching fulfiller ids: Vector(c491637f-ce67-4ad8-bd37-3c53e04a73f3) called by Some(151e476a-715e-ec33-db9a-a7ff4d51f70a)'\ndetails:\n validationError:\n fieldViolations:\n - field: 61e29eec-bb63-461a-a77c-cf64f36bfe21\n description: 'Order [61e29eec-bb63-461a-a77c-cf64f36bfe21] - Non matching fulfiller ids: Vector(c491637f-ce67-4ad8-bd37-3c53e04a73f3) called by Some(151e476a-715e-ec33-db9a-a7ff4d51f70a)'\n violatedRule: OTHER\n ruleName: NON_MATCHING_FULFILLER_IDS_WITH_APP_DEF"]"

I’ll raise internally but if you think this is a bug then the best place to report this is customer care: Contact Wix

1 Like