Jump to content

Edit History

Paliur

Paliur

Hello to all, 

I am just starting to develop modules for prestashop. I know very little about the CMS at the moment. 

I have two questions to ask you: 

- Is it possible to define a new action when a product goes from "Active" to "Inactive"? Example, send an email. 
For example, at the moment I can trigger an event (and therefore send this email) when a product is updated thanks to the hook :

actionObjectProductUpdateAfter

But if the product is inactive, every time you click on "SAVE" in product admin page.
I would really like the email to be sent only if the product BECOMES inactive.

This brings me to my second question: 

- Is it possible to use the result of an action of a first Hook IN the action of a second Hook?
Indeed, the idea would be to get the "$poduct->active" in the actionObjectProductUpdateBefore hook, in order to compare it to the "$poduct->active" of the actionObjectProductUpdateAfter hook.

If so, how do you advise me to proceed in order to respect the good practices?

Here is my little piece of code :

public function hookActionObjectProductUpdateAfter($params)
    {
        $product = $params['object'];

        if (!$product->active && $product->id) {
            $emails = ['[email protected]', '[email protected]'];
            foreach ($emails as $email) {
                Mail::send(
                    (int)(Configuration::get('PS_LANG_DEFAULT')),
                    'myCustomMailTemplate',
                    'Test Mail',
                    array(
                        '{email}' => '[email protected]',
                        '{title}' => 'mail test',
                        '{message}' => 'test message.'
                    ),
                    $email,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    _PS_MODULE_DIR_ . 'mycustommodule/mails'
                );
            }
        }
    }


Thank you in advance for your help.


Prestashop 1.7.8.8

Florian

 

Paliur

Paliur

Hello to all, 

I am just starting to develop modules for prestashop. I know very little about the CMS at the moment. 

I have two questions to ask you: 

- Is it possible to define a new action when a product goes from "Active" to "Inactive"? Example, send an email. 
For example, at the moment I can trigger an event (and therefore send this email) when a product is updated thanks to the hook :

actionObjectProductUpdateAfter

But if the product is inactive, every time you click on "SAVE" in product admin page.
I would really like the email to be sent only if the product BECOMES inactive.

This brings me to my second question: 

- Is it possible to use the result of an action of a first Hook IN the action of a second Hook?
Indeed, the idea would be to get the "$poduct->active" in the actionObjectProductUpdateBefore hook, in order to compare it to the "$poduct->active" of the actionObjectProductUpdateAfter hook.

If so, how do you advise me to proceed in order to respect the good practices?

Here is my little piece of code :

public function hookActionObjectProductUpdateAfter($params)
    {
        $product = $params['object'];

        if (!$product->active && $product->id) {
            $emails = ['[email protected]', '[email protected]'];
            foreach ($emails as $email) {
                Mail::send(
                    (int)(Configuration::get('PS_LANG_DEFAULT')),
                    'myCustomMailTemplate',
                    'Test Mail',
                    array(
                        '{email}' => '[email protected]',
                        '{title}' => 'mail test',
                        '{message}' => 'test message.'
                    ),
                    $email,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    _PS_MODULE_DIR_ . 'mycustommodule/mails'
                );
            }
        }
    }


Thank you in advance for your help.


Prestashop 1.7.8.8

Florian

 

Paliur

Paliur

Hello to all, 

I am just starting to develop modules for prestashop. I know very little about the CMS at the moment. 

I have two questions to ask you: 

- Is it possible to define a new action when a product goes from "Active" to "Inactive"? Example, send an email. 
For example, at the moment I can trigger an event (and therefore send this email) when a product is updated thanks to the hook :

actionObjectProductUpdateAfter

But if the product is inactive, every time you click on "SAVE" in product admin page.
I would really like the email to be sent only if the product BECOMES inactive.

This brings me to my second question: 

- Is it possible to use the result of an action of a first Hook IN the action of a second Hook?
Indeed, the idea would be to get the "$poduct->active" in the actionObjectProductUpdateBefore hook, in order to compare it to the "$poduct->active" of the actionObjectProductUpdateAfter hook.

If so, how do you advise me to proceed in order to respect the good practices?

Here is my little piece of code :

public function hookActionObjectProductUpdateAfter($params)
    {
        $product = $params['object'];

        if (!$product->active && $product->id) {
            $emails = ['[email protected]', '[email protected]'];
            foreach ($emails as $email) {
                Mail::send(
                    (int)(Configuration::get('PS_LANG_DEFAULT')),
                    'myCustomMailTemplate',
                    'Test Mail',
                    array(
                        '{email}' => '[email protected]',
                        '{title}' => 'mail test',
                        '{message}' => 'test message.'
                    ),
                    $email,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    _PS_MODULE_DIR_ . 'mycustommodule/mails'
                );
            }
        }
    }


Thank you in advance for your help.


Prestashop 1.7.8.8

Florian

 

×
×
  • Create New...