JohnsonZA Posted July 12, 2010 Share Posted July 12, 2010 I have a problem with my shop that has resulted in invoices not being sent with emails. Invoices are enabled and are available in the "My orders" page.From this segment of code that attaches the PDF in PaymentModule.php: // Join PDF invoice if (intval(Configuration::get('PS_INVOICE')) AND Validate::isLoadedObject($orderStatus) AND $orderStatus->invoice AND $order->invoice_number) { $fileAttachment['content'] = PDF::invoice($order, 'S'); $fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', intval($order->id_lang)).sprintf('d', $order->invoice_number).'.pdf'; $fileAttachment['mime'] = 'application/pdf'; } I have determined that $order->invoice_number is not set when the email is being sent and appears to be the reason why the invoice is not attached. But, it must be set at some stage since the invoices appear with the correct number in the "My orders" page.Does anyone know what could have caused this problem? Your help will be greatly appreciated. Link to comment Share on other sites More sharing options...
tomerg3 Posted July 12, 2010 Share Posted July 12, 2010 Which version of PS do you use?Did you make any changes to it?Do regular emails work fine? Link to comment Share on other sites More sharing options...
JohnsonZA Posted July 12, 2010 Author Share Posted July 12, 2010 Which version of PS do you use?Did you make any changes to it?Do regular emails work fine? I'm using 1.3.1. I have made numerous changes to the code, but none that deal with payment/invoicing that I can recall. Regular emails work fine. The emails confirming orders and payment are sent, they just don't contain the invoice attachments. Link to comment Share on other sites More sharing options...
tomerg3 Posted July 13, 2010 Share Posted July 13, 2010 You can try to do a new clean install of Prestashop and see if it happens there as well, if it does, it's a bug, if not, then probably something was changed on your server, or maybe a problem with the payment method you use. Link to comment Share on other sites More sharing options...
JohnsonZA Posted July 13, 2010 Author Share Posted July 13, 2010 I've figured out a fix, but I don't know if this applies to new installations, although my guess is it would. Maybe someone else can test this?The invoice number is set in a call to OrderHistory::changeIdOrderState() when the new order state says that the invoice can be issued. The invoice_number and invoice_date fields of the $order object in the changeIdOrderState() function are set and the changes are saved to the database. When the function returns to the PaymentModule::validateOrder() function, the $order object still has the old invoice_number and invoice_date values, which are null.My solution is expressed in the following code: $new_order = new Order(intval($order->id)); $order->invoice_number = $new_order->invoice_number; $order->invoice_date = $new_order->invoice_date; By reading the order in from the database again, the invoice number and invoice date values are now available. The PDF is then attached because the invoice number on the order is set.Is there perhaps a neater way to do this? 1 Link to comment Share on other sites More sharing options...
Jean-Bruno Posted October 19, 2010 Share Posted October 19, 2010 HiI will test it if you tell me where do i put this 3 linesMany, many thanks Link to comment Share on other sites More sharing options...
JohnsonZA Posted October 19, 2010 Author Share Posted October 19, 2010 HiI will test it if you tell me where do i put this 3 linesMany, many thanks The code must be added around line 365 (in PS v1.3.2) of classes/PaymentModule.php just before the "Join PDF Invoice" comment.As I said in my earlier comment, the issue is that the invoice_number and invoice_date variables of the $order object don't reflect the changes made by the changeIdOrderState() function.Reading the order object in from the databases provides the updated variables. Link to comment Share on other sites More sharing options...
nzrobert Posted February 28, 2011 Share Posted February 28, 2011 It works! But you do need to enable invoice generation at any of the order statuses you want it to work for. Link to comment Share on other sites More sharing options...
holle75 Posted March 1, 2011 Share Posted March 1, 2011 Hi nzrobert, in my case with this mod it only sends the invoice with the "order confirmation"-Mail. Even when invoice generation is allowed in status "payment accepted", no attachement to the corresponding Mail in my case. How did you make it work? Link to comment Share on other sites More sharing options...
przemossj4 Posted March 11, 2011 Share Posted March 11, 2011 good thing I'm using version prestashop 1.3.1.1 Link to comment Share on other sites More sharing options...
mouse1 Posted June 27, 2012 Share Posted June 27, 2012 I've figured out a fix, but I don't know if this applies to new installations, although my guess is it would. Maybe someone else can test this? The invoice number is set in a call to OrderHistory::changeIdOrderState() when the new order state says that the invoice can be issued. The invoice_number and invoice_date fields of the $order object in the changeIdOrderState() function are set and the changes are saved to the database. When the function returns to the PaymentModule::validateOrder() function, the $order object still has the old invoice_number and invoice_date values, which are null. My solution is expressed in the following code: $new_order = new Order(intval($order->id)); $order->invoice_number = $new_order->invoice_number; $order->invoice_date = $new_order->invoice_date; By reading the order in from the database again, the invoice number and invoice date values are now available. The PDF is then attached because the invoice number on the order is set. Is there perhaps a neater way to do this? This worked perfect for my problem. When I placed a test order, an invoice was created in BO and looked perfect. But when I (as a test customer) received the order confirmation e-mail, a file attached in the e-mail wasn't the same invoice as in BO, but just some kind of order confirmation document called ORDER that looked similar to the invoice with lots of missing data (missing dates, invoice and order numbers). I just added the code in class/PaymentModule.php as JohnsonZA advised and the problem is solved. I copied the code below these lines: if ($id_order_state != _PS_OS_ERROR_ AND $id_order_state != _PS_OS_CANCELED_ AND $customer->id) { $invoice = new Address(intval($order->id_address_invoice)); $delivery = new Address(intval($order->id_address_delivery)); $carrier = new Carrier(intval($order->id_carrier)); $delivery_state = $delivery->id_state ? new State(intval($delivery->id_state)) : false; $invoice_state = $invoice->id_state ? new State(intval($invoice->id_state)) : false; It must have been some bug in Prestashop coding. I'm running an old old version 1.1.0.5 (crazy I know), but it is sufficient for my purpose. Thank you very much JohnsonZA!! Hope this helps others too. Jana Link to comment Share on other sites More sharing options...
mister006 Posted February 14, 2013 Share Posted February 14, 2013 Hi guys, I have the same problem: I can see the invoices in the back office of the shop, but the pdf is not attached to the order confirmation mails which are sent to customers. I have checked the status page, send invoice is marked, but It doesn't matter. Also with other statusses like Payment Accepted, an email is sent to the customer but no invoice is attached, while the option is marked in the back-office. I tried all configuration options in the back office, but no change: The invoice-pdf is not attached to any mail. The normal mailing works perfect. I also tried to program the solutions above, but it is not that straightforward in Prestashop 1.5.3.1 and I am not an expert in programming. So can you please help me with this? Thanks! Link to comment Share on other sites More sharing options...
gsoffer Posted May 21, 2013 Share Posted May 21, 2013 I have the same problem. I can generate a PDF with the invoice details, however no pdf is attached to the e mails. any suggestions? Link to comment Share on other sites More sharing options...
Recommended Posts