1.0.8.20 - images directory
- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Re: 1.0.8.20 - images directory
https://github.com/CE-PhoenixCart/Phoen ... action.php
The hook-calls connected to the actions are here. Like Zipur said; you can use postAction to do stuff after the action have happened (in this case insertProuctAction or updateProductAction). You still have all the posted values, so you can almost just recreate the code in a hook and then modify it as you wish.
//Daniel
The hook-calls connected to the actions are here. Like Zipur said; you can use postAction to do stuff after the action have happened (in this case insertProuctAction or updateProductAction). You still have all the posted values, so you can almost just recreate the code in a hook and then modify it as you wish.
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
- zipurman
- Builder
- Posts: 540
- Joined: Tue Oct 13, 2020 5:20 pm
- Phoenix Version: v
- Has thanked: 93 times
- Been thanked: 162 times
Re: 1.0.8.20 - images directory
Okay, so the file admin/includes/segments/process_action.php has a line:PiLLaO wrote: ↑Tue Aug 01, 2023 11:51 am 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); }
Code: Select all
$admin_hooks->cat($hook_action);So for example, if you created a file /includes/hooks/admin/catalog/updateProduct.php with the following content:
Code: Select all
<?php
class hook_admin_catalog_updateProduct{
public function listen_updateProductAction(){
var_dump($_POST);
die();
}
}
You should have all of your data in the $_POST, so you can just do a SQL update as this is called after the action is done, so you'll just be overriding whatever changes you need to override after the initial action was already completed.
Once you have coded your update, removed the die() and the var_dump() and test. Add them back to test as needed.
Hope that helps
zipurman
-----------
-----------
-
PiLLaO
- Contributor
- Posts: 107
- Joined: Thu Nov 05, 2020 9:28 pm
- Phoenix Version: v1.1.0.6
- Has thanked: 53 times
- Been thanked: 11 times
Re: 1.0.8.20 - images directory
Thanks for both explains.
So, all hooks are called previous $admin_hooks->cat('postAction');
And them admin/includes/actions/catalog/ [insert_product.php, update_product.php] ??
Because, I'm confused.
Can I move the file before this piece of code in actions?
Because I can't move the file before save the image from $_FILES['tmp_name'], isn't it?
So, all hooks are called previous $admin_hooks->cat('postAction');
And them admin/includes/actions/catalog/ [insert_product.php, update_product.php] ??
Because, I'm confused.
Can I move the file before this piece of code in actions?
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);
}- zipurman
- Builder
- Posts: 540
- Joined: Tue Oct 13, 2020 5:20 pm
- Phoenix Version: v
- Has thanked: 93 times
- Been thanked: 162 times
-
PiLLaO
- Contributor
- Posts: 107
- Joined: Thu Nov 05, 2020 9:28 pm
- Phoenix Version: v1.1.0.6
- Has thanked: 53 times
- Been thanked: 11 times
Re: 1.0.8.20 - images directory
I just view the video, it's very useful.
But I still need a little help, when I said before
Using the code that you post my previously
If I use listen_postAction() I get empty $_FILES and $_POST, if I use listen_updateProductAction() I have all the data.
So I don't understand the order than happens hooks, insert/update_product, post_action to make work the code
But I still need a little help, when I said before
I was talking about admin/catalog.phpSo, all hooks are called previous $admin_hooks->cat('postAction');
Using the code that you post my previously
Code: Select all
class hook_admin_catalog_updateProduct{
// public function listen_updateProductAction(){
public function listen_postAction(){
global $products_id;
echo 'updateProductAction<br><br>';
echo '$products_id ' . $products_id . '<br>';
echo '<pre>';
var_dump($_FILES);
echo '</pre>';
echo '<pre>';
var_dump($_POST);
echo '</pre>';
die();
}
}So I don't understand the order than happens hooks, insert/update_product, post_action to make work the code
- zipurman
- Builder
- Posts: 540
- Joined: Tue Oct 13, 2020 5:20 pm
- Phoenix Version: v
- Has thanked: 93 times
- Been thanked: 162 times
Re: 1.0.8.20 - images directory
Forget about "postAction" as it is called to late. The problem is that in admin/includes/segments/process_action.php, There is a Href::redirect before "postAction", so the "postAction" is never called as the page re-directs before it has a chance.
listen_updateProductAction however is called before the Href::redirect, so you will want to use that to code in your changes and updates with the $_POST data and $_FILES data.
listen_updateProductAction however is called before the Href::redirect, so you will want to use that to code in your changes and updates with the $_POST data and $_FILES data.
zipurman
-----------
-----------
-
PiLLaO
- Contributor
- Posts: 107
- Joined: Thu Nov 05, 2020 9:28 pm
- Phoenix Version: v1.1.0.6
- Has thanked: 53 times
- Been thanked: 11 times
Re: 1.0.8.20 - images directory
I think I'm missing something.
I use this piece of code in catalog/test_upload.php and works like a charm
But If I use in hook, allways shows error
I use var_dump($_FILE) to see if data it's ok, and looks correctly but don't works.
Also I use
And use var_dump($products_image) $products_image['filename'] and $products_image['temp_filename'] are NULL
I don't know how make it works
I use this piece of code in catalog/test_upload.php and works like a charm
Code: Select all
$temp_file = $_FILES["products_image"]["tmp_name"];
$dest_path = '/home/public_html/catalog/images/productos/' . $_FILES["products_image"]["name"];
if (move_uploaded_file($temp_file , $dest_path )) {
echo "sucess: " . $ruta_destino;
} else {
echo "error.";
}Code: Select all
<?php
class hook_admin_catalog_updateProduct{
public function listen_updateProductAction() {
$temp_file = $_FILES["products_image"]["tmp_name"];
$dest_path = '/home/public_html/catalog/images/productos/' . $_FILES["products_image"]["name"];
if (move_uploaded_file($temp_file , $dest_path )) {
echo "sucess: " . $ruta_destino;
} else {
echo "error.";
}
}
}
Also I use
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);
}I don't know how make it works
- zipurman
- Builder
- Posts: 540
- Joined: Tue Oct 13, 2020 5:20 pm
- Phoenix Version: v
- Has thanked: 93 times
- Been thanked: 162 times
Re: 1.0.8.20 - images directory
Keep in mind that the listen_updateProductAction is being called AFTER the actual product update has already happened. This means any $_FILES have already been dealt with and are no longer available. However, you still have access to the $_FILES array, so you could do the following:
1. Check if the file exists in '/home/public_html/catalog/images/' . $_FILES["products_image"]["name"]
2. If the file does exist in the root images directory, move it to the /productos/ directory
3. If the file was moved, update the product sql to reflect the change.
1. Check if the file exists in '/home/public_html/catalog/images/' . $_FILES["products_image"]["name"]
2. If the file does exist in the root images directory, move it to the /productos/ directory
3. If the file was moved, update the product sql to reflect the change.
zipurman
-----------
-----------
-
PiLLaO
- Contributor
- Posts: 107
- Joined: Thu Nov 05, 2020 9:28 pm
- Phoenix Version: v1.1.0.6
- Has thanked: 53 times
- Been thanked: 11 times
Re: 1.0.8.20 - images directory
That's the problem!
File exists but move_uploaded_file() still show error, I think because "the actual product update has already happened" so I use rename() to move it.
I think now I can make it works, many thanks for your answers
File exists but move_uploaded_file() still show error, I think because "the actual product update has already happened" so I use rename() to move it.
I think now I can make it works, many thanks for your answers