Has anyone figured out how to programatically create an order in Magento 2.1 yet ?
There are a few tutorials kicking around for 2.0 which work nicely but every since I upgraded it no longer works. The error I most often see is:
Exception #0 (Magento\Framework\Exception\NoSuchEntityException): Cart 88 does not contain item 91
Obviously the cart ID and item ID change with every attempt.
I have been looking at admin order create and the only difference is when we hit the file:
save() function when processing an order in the admin
$items = $quote->getItems(); is
null whereas when programmatically creating an order we have an item still.
Anyone know why this is happening? Or just know how to create an order?
My class can be found here:
But there is quite a lot going on. Most logic happens in function
If you use the code that's in this question : How to create order programmatically in Magento 2?
You will get the same error. It might be easier to follow than my example
Big thanks to Jaimin Parikh for helping me out with this.
I thought it might be useful to put together a quick blog post about the differences between 2.0 and 2.1 now that I've solved my problem with a more simplified example. Here is the link:
Another side note to this if anyone still has problems after the above. You need to us the environment emulation. Various checks in magento core get the current store view, which, if you are running this from a cron for example, will return as store id 0 which may not match the quote that you are creating.