We have a scenario where we fulfill orders via an API. Previously the logic has been tied to the invoicing process, so that when an invoice is created, the fulfillment logic is executed. If there were API errors, an order attribute was set which would then display a column in the order grid indicating that an API error occurred during fulfillment.
After refactoring and cleaning up this messy code, we got rid of "API Error" column. We were hoping to set the order status to "Pending Fulfillment" or similar when starting the fulfillment process, and having the order stay in that status in case of an error to indicate to our customer service department that the order had an error and needs manual intervention to attempt fulfillment again.
We attempted to programmatically hold the order in a "Fulfillment Failed" status, but that also did not work due to Magento completing the order. The "Fulfillment Failed" status gets set when we encounter an API error, but Magento still completes the order. Since our fulfillment function is listening for the event
sales_order_invoice_pay I'm assuming this is because the invoice has already been created, and Magento thinks the order is now complete even though there were API errors.
The question is: how do we get Magento to stop completing the orders and leave them in the "Fulfillment Failed" status, so they can be manually reviewed?
So far, here are some ideas we've come up with: + Partially invoice each order item as its fulfillment succeeds (not really sure how to accomplish this) + Programmatically change the status AFTER Magento has completed it. Unfortunately, this also doesn't seems possibly after the order is Complete. If I can't change its status to HOLDED after it's complete manually, I'm guessing we won't be able to do it programmatically either. + Bring back the API Errors column
I'm hoping that we're overlooking something and that there may be a much simpler to implement solution for our scenario.