Page 1 of 2

1.0.8.20 - images directory

Posted: Fri Jul 28, 2023 9:56 am
by PiLLaO
Hi!

I'm using v1.0.8.20

I need to choose the directory to upload images (separated by manufacturer).

I just make a file in catalog/admin/includes/hooks/admin/catalog/ to add the input to choose the folder, but I don't know where create the file to change the image path.

I look that this file catalog/admin/includes/actions/catalog/update_product.php save the product data to DB

Need to override this file?
Is there a better way to do this?

Thanks in advance.

Re: 1.0.8.20 - images directory

Posted: Fri Jul 28, 2023 12:18 pm
by raiwa
Admin actions can't be overridden and as far as I see there is no hook which allows to manipulate the image path and database entry.
I believe you would need to use a copy of that action and call it in a copy of the views/new_product.php file.
Maybe best a custom catalog.php file to which you redirect in a hook. Then you can use there your custom view and action file.

Re: 1.0.8.20 - images directory

Posted: Sat Jul 29, 2023 4:28 am
by zipurman
You could just write an admin hook to listen_postAction and then update the image as required as your custom field should be in the $_POST. The original update that catalog/admin/includes/actions/catalog/update_product.php does, would be done first, and then listen_postAction would allow you to update again, but with the desired image path data?

Re: 1.0.8.20 - images directory

Posted: Sat Jul 29, 2023 6:39 am
by raiwa
But the image file would still be saved in the original location “images/“. Or do I miss something?

Re: 1.0.8.20 - images directory

Posted: Sat Jul 29, 2023 6:41 am
by zipurman
You could move the file in the same hook.

Re: 1.0.8.20 - images directory

Posted: Sat Jul 29, 2023 6:44 am
by zipurman
BTW, the following addon has this functionality and more.

app.php/addons/paid_addon/zipur_product_manager

Re: 1.0.8.20 - images directory

Posted: Sat Jul 29, 2023 7:02 am
by raiwa
Thinking more about the original question and my first answer:
You could rename the action in a redirect hook from "update_product" to "custom_update_product" and then use a copy of the action file with your modifications. This would be the most similar to override the action.

Preston's method may be less core invasive and therefore more stable regarding core updates.

Re: 1.0.8.20 - images directory

Posted: Sun Jul 30, 2023 11:08 am
by 14Steve14
Is this the sort of thing you are after.

viewtopic.php?p=12310#p12310

Re: 1.0.8.20 - images directory

Posted: Sun Jul 30, 2023 11:11 am
by 14Steve14
14Steve14 wrote: Sun Jul 30, 2023 11:08 am Is this the sort of thing you are after.

viewtopic.php?p=12310#p12310
No idea whether it was ever released as an addon though.

Re: 1.0.8.20 - images directory

Posted: Tue Aug 01, 2023 11:51 am
by PiLLaO
zipurman wrote: Sat Jul 29, 2023 4:28 am You could just write an admin hook to listen_postAction and then update the image as required as your custom field should be in the $_POST. The original update that catalog/admin/includes/actions/catalog/update_product.php does, would be done first, and then listen_postAction would allow you to update again, but with the desired image path data?
How can I know the products listener? Because if I search in files for listen_postAction I can't find anything.

I'm having problems to make It works, and I see that I don't know where need to put the code to make it works (listener are new for my).

The easyest way, will be modify the path here (set_destination)

Code: Select all

  $products_image = new upload('products_image');
  $products_image->set_destination(DIR_FS_CATALOG_IMAGES);
  if ($products_image->parse() && $products_image->save()) {
    $sql_data['products_image'] = Text::prepare($products_image->filename);
  }