How to send sms when an item quantity is out of stock in magento ? i have used :
<catalog_product_save_before>
<observers>
<Metro_Notify>
<type>singleton</type>
<class>notify/Productobserver</class>
<method>productSaveBefore</method>
</Metro_Notify>
</observers>
</catalog_product_save_before>
in my observer
private function lowStockReportSendEmail($product,$toEmailAddress)
{
$stockItem = $observer->getEvent();
Mage::log($stockItem,null,'stockitem.null');
if($stockItem->getQty() < $stockItem->getNotifyStockQty())
{
//stock is lower than the notify amount, send email
$product = $observer->getProduct();
$productName = $product->getName();
$productId = $product->getId();
$supplierId = $product->getSeller_id();
$supplierData = $this->_getSupplierData($supplierId);
// $product = Mage::getModel('catalog/product')->load($stockItem->getProductId());
$body = "{$productName} :: {$product->getSku()} just Ran out of stock:\n\n";
$body .= "Current Qty: {$stockItem->getQty()}\n";
$body .= "Low Stock Date: {$stockItem->getLowStockDate()}\n";
$vars['PRODUCTID'] = $productData->getId();
$vars['PRODUCTNAME'] = $productData->getName();
$vars['SUPPLIERNAME'] = $supplierData->getFirstname();
$vars['SUPPLIERNO'] = $supplierData->getSupplier_no();
$vars['QTY'] = $stockItem->getQty();
$vars['PREVIOUSQTY'] = $stockItem->getQty() - $stockItem->getOrigData('qty');
$categoryManagerTemplateId = 'categorymanager_template_lowstock_report';
$adminTemplateId = 'admin_template_lowstock_report';
$fromEmailId = $supplierData->getEmail();
$sender = array('name' => $fromEmailId,'email' => $fromEmailId);
if(!empty($toEmailAddress))
{
$categoryManagerEmail = $toEmailAddress;
$adminEmail = $toEmailAddress;
}
else
{
$categoryManagerEmail = $supplierData->getSupplier_cat_manager_email();
$adminEmail = $this->_getAdminEmailAddress();
$this->log('categoryManagerEmail',$categoryManagerEmail);
$this->log('adminEmail',$adminEmail);
}
/* $storeId = Mage::app()->getStore()->getId();
$templateId = 'supplier_product_stock_update';
$fromEmailId = $supplierData->getEmail();
$sender = array('name' => $fromEmailId,'email' => $fromEmailId);
$toEmail = $supplierData->getSupplier_cat_manager_email();
$name = $supplierData->getFirstname();
$mailSubject = "Supplier Low Stock Notification"; */
$name = $supplierData->getFirstname();
$mailCategorySubject = "Out of Stock".$productName."(".$productId.")";
$mailAdminSubject="Out of Stock".$supplierName;
$this->_sendNotifyEmail($categoryManagerTemplateId, $sender, $categoryManagerEmail, $name, $mailCategorySubject,$vars, $storeId);
$this->_sendNotifyEmail($adminTemplateId, $sender, $adminEmail, $name, $mailAdminSubject,$vars, $storeId);
$this->log('LowStockReportEmail',$vars);
}
}
Mage::log($stockItem,null,'stockitem.null');
please?lowStockReportSendEmail
please? I believve it isproductSaveBefore
from your config.xmlcataloginventory_stock_item_save_after
event?? your xml snipped says your hooking thecatalog_product_save_before
event?