How to send PDF invoice together with mail button from the back-end?

  • Posts: 3
  • Thank you received: 1
5 years 7 months ago #305551

Hi,

is there a way to alter the PDF invoice plugin so that the invoice will be sent when an order is created on the back-end? The plugin does work, but the pdf is only sent on 'confirmed' status.
I offer web design services so I create the order for my customers and want to notify them with the email button (order_notification.html.modified.php) and the invoice attached.

Setting the "Statuses for email attachment" in the plugin to "Created" did not work.

I also followed the instruction using the info on this post: www.hikashop.com/forum/orders-management...s-and-invoicing.html ,
changing "order_confirmed_status" in line 345 of attachinvoice.php to "invoice_order_statuses", but no luck so far. Did I overlook something? How to get this working? Thanks in advance,
Mark

Last edit: 5 years 7 months ago by mark78.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 7 months ago #305556

Hi,

The "order notification" email is not supported by the PDF invoice plugin.
You would also have to change the line:
if(empty($data->mail_name) || !in_array($data->mail_name, array('order_status_notification', 'order_creation_notification')))
to add 'order_notification' to the list of emails to handle.

The following user(s) said Thank You: fernando.alh

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 1
5 years 7 months ago #305575

Thanks for your reply!

I can't get it working though, think I have tried most options. What I have done:

- installed the PDF invoice plugin once again
- Put the status "created" in the override setting in the plugin. I understand that this overrides variable $confirmed, is this correct?
- 'Override on the backend': Yes

In attachinvoice.php in the function onBeforeMailSend
- changed line 335 in : $confirmed = array($config->get('invoice_order_statuses', 'confirmed'));
(however, I don't know about this. Or is 'invoice_order_statuses' only for the 'pending' status? )

- changed line 341 in : if(empty($data->mail_name) || !in_array($data->mail_name, array('order_notification', 'order_creation_notification'))) like you said.

What am I doing wrong? I tried to send an email and invoice attachment using the email button on the backend for every status, but I still get no pdf, only an email.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 7 months ago #305633

Hi,

Yes, if you set created in the status override setting of the plugin, you don't need to change the line $confirmed = array($config->get('invoice_order_statuses', 'confirmed')); of the plugin as the override will be used.
And the other change looks good. So I don't see why it wouldn't work.
It should at least generate an error or something. That would require some debugging to see which condition prevents the plugin from adding the PDF.
In the plugin file, you have 4 conditions which can stop that process:

// Valid order type
		if(!empty($data->data->order_type) && $data->data->order_type != 'sale')
			return;
		// Valid email
		if(empty($data->mail_name) || !in_array($data->mail_name, array('order_status_notification', 'order_creation_notification')))
			return;
		// Valid status
		if(empty($data->data->order_status) || !in_array($data->data->order_status, $confirmed))
			return;
		//
		$invoice_id_required = $this->params->get('invoice_id_required', 0);
		if(empty($data->data->order_invoice_id) && !empty($invoice_id_required))
			return;
try removing the conditions one by one to see which one is blocking the process from adding the PDF.
Once you find the condition, that will help understand why it doesn't work.

The following user(s) said Thank You: mark78

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 1
5 years 7 months ago #305696

Fixed it!! Thanks a lot, Nicolas!

By removing this condition:

// Valid status
		if(empty($data->data->order_status) || !in_array($data->data->order_status, $confirmed))
			return;
		//

the pdf showed up.

Then for some reason the order number was missing in the file name. Retrieved it by substituting line 461:
$invoice_name = JText::sprintf('PDF_INVOICE', $data->data->order_invoice_number);
for:
$invoice_name = JText::_('INVOICE').'_'.$order->order_invoice_number;

The following user(s) said Thank You: fernando.alh

Please Log in or Create an account to join the conversation.

Time to create page: 0.064 seconds
Powered by Kunena Forum