How to display product image in invoice?

  • Posts: 356
  • Thank you received: 7
  • Hikashop Business
1 year 8 months ago #343667

Hi,

Yes I can confirm the path to the image is correct and the image is there. If the image is not there the error message is different.

Thanks

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 8 months ago #343668

Hi,

Then how about trying with the URL of the image instead of the relative path ?

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

  • Posts: 356
  • Thank you received: 7
  • Hikashop Business
1 year 8 months ago #343716

Hi,

I'm using the code you pasted here earlier in this thread

<?php
		$imageHelper = hikashop_get('helper.image');
		if(!empty($product->images[0]->file_path) && $config->get('thumbnail', 1) != 0) {
			$img = $imageHelper->getThumbnail($product->images[0]->file_path, array(50, 50), array('forcesize' => true, 'scale' => 'outside'));
			if($img->success) {
				echo '<img src="'.$img->url.'" alt="" style="float:left;margin-top:3px;margin-bottom:3px;margin-right:6px;"/>';
			}
		} ?>

I believe that does use the URL of the image - how would I change that to use the relative path?

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 8 months ago #343721

Hi,

The variable $img->url should normally contains something like that:
"/images/com_hikashop/upload/thumbnails/100x100f/myimage.jpg"
That' a relative path. So you already are using a relative path.
What's before the first / is filled by the browser (or the HTML2PDF library in this instance).
So what you can do is prepend the URL of the website so that you force it to use the full URL instead of letting it guess it.
So for example, instead of:

echo '<img src="'.$img->url.'" alt="" style="float:left;margin-top:3px;margin-bottom:3px;margin-right:6px;"/>';
you could try:
echo '<img src="https://www.mywebsite.com'.$img->url.'" alt="" style="float:left;margin-top:3px;margin-bottom:3px;margin-right:6px;"/>';
Of course, this is an example. You need to replace www.mywebsite.com by your real website URL.
And that's just what I remember from memory.
The best would be to first directly echo the variable $img->url to see what's inside so that you can prepend what's needed accordingly.

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

  • Posts: 356
  • Thank you received: 7
  • Hikashop Business
1 year 8 months ago #343726

HI,

Thanks for the reply.

This produces the same result.

I echo the result to make sure the URL was formed correctly etc but still the same issue?

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 8 months ago #343727

Hi,

Can you provide an example of URL that was generated for a thumbnail ?
If you can open it with your browser and see the image, then it means that the URL is correct. In that case, it means there is a problem with the server settings preventing PHP from accessing URLs (most likely with allow_url_fopen : www.a2hosting.com/kb/developer-corner/ph...-url-fopen-directive ).
If you can't open the URL with the browser, then there is a problem with the URL itself.

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

  • Posts: 356
  • Thank you received: 7
  • Hikashop Business
1 year 8 months ago #343729

Hi,

allow_url_fopen is tunred on yes (see attached)



Yes you can access the images if you go to the resulting URL, they work fine.

Example URL

www.totalfootballdirect.com/images/com_h...c_academy_bundle.png

Or tried:

/images/com_hikashop/upload/thumbnails/50x50sO/fitc_academy_bundle.png

Thank you

Attachments:

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 8 months ago #343730

Hi,

As I said, if the URL added in the invoice is correct, then if you get an error about it, it normally means that the HTML2PDF library was not able to get the image. It could be an issue with allow_url_fopen, but it could be something else. For example, a rule in your web server configuration preventing some user-agent from accessing files (to prevent bots from accessing them), or a similar rule in a htaccess file.

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

  • Posts: 356
  • Thank you received: 7
  • Hikashop Business
1 year 8 months ago #343777

Hi,

I have checked .htaccess, this is not the issue. The hosts ask what "user-agent" could be preventing the access? So they can try to trace the issue.

You can access the image via the URL so not sure why you think its not accessible?

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 8 months ago #343780

Hi,

It's quite common to block user agents on web servers :
techexpert.tips/apache/apache-blocking-user-agent-access/
Most security extensions for Joomla usually have some mechanism to filter user-agents.
There are also security rules for htaccess files to block user-agents for Joomla:
gist.github.com/uzielweb/11997372b325d38218b0b28bc90062ea
The library used by the plugin to generate the PDF is called TCPDF. It uses file_get_contents to get the data of each image without sepcifying a user-agent. In that case, either PHP will use the user-agent specified in the php.ini or won't send any user-agent:
www.php.net/manual/en/context.http.php

Value to send with User-Agent: header. This value will only be used if user-agent is not specified in the header context option above.

By default the user_agent php.ini setting is used

So I can't say what user-agent is used as it depends on the way your server is setup. What's sure is that it's quite likely different from what a browser sends and could explain why TCPDF is unable to load the image while a browser loads it fine.

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

  • Posts: 356
  • Thank you received: 7
  • Hikashop Business
1 year 8 months ago #343806

HI Nicolas,

Thanks for the info - I went back to the hosting company which they have replied with:

Thanks for waiting, We've had a look on our side and we cannot see any issues with the server itself. The permissions and ownerships of the files and folders have also been looked at but this doesn't look to be due to the server or platform.

Whats ODD is now it works - so someone did something lol - thanks for your help.

Last edit: 1 year 8 months ago by grayt7.
The following user(s) said Thank You: Philip

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

Time to create page: 0.075 seconds
Powered by Kunena Forum