Magento – Daily admin email for products that went out of stock that day

adminemailinventory

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!

Best Answer

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.

Related Topic