Handle the indexerror exception on create_order

LMS-2646
You can do loops like that in JS? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for