2

Magento does send an email to customer who registers for receiving email alert when a product comes back in stock. I noticed that email is not sent instant for only once a day.

Is it possible that email is sent to all the subscribed users as soon as the stock is updated from the backend?

3

I think the best way to solve your problem is setting the sending frequency higher. The sending frequency can be set from the backend (under System | Configuration | Catalog | Catalog | Product Alerts Run Settings), but only to once a day, once a week or once a month.

Now, if you look in Mage_Adminhtml_Model_System_Config_Backend_Product_Alert_Cron, you'll see that that's where the cron expression gets built and saved into the database in core_config_data.

You could modify this behaviour and create an extension that modifies the available dropdown values in the backend. You should add rewrites for Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency to add the options and Mage_Adminhtml_Model_System_Config_Backend_Product_Alert_Cron to build the corresponding cron expressions.

A quick way to change the behaviour, is to edit the record with path crontab/jobs/catalog_product_alert/schedule/cron_expr in the table core_config_data. Most probably you'll find a record in the table with a value like 0 1 * * * (of not, enable product alerts in the backend, change the running time and save the section). You could edit it to match your needs, for instance 0 * * * * to send the alerts every hour. Beware that if you save the settings for the Catalog | Catalog section again in the backend, the custom settings you saved in the database are lost so you should only use this as a temporary solution.

1

Before providing a possible solution I want to say: "DON'T DO IT". If you take this approach and have n-hundred users subscribed to a product then the save process on the product has to wait for n-hundred e-mails to be sent. This will make the product management a living hell. Also if you decide to put in stock X products (X > 1) in a short period of time and a customer is subscribed for alert on all those products, he will receive X e-mails in a few minutes. That becomes annoying and he will never subscribe again.
I think the best approach here, if you want to sent e-mails more than once a day is to make the cron run every hour, or every X hours. (not the same X as above).
But here is a possible solution to what you want. You need to create an observer on the catalog_product_save_after event.
Add this in the config.xml of your module

<adminhtml>
    <events>
        <catalog_product_save_after>
            <observers>
                <[moudle]>
                    <class>[module]/observer</class>
                     <method>checkStockChange</method>
                </[module]>
            </observers>
        </catalog_product_save_after>
    </events>
</adminhtml>

Now create the observer: app/code/local/[Namespace]/[Module]/Model/Observer.php

<?php 
class [Namespace]_[Module]_Model_Observer extends Mage_ProductAlert_Model_Observer{
//it must extend Mage_ProductAlert_Model_Observer so you won't duplicate code
    public function checkStockChange($observer){
        $product = $observer->getEvent()->getProduct();
        $stock = $product->getStockItem();
        if ($stock->getIsInStock() == 1 && $stock->getOrigData('is_in_stock') == 0){
            $this->_processStock( Mage::getModel('productalert/email'));
        }
    }
}

This will send out all the e-mails for all the products that come back in stock, but since you are calling this when each product that comes back in stock, then only that product should be processed.
And in case you missed it at the top of this answer, here it is again: DON'T DO IT

  • I did not do it :) I understood this would freeze the product saving screen and used the other way suggested above. – tanay jha Nov 13 '13 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.