Jump to content

[Solved] Specific action for deactivation of a product


Recommended Posts

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

 

Edited by Paliur (see edit history)
Link to comment
Share on other sites

  • Paliur changed the title to [Solved] Specific action for deactivation of a product

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...