'Prestashop 1.7 Mail Alerts cron task

I need to create a cron task of Mailalert to I can force it to run when I update stock. Products stock is updated via API and emails are not sent to customers when the product is available again.

Anyone know how I can create a cron task that launches the mailalert process? Regards.



Solution 1:[1]

ps_emailalerts module is sending notification e-mails through Prestashop hooks (including the stock update one - hookActionUpdateQuantity) , so first I would investigate if there is a way to trigger those hooks during your API calls.

If not, I would consider keeping a list of the ID products "touched" by your API, and build a simple script to call the StockAvailable::setQuantity() method on those ID products asynchronously.

This will trigger the ps_emailalerts ActionUpdateQuantity hook for sending out of stock email if needed.

Solution 2:[2]

The ps_emailAlerts module is working based on the hooks. For example, after the hookActionUpdateQuantity is fired, the modules checks the new stock value, and send email if needed.

You're using the prestashop webservice to update the stocks via API, or are you created your own method? If you have created your own method for it, you just need to add the following code:

Hook::exec(
                            'actionUpdateQuantity',
                                    [
                                        'id_product' => $id_product,
                                        'id_product_attribute' => $id_product_attribute,
                                        'quantity' => $quantity,
                                        'id_shop' => $id_shop,
                                    ]
                        );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3256843
Solution 2 KoreLewi