Use custom field image like the product image field

  • Posts: 20
  • Thank you received: 0
2 years 2 months ago #339473

-- HikaShop version -- : 4.4.5
-- Joomla version -- : 4.1
-- PHP version -- : 7.4
-- Browser(s) name and version -- : Firefox

Hi,
I need to implement 2 sets of images for product display (in 2 different places). I don't know in advance how many images there will be in each set.
For the first set of images, I can use the normal product image field.
For the second image set, I investigated the custom field image (AJAX) that allows backend users to upload and delete images. The issue is that I cannot use the images form that field in my template overrides like the normal images. I have custom code that uses

$this->image->getThumbnail(@$secondaryImage, array('width' => 2000, 'height' => 2000), $image_options);
to build urls and create thumbnails for responsive images (using srcset).

The main issue I have is that the images from the custom field are uploaded to the safe folder and it is protected with the .htaccess
Is there a way to upload these images to the images\com_hikashop\upload folder instead ?
That would allow me to create thumbnails and use them in my template overrides like the normal product image field.

If there is another way to manage multiple sets of images that I overlooked (without custom fields) I would be happy to try. The most user friendly solution would be to duplicate the normal product image field but I have no Idea if it is possible.

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

  • Posts: 81513
  • Thank you received: 13068
  • MODERATOR
2 years 2 months ago #339475

Hi,

Supposing that you don't use the "Files" area of the products, what you can do is to force the variables $this->image->uploadFolder_url and $this->image->uploadFolder to point to the secure folder where you have the htaccess file before calling $this->image->getThumbnail for the secondary images, and modify that htaccess file to allow access to it.

Another solution would be to generate the URL of the image yourself like this:

echo hikashop_completeLink('order&task=download&field_table=product&field_namekey='.urlencode(base64_encode('xxx')).'&name='.urlencode(base64_encode($secondaryImage)).'&thumbnail_x=2000&thumbnail_y=2000');
where xxx is the column name of the custom field and $secondaryImage the filename stored in the custom field.
This URL will go through HikaShop to check that the image can be accessed and then sent back to the browser, with resizing if necessary.

The following user(s) said Thank You: web-tiki

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

  • Posts: 20
  • Thank you received: 0
2 years 2 months ago #339491

Hi Nicolas,

Thanks for that info, I have managed to test both approaches.
The first one forcing $this->image->uploadFolder_url and $this->image->uploadFolder seems the best for my use case as it allows me to build all the thumbnails I need (.webp for example) and use the same approach for all images.

I see the thumbnails are generated inside the safe folder. Is there a way to force the thumbnails to be generated in the same folder as "normal images" ?
If not, how should I modify the .htaccess file to allow access to the thumbnail folder. For now I deleted the .haccess file to test.

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

  • Posts: 81513
  • Thank you received: 13068
  • MODERATOR
2 years 2 months ago #339497

Hi,

If you delete the htaccess file, HikaShop will add it back each time you update HikaShop.
So it's not a long term solution.
The best is to edit the htaccess file and change its code. In it, you'll have a line:
deny from all
You want to change it to :
allow from all

The following user(s) said Thank You: web-tiki

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

  • Posts: 2
  • Thank you received: 0
3 months 1 week ago #358216

Hi, may I have the example code with the solution above? Because I tried it, and it shows undefined function for hikashop_completeLink.

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

  • Posts: 81513
  • Thank you received: 13068
  • MODERATOR
3 months 1 week ago #358255

Hi,

That code is fine. If you get an error "undefined function hikashop_completeLink", it means that this code runs somewhere where HikaShop is not loaded.
In that case, you first need to load the HikaShop main helper file:

if(!@include_once(rtrim(JPATH_ADMINISTRATOR,'/').'/components/com_hikashop/helpers/helper.php')){ return false; }
www.hikashop.com/support/documentation/6...umentation.html#code

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

  • Posts: 2
  • Thank you received: 0
3 months 1 week ago #358268

Hi. After load the HikaShop main helper file, the code can works. Thanks a lot.

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

Time to create page: 0.077 seconds
Powered by Kunena Forum