7

I am trying to set up a script to send out daily emails to my admin to let them know what went out of stock that day only.

It doesn't need to be anything fancy, perhaps even writing items to a text file as products go out of stock until the end of a day when that text files is sent out as an email and cleared for the next day?

Thanks!

  • 1
    Did you find an answer here? If yes, please mark it as solution. – Fabian Blechschmidt May 8 '13 at 14:09
8

Aside from the built-in RSS feed, there are two ways to actually send yourself an email - the actual answer to your actual question:

Purchase an extension:

I have no experience with this extension, but was mentioned on a StackOverflow:

http://www.magentocommerce.com/magento-connect/irzoo-lowstockreport-1278.html

Do it yourself:

Create an observer for cataloginventory/stock_item - on the save event. All models have save events provided by Mage_Core_Model_Abstract. On save, it will call your observer, you can examine the stock level at that point.

<global>
    <events>
        <cataloginventory_stock_item_save_after>
            <observers>
                <mymodule_stock_item_save>
                    <type>singleton</type>
                    <class>yourmodel/observer</class>
                    <method>lowStockReport</method>
                </mymodule_stock_item_save>
            </observers>
        </cataloginventory_stock_item_save_after>
    </events>
</global>

Observer.php:

<?php

class MyCompany_MyModule_Model_Observer
{
    public function lowStockReport($observer)
    {
        $event = $observer->getEvent();
        $stockItem = $event->getItem();

        if($stockItem->getQty() < $stockItem->getNotifyStockQty()){

            //stock is lower than the notify amount, send email

            $product = Mage::getModel('catalog/product')->load($stockItem->getProductId());

            $body = "{$product->getName()} :: {$product->getSku()} just Ran out of stock:\n\n";
            $body .= "Current Qty: {$stockItem->getQty()}\n";
            $body .= "Low Stock Date: {$stockItem->getLowStockDate()}\n";

            $mail = new Zend_Mail();
            $mail->setType(Zend_Mime::MULTIPART_RELATED);
            $mail->setBodyHtml($body);
            $mail->setFrom('lowstock@yourwebsite.com', 'Low Stock Notifier');
            $mail->addTo('youremail@gmail.com', 'Your Name Here');
            $mail->setSubject('[Notice] An Item Has Gone Out of Stock');
            $mail->send();
        }
    }
}

This sends an email every time a stock item model is saved and the quantity on-hand is lower than the notify quantity set in Admin > Catalog > Manage Products.

Hope that helps.

| improve this answer | |
  • 2
    The DIY route here is on the right track. The OP asked for a single email per night though, so I would suggest a table with 'product_id', 'timestamp', and 'notified' columns. When a product goes out of stock add an entry, when it comes back, remove the entry. Nightly you send an email for all un-notified and set the flag. That keeps you from notifying multiple times for each product, but you do get notification the next time the product goes out of stock. – Lee Saferite May 28 '13 at 13:25
  • 1
    Unfortunately, the cataloginventory_stock_item_save_after event is not triggered on purchase, at least in recent Magento versions. See here for alternative solutions: magento.stackexchange.com/questions/25207/… – Fabian Schmengler Sep 18 '15 at 11:53
  • One minor change to the wonderful explanation of @philwinkle Instead of: $stockItem = $observer->getEvent() use: $stockItem = $observer->getEvent() –getItem() – diazwatson Jan 16 '16 at 1:06
1

Old question, however I don't feel like it was ever really answered. I would add a and cronjob to the config.xml file in a custom module, figure out which products would need to be on the e-mail by building the collection (as below), then email the results.

    $date = strtotime('yesterday');

    $collection = Mage::getModel('cataloginventory/stock_item')
    ->getCollection()
    ->addFieldToFilter('backorders', 0) 
    ->addFieldToFilter('is_in_stock', 0) 
    ->addFieldToFilter('manage_stock', 1) 
    ->addFieldToFilter('low_stock_date', array('date' => true, 'from' => date("Y-m-d", $date)))
    ->getAllIds();
| improve this answer | |
-1

While not an Out of Stock alert, Magento ships with a low stock RSS feed which might suit your needs.

Low Stock RSS Feed

| improve this answer | |
  • how can i get downloadable report, rss just see the report – Gem Nov 19 '16 at 12:35
-1

You could just use the native RSS feed for inventory - run a diff against the previous day's stock (ie. to find what changed only) - then fire off an email based on the result.

It would be a super simple ~10 line PHP script.


If you want something more sophisticated as a proper extension, then you'll need to add an observer to the order_save or stock index - to be able to capture then a value goes below 0 - and create a summary based on those values.

| improve this answer | |
  • I do not have the experience unfortunately to build this but if you do, would you be interested in a fee for your services? My client would really benefit from it. – Adam Ross Apr 1 '13 at 13:39

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.