PDF Invoice Plugin not working

  • Posts: 15
  • Thank you received: 0
9 years 8 months ago #191980

-- HikaShop version -- : 2.2.2
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.4.37
-- Browser(s) name and version -- : Chrome 40.0.2214.115 m

Hi,

I have installed the PDF Invoice Plugin and in the plugin settings I have set the "Statuses for email attachment" to "confirmed" and all other settings are at default.

With this plugin enabled, when an order is successfully paid for through Paypal, the customer does not receive the order confirmation email and no payment confirmation email is received by the site administrator. The order creation email is received every time though. If I turn the PDF Invoice plugin off, then all emails are received fine.

When I go to the back end and generate an invoice by clicking the invoice button in the order detail screen, the popup that opens to display the PDF invoice displays a partly formed invoice only. I am attaching a screen shot of that popup.

Also, I do not find any invoice generated in the /plugins/hikashop/attachinvoice/attachinvoice/invoices directory. It seems that the plugin is not able to create the PDF invoice as a result of which the order confirmation email does not get sent out at all to the customer and neither does the payment confirmation email gets sent out to the administrator.

Thanks in advance for your help in resolving this.

UPDATE:

I notice that if I comment out the following code in /plugins/hikashop/attachinvoice/attachinvoice/invoice.php then everything works fine and the confirmation and payment notification mails get sent out (though obviously the Billing and Shipping addresses do not get printed in the attached invoice):

<fieldset>

<legend><?php echo JText::_('HIKASHOP_'.strtoupper($oneAddress)); ?></legend>

<?php

$override = false;

if(!empty($order->order_shipping_id) && $oneAddress=='shipping_address' && method_exists($currentShipping, 'getShippingAddress')) {

$override = $currentShipping->getShippingAddress($order->order_shipping_id);

}

if($override !== false ) {

echo $override;

} else {

$addressClass = hikashop_get('class.address');

if($app->isAdmin()){

$view = 'order';

}else{

$view = 'address';

}

echo $addressClass->displayAddress($order->fields,$order->$oneAddress,$view);

}

?>

</fieldset>

Attachments:
Last edit: 9 years 8 months ago by rdpaul. Reason: Further information added to the problem

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

  • Posts: 26146
  • Thank you received: 4026
  • MODERATOR
9 years 8 months ago #191997

Hi,

I think you should have a PHP error due to a too old HikaShop version.
The function "displayAddress" is not available in HikaShop 2.2.2 ; you should update to the last one (2.3.5)
www.hikashop.com/support/documentation/5...ashop-changelog.html

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 15
  • Thank you received: 0
9 years 8 months ago #192021

Hi Jerome,

Thanks for your reply.

Unfortunately, I have inherited the current site from a previous developer and I cannot risk a Hikashop update because of the fact that the code is heavily customized.

Meantime I have found a replacement for the offending displayAddress() function call and am giving it here in case some one else can benefit from it.

if($override !== false ) {

	echo $override;

} else {

	/* The following block to be commented out
	$addressClass = hikashop_get('class.address');

	if($app->isAdmin()){

		$view = 'order';

	}else{

		$view = 'address';

	}
	echo $addressClass->displayAddress($order->fields,$order->$oneAddress,$view);
	*/


	/*Add the following block to replace the above*/

	$html = hikashop_getLayout('address','address_template',$params,$js);

	if(!empty($order->fields)){

		foreach($order->fields as $field){

			$fieldname = $field->field_namekey;

			
			if(!empty($order->$oneAddress->$fieldname)) $html=str_replace('{'.$fieldname.'}',$fieldsClass ->show($field,$order->$oneAddress->$fieldname),$html);

		}

	}

	echo str_replace("\n","<br/>\n",str_replace("\n\n","\n",preg_replace('#{(?:(?!}).)*}#i','',$html)));

	   /*End of new lines added*/
}
	
Besides the above change you will also need to add one more line before the foreach loop which processes the addresses. 

/*Add the following ONE line*/
$fieldsClass = hikashop_get('class.field');

foreach($addresses as $oneAddress){ .............................


Thanks for your help and for a super component.

Last edit: 9 years 8 months ago by rdpaul.

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

  • Posts: 15
  • Thank you received: 0
9 years 8 months ago #192060

Hi,

A further update to my earlier message. After changing the code as mentioned earlier, my customers are able to receive confirmation emails along with the attached PDF invoice. Now I am facing two new problems as follows:

1. In spite of setting Override Front End and Back End to Yes in the plugin parameters, my Print button for the invoice on the front end is not overridden. I still get to see the regular invoice (not the PDF version) when I click Print button in the order detail screen on the front end. Is there some other way for the customer to be able to download a PDF version of the invoice on the front end?

2. In the Back End, when I click the Invoice button I momentarily get to see part of the PDF invoice being rendered and then immediately in less than a second the page redirects to www.mysite/adminsitrator/index.php .

I can't figure out why this is happening. Any help will be much appreciated.

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

  • Posts: 82683
  • Thank you received: 13337
  • MODERATOR
9 years 8 months ago #192116

Hi,

1. This function requires a trigger that didn't exist on HikaShop 2.2.2 which is why it doesn't work.
The solution is to edit the file "show" of the view "order" for your frontend template via the menu Display>Views and add such code at the top:

<?php
			JPluginHelper::importPlugin('hikashop');
			$dispatcher = JDispatcher::getInstance();
			$dispatcher->trigger('onHikashopBeforeDisplayView', array(&$this)); 
?>

2. Same problem. You're using an old version of HikaShop which is not compatible with that.
Add the same code in the file 'invoice' of the view 'order' for your backend template via the menu Display>Views.

The following user(s) said Thank You: rdpaul

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

  • Posts: 15
  • Thank you received: 0
9 years 8 months ago #192319

Hi,

Thanks for your reply but unfortunately the changes suggested by you are not solving the problem.

I have followed your instructions and have made overrides in both the front end and back end files suggested by you.

Now when I click the Print button to print the invoice in the front end, I get to see a new page loading up (earlier the override was not working at all and I was just seeing the non-pdf version of the invoice only) but the page is totally blank with just the following error message: "TCPDF ERROR: Some data has already been output to browser, can't send PDF file".

As regards the back end, the problem remains the same as before. A partly rendered version of the PDF invoice loads up for a second and then the page redirects to www.mysite/adminsitrator/index.php .

My apologies for not being able to update to the latest version of Hikashop. Will greatly appreciate if you can find a workaround for my situation.

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

  • Posts: 82683
  • Thank you received: 13337
  • MODERATOR
9 years 8 months ago #192352

Hi,

That error indicates that something has already started displaying. Did you put the code completely at the top, without an space before it ?

For the backend, maybe it requires something else in the code of HikaShop to handle the toolbar behavior properly. I don't remember. Honestly, an update would be recommended here.
You can copy the website somewhere else and try the update on the copy and see what you lost. Nomally, if the previous developer did things right like we usually recommend, he should have used view overrides, translation overrides CSS overrides and plugins and not modify the HikaShop core files directly.

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

  • Posts: 15
  • Thank you received: 0
9 years 8 months ago #192453

Thank you Nicolas for all your effort. I understand what you are saying and will see what I can do.

Can you just help me with the following code that I have changed in /plugins/hikashop/attachinvoice/attachinvoice/invoice.php to display addresses in my invoice (because $addressClass->displayAddress is not available to be used in Hikashop 2.2.2). This code is working fine on the front end but it is causing problem while displaying an address when the invoice is to be printed from the back end. If I comment out printing addresses altogether from the invoice then it works on the back end also.

How can I make printing of the addresses possible on both front end and back end without using $addressClass->displayAddress?

The code that I am talking about is as under.

/*The following block commented out
$addressClass = hikashop_get('class.address');

if($app->isAdmin()){

	$view = 'order';

}else{

	$view = 'address';

}
echo $addressClass->displayAddress($order->fields,$order->$oneAddress,$view);
*/


/*The following block added to replace above but DOES NOT WORK ON BACK END*/

$html = hikashop_getLayout('address','address_template',$params,$js);

if(!empty($order->fields)){

	foreach($order->fields as $field){

		$fieldname = $field->field_namekey;

		
		if(!empty($order->$oneAddress->$fieldname)) $html=str_replace('{'.$fieldname.'}',$fieldsClass ->show($field,$order->$oneAddress->$fieldname),$html);

	}

}

$html = str_replace("\n","<br/>\n",str_replace("\n\n","\n",preg_replace('#{(?:(?!}).)*}#i','',$html)));
echo str_replace("<br />\r<br/>","<br/>",$html);

Thanks again for your help and patience.

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

  • Posts: 82683
  • Thank you received: 13337
  • MODERATOR
9 years 8 months ago #192480

Hi,

Your issue is that line of code:
$html = hikashop_getLayout('address','address_template',$params,$js);
That will only work on the frontend as there is no such view in the backend.
In the backend, you should use that code instead:
$html = hikashop_getLayout('order','address_template',$params,$js);

So you can do like that:
$app = JFactory::getApplication();
if($app->isAdmin()){
$html = hikashop_getLayout('order','address_template',$params,$js);
}else{
$html = hikashop_getLayout('address','address_template',$params,$js);
}

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

  • Posts: 15
  • Thank you received: 0
9 years 8 months ago #192501

That works great! Thanks a ton. Your component is the best and your support is matchless.

Have a great day.

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

Time to create page: 0.069 seconds
Powered by Kunena Forum