hi,
I’m trying to implement an interface with my fulfillment center. They use EDI XML file transfers which I’ve managed to implement as a dashboard page.
Once all order information is sent to the fulfillment center, I want to mark the orders as fulfilled.
I’m using createFulfillment() function under Wix-Stores-Backend API.
The function is executing without errors and creates the fulfillment.
The problem is the order fulfillmentStatus doesn’t change from “NOT_FULFILLED”.
This is the main code:
import { createFulfillment } from 'backend/fulfillment';
import { deleteFulfillment } from 'backend/fulfillment';
...
$w("#repeaterOrders").forEachItem(async ($item, itemData, index) => {
if ($item("#checkboxSelected").checked) {
orderId=$item("#textOrderId").text;
lineItemsArray=JSON.parse($item("#textBoxLineItems").value);
fulfillmentsArray=JSON.parse($item("#textBoxFulfillments").value);
console.log("before delete");
console.log(fulfillmentsArray);
if (fulfillmentsArray.length>0) {
fulfillmentsArray.forEach(async element => {
//console.log("Fulfillment Id: "+element.id)
fulfillmentId=element.id;
results= await deleteFulfillment(orderId,fulfillmentId);
console.log("after delete");
//console.log(results);
} );
}
lineItemsArray.forEach(async element => {
toFulfill= {
"index": element.index,
"quantity": element.quantity
}
fulfillmentLineItems.push(toFulfill);
} );
//console.log(fulfillmentLineItems);
//console.log(orderId);
results= await createFulfillment(orderId,lineItemsArray);
console.log("After Create");
console.log(results);
totalOrders--;
totalRevenue=totalRevenue-parseFloat($item("#textValue").text);
let tempData = $w("#repeaterOrders").data;
tempData.splice(index,1);
//$w("#repeaterOrders").data = tempData;
}
} );
and the backend code:
import wixStoresBackend from 'wix-stores-backend'
export async function createFulfillment(orderId,lineItemsArray) {
let newFulfillment= await wixStoresBackend.createFulfillment(
orderId,
{
"fulfillment": {
"lineItems": lineItemsArray,
}
});
// Fulfillment created
const fulfillmentId = newFulfillment.id
const fulfillmentStatus = newFulfillment.order.fulfillmentStatus
console.log("(backend create) fulfillmentId: "+fulfillmentId);
console.log("(backend create) fulfillmentStatus: "+fulfillmentStatus);
return newFulfillment;
}
export async function deleteFulfillment(orderId, fulfillmentId) {
console.log("(backend delete) before delete ");
let updatedOrderObject= await wixStoresBackend.deleteFulfillment(orderId, fulfillmentId);
return updatedOrderObject;
}
What am I missing?