Page 1 of 2

Images on Product Info pages - External URLs/ Links

Posted: Tue Dec 07, 2021 11:23 pm
by zeeshop
Hi,

I am exploring the possibility of using external Images URLs for product info pages along with local Images use as required.

I found most of the references which control images in several places, such as reference to 

Code: Select all

tep_image('images/'
by removing 'images/' External image URL can work,

But then the system is only looking for full URL and will not look for the Default images folder and many default settings may get affected.

I am wondering if there is any code I can use which can work with either possibility. for example, if images are stored and linked locally, it uses that, or if the external URL link is entered it use the external one.

For external image links, I will be using a bulk data upload system, just looking to adjust the code in the system which can accept both options. (External images are not subject to copyright and stored and used by my other site).

Thanks in advance.

Re: Images on Product Info pages - External URLs/ Links

Posted: Wed Dec 08, 2021 7:40 am
by LeeFoster
Where are you storing the URL? Are you adding an extra column in the table or using an existing one?

Re: Images on Product Info pages - External URLs/ Links

Posted: Wed Dec 08, 2021 8:20 am
by zeeshop
Basically intention is to display external images for products.
No column changes needed I think.
Only code change is needed, which can either display image from local folder or external URL.

Link of either local or external images will be uploaded via data update wizard which is great tool for bulk uploading and updating of products.

Re: Images on Product Info pages - External URLs/ Links

Posted: Wed Dec 08, 2021 8:59 am
by LeeFoster
zeeshop wrote: Wed Dec 08, 2021 8:20 am Basically intention is to display external images for products.
No column changes needed I think.
Only code change is needed, which can either display image from local folder or external URL.

Link of either local or external images will be uploaded via data update wizard which is great tool for bulk uploading and updating of products.
So you're wanting to store the URL in the image name field?

Re: Images on Product Info pages - External URLs/ Links

Posted: Wed Dec 08, 2021 9:19 am
by zeeshop
Yes, in the database column for images i.e products_image, the internal or external links can be easily entered, but it won't display on the product pages as code is set to only look for the internal images at present.
Hope that clarifies.

Re: Images on Product Info pages - External URLs/ Links

Posted: Wed Dec 08, 2021 3:44 pm
by LeeFoster
zeeshop wrote: Wed Dec 08, 2021 9:19 am Yes, in the database column for images i.e products_image, the internal or external links can be easily entered, but it won't display on the product pages as code is set to only look for the internal images at present.
Hope that clarifies.
You're going to want to re-write the code

Code: Select all

tep_image('images/'
Any where it appears with something like

Code: Select all

if (str_contains($products_image, 'www')) { 
tep_image($products_image
} else {
tep_image('images/'
}
I'm not sure the exact variable used for products_image as I'm not at my PC.

Re: Images on Product Info pages - External URLs/ Links

Posted: Wed Dec 08, 2021 5:18 pm
by zeeshop
Thanks, Much appreciated - You gave me some hope :)
But not being a coder still struggling to use it properly.

I may not be putting it in a right place properly.

for example,
The file is at /ext/scripts/ajax_buttons.php code, the original code calling image is as below:

Code: Select all

$_POST['image'] = tep_image('images/' . $product_info['products_image']);
By following and changing tep_image('images/' is not working, perhaps it need replacing in a different way.

On the other file at product_info.php the code which displays image is as below:

Code: Select all

new Image('images/' . $active_image['image'], ['alt' => htmlspecialchars( $active_image['htmlcontent'])])
and

Code: Select all

$first_img = new Image('images/' . $active_image['image'], ['alt' => htmlspecialchars($active_image['htmlcontent']), 'loading' => 'lazy']);
Could you please guide how the above few samples can be changed to work properly?

Once I know how to change the above sample code, I will be able to replace others, wherever they need changing.

Kind Regards,

Zee

Re: Images on Product Info pages - External URLs/ Links

Posted: Wed Dec 08, 2021 6:15 pm
by LeeFoster
zeeshop wrote: Wed Dec 08, 2021 5:18 pm Thanks, Much appreciated - You gave me some hope :)
But not being a coder still struggling to use it properly.

I may not be putting it in a right place properly.

for example,
The file is at /ext/scripts/ajax_buttons.php code, the original code calling image is as below:

Code: Select all

$_POST['image'] = tep_image('images/' . $product_info['products_image']);
By following and changing tep_image('images/' is not working, perhaps it need replacing in a different way.

On the other file at product_info.php the code which displays image is as below:

Code: Select all

new Image('images/' . $active_image['image'], ['alt' => htmlspecialchars( $active_image['htmlcontent'])])
and

Code: Select all

$first_img = new Image('images/' . $active_image['image'], ['alt' => htmlspecialchars($active_image['htmlcontent']), 'loading' => 'lazy']);
Could you please guide how the above few samples can be changed to work properly?

Once I know how to change the above sample code, I will be able to replace others, wherever they need changing.

Kind Regards,

Zee
Which version of Phoenix are you using?

Re: Images on Product Info pages - External URLs/ Links

Posted: Wed Dec 08, 2021 6:35 pm
by ecartz
LeeFoster wrote: Wed Dec 08, 2021 3:44 pm You're going to want to re-write the code

Code: Select all

tep_image('images/'
I would not do it there. If you do it there, you will have to maintain your own copies of every single file with a tep_image call in it plus files with new Image. Instead, override https://github.com/CE-PhoenixCart/Phoen ... L158..L176

Also, I would look for http rather than www, as http will appear in all URLs while www only appears in some. If you can, look for 'https://'. Because it is highly unlikely that a colon will appear in an image file name.

Code: Select all

if (Text::is_prefixed_by($this->get('src'), 'images/http')) {
  $this->set('src', Text::ltrim_once($this->get('src'), 'images/'));
} else {
// lines 158-176 here
}

Re: Images on Product Info pages - External URLs/ Links

Posted: Wed Dec 08, 2021 6:37 pm
by zeeshop
Hi,

Phoenix v1.0.8.8
PHP 7.4.25

Thanks