How To Create An Invoice For Order Programatically In Prestashop

In this tutorial I will show you step by step how to create an invoice for orders programatically, first of all you need to create the code for your order to insert it in the database, if you don't know how to create an order programatically in prestashop you can use our tutorials. To create an invoice for every order you need to make an insert in the database, anyway, these functions are already made in prestashop so you need to use only a line of code to implement this feature. 

$order_object->setInvoice(true);

Using the above function prestashop will know to generate the invoice for the current order and it will save it for you the back office order panel. $order_object being the main order object you have just made from the customer details. I had some problems with this function because sometimes it does not work, so if you have the same problems with it, try to add the following line code before the setInvoice() function.

$_GET['id_order'] = (int)$order_object->id; 

Adding in $_get paramter the order id solved the problem with invoice for me. Once you have the invoice added in the database is more easier to generate it in a pdf and send to the customer by email after the order is completed. In the future tutorials I will show you how to send invoice by email to customer after order is completed, you can check the validateOrder() from PaymentModule.php file, you have to check the code from that function and then you will know how to implement it in your own function, using that function seems more complicated then if you create it from scratch. 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x