00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Rss_Block_Catalog_NotifyStock extends Mage_Rss_Block_Abstract
00035 {
00036 protected function _construct()
00037 {
00038
00039
00040
00041 $this->setCacheKey('rss_catalog_notifystock');
00042 $this->setCacheLifetime(600);
00043 }
00044
00045 protected function _toHtml()
00046 {
00047 $newurl = Mage::getUrl('rss/catalog/notifystock');
00048 $title = Mage::helper('rss')->__('Low Stock Products');
00049
00050 $rssObj = Mage::getModel('rss/rss');
00051 $data = array('title' => $title,
00052 'description' => $title,
00053 'link' => $newurl,
00054 'charset' => 'UTF-8',
00055 );
00056 $rssObj->_addHeader($data);
00057
00058 $_configManageStock = (int)Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK);
00059 $stockItemWhere = "({{table}}.low_stock_date is not null) "
00060 . " and ({{table}}.low_stock_date>'0000-00-00') "
00061 . " and IF({{table}}.use_config_manage_stock=1," . $_configManageStock . ",{{table}}.manage_stock)=1";
00062
00063 $product = Mage::getModel('catalog/product');
00064 $collection = $product->getCollection()
00065 ->addAttributeToSelect('name', true)
00066 ->addAttributeToSelect('name', true)
00067 ->joinTable('cataloginventory/stock_item', 'product_id=entity_id', array('qty'=>'qty', 'notify_stock_qty'=>'notify_stock_qty', 'use_config' => 'use_config_notify_stock_qty','low_stock_date' => 'low_stock_date'), $stockItemWhere, 'inner')
00068 ->setOrder('low_stock_date')
00069 ;
00070 $_globalNotifyStockQty = (float) Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY);
00071
00072
00073
00074
00075
00076 Mage::getSingleton('core/resource_iterator')
00077 ->walk($collection->getSelect(), array(array($this, 'addNotifyItemXmlCallback')), array('rssObj'=> $rssObj, 'product'=>$product, 'globalQty' => $_globalNotifyStockQty));
00078
00079 return $rssObj->createRssXml();
00080 }
00081
00082 public function addNotifyItemXmlCallback($args)
00083 {
00084 $product = $args['product'];
00085 $product->setData($args['row']);
00086 $url = Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit/', array('id'=>$product->getId(),'_secure' => true,'_nosecret' => true));
00087 $description = Mage::helper('rss')->__('%s has reached a quantity of %s.', $product->getName(),(1*$product->getQty()));
00088 $rssObj = $args['rssObj'];
00089 $data = array(
00090 'title' => $product->getName(),
00091 'link' => $url,
00092 'description' => $description,
00093 );
00094 $rssObj->_addEntry($data);
00095 }
00096 }