Hhow to customize Product Image upload code?

  • Posts: 3
  • Thank you received: 0
3 years 5 months ago #334459

-- HikaShop version -- : 4.4.3
-- Joomla version -- : 3.9.27
-- PHP version -- : 8.0.7
-- Browser(s) name and version -- : chrome
-- Error-message(debug-mod must be tuned on) -- : How to add manual code for product image upload?

when the image is uploaded from hikahop product admin I want to upload this image at a custom path instead of the default hikashop image upload path.

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
3 years 5 months ago #334463

Hi,

You could just change the "upload folder" of the HikaShop configuration to where you want the images to be uploaded instead of the default folder.

Now, to answer your question, supposing that you want to override this setting with a dynamic path, I would recommend you to do it by developing a system plugin. In it, you could implement the onAfterRoute event of Joomla. In there, you would include_once the main helper.php file of HikaShop ( administrator/components/com_hikashop/helpers/helper.php) and then force the upload path with such code:

$config = hikashop_config();
$config->set('uploadfolder', 'xxx');
where xxx is the path you want instead of the one set in the config.

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

  • Posts: 3
  • Thank you received: 0
3 years 5 months ago #334480

$config = hikashop_config();
$config->set('uploadfolder', 'xxx');
where xxx is the path you want instead of the one set in the config.[/quote]

Ok so with this code I can change default image upload path. What I want is when one image upload from product image upload admin I want create three different images with different resolution like(large,medium,small) and it to their respective paths like large image store in pics/large folder and medium image is stored in pics/medium folder like this. In short I want to customize the product admin image upload code. Is it possible?

Last edit: 3 years 5 months ago by dixit.

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
3 years 5 months ago #334482

Hi,

In that case, you could create a plugin of the group "hikashop" and implement the event onAfterFileCreate(&$file)
This method of your plugin will be called each time a new file is created (be it an image or a file). Then, in $file you'll have the file_type that you can check so that you process only images. And the file_path attribute will contain the relative path of the file in the upload folder. From that, you can load the image, resize it and save the result where you want.

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

  • Posts: 3
  • Thank you received: 0
3 years 5 months ago #334521

nicolas wrote: Hi,

In that case, you could create a plugin of the group "hikashop" and implement the event onAfterFileCreate(&$file)
This method of your plugin will be called each time a new file is created (be it an image or a file). Then, in $file you'll have the file_type that you can check so that you process only images. And the file_path attribute will contain the relative path of the file in the upload folder. From that, you can load the image, resize it and save the result where you want.


Ok, this is working fine. but if I will delete the uploaded image from the product admin then how can I delete the other images which were created from that image by onAfterFileCreate(&$file) method of the plugin.

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
3 years 5 months ago #334524

Hi,

We do have the event onAfterFileDelete for that.
However, looking at the file there, I can see a problem with how we've added it previously.
The first parameter is an array of ids, but the entries are already removed from the database by that point.
So that won't help.
To fix that, you need to change the line:

$app->triggerEvent('onAfterFileDelete', array( &$pkeys, &$type ));
to:
$app->triggerEvent('onAfterFileDelete', array( &$oldEntries ));
in the file administrator/components/com_hikashop/classes/file.php
That way, in $oldEntries you'll get an array of the files that were just deleted (we'll remove the $type variable since each element of the array has a file_type with its type).
We'll include that modification in the next version of HikaShop and we'll also add a onBeforeFileDelete in that same deleteFiles function.

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

Time to create page: 0.066 seconds
Powered by Kunena Forum