Uipl_Stockalert - Version 1.0.0.1

Version Notes

After installation of this module you should enable cron job at cpanel for magento.

Download this release

Release Info

Developer Ujjal
Extension Uipl_Stockalert
Version 1.0.0.1
Comparing to
See all releases


Version 1.0.0.1

app/code/community/Uipl/Stockalert/Model/Cron.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Uipl_Stockalert_Model_Cron{
3
+ public function SendAlert(){
4
+
5
+ $configValue = Mage::getStoreConfig('general/stockalert/active');
6
+ if($configValue!=1){
7
+ Mage::log("Stock alert is disabled from admin general system configuration");
8
+ return false;
9
+ }
10
+
11
+ $collection = Mage::getModel('catalog/product')
12
+ ->getCollection()->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
13
+ ->addAttributeToSelect('*')->addAttributeToFilter('status', array('eq'=>'1'));
14
+
15
+ $expro='<table width="100%" cellpadding="10" cellspacing="10">
16
+ <tr><td>Product Id</td><td>Product Name</td><td>SKU</td><td>Product Url</td></tr>
17
+ ';
18
+ foreach($collection as $_product){
19
+ $_product = Mage::getModel('catalog/product')->load($_product->getId());
20
+
21
+
22
+ $num= Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
23
+ $qtyStock=Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getMinQty();
24
+ $qtyStock=$qtyStock-$orderqty;
25
+ if($num<=$qtyStock){
26
+
27
+ $expro .='<tr><td>'.$_product->getId().'</td><td>'.$_product->getName().'</td><td>'.$_product->getSku().'</td><td>'.$_product->getProductUrl().'</td></tr>';
28
+
29
+ }
30
+
31
+ }
32
+
33
+ $expro .='</table>';
34
+
35
+ $email_to=Mage::getStoreConfig('trans_email/ident_sales/email');
36
+
37
+ $email_template_variables = array(
38
+ 'alertGrid' => $expro,
39
+
40
+
41
+ );
42
+
43
+
44
+ $sender_name = Mage::getStoreConfig('trans_email/ident_general/name'); ;
45
+
46
+ $sender_email = Mage::getStoreConfig('trans_email/ident_general/email');
47
+
48
+ $emailTemplate->setSenderName($sender_name);
49
+ $emailTemplate->setSenderEmail( $sender_email);
50
+
51
+ $processedTemplate = $emailTemplate->getProcessedTemplate($email_template_variables);
52
+
53
+ $emailTemplate->send($email_to,'Product Stock Alert Notification', $email_template_variables);
54
+
55
+
56
+
57
+
58
+ }
59
+ }
app/code/community/Uipl/Stockalert/Model/Observer.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Uipl_Stockalert_Model_Observer {
3
+
4
+ public function getalert($observer) {
5
+
6
+ $configValue = Mage::getStoreConfig('general/stockalert/active');
7
+ if($configValue!=1){
8
+ Mage::log("Stock alert is disabled from admin general system configuration");
9
+ return false;
10
+ }
11
+
12
+ $order = $observer->getEvent()->getOrder();
13
+
14
+ $orders = Mage::getModel("sales/order")->load($order->getId());
15
+
16
+
17
+ $ordered_items = $orders->getAllItems();
18
+
19
+ foreach($ordered_items as $item){
20
+
21
+ $product_id =$item->getProductId();
22
+ //product id
23
+
24
+ $orderqty= $item->getQtyOrdered();
25
+ $_product = Mage::getModel('catalog/product')->load($product_id);
26
+ //$qtyStock= $_product->getMinQty();
27
+
28
+ $num= Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
29
+ $qtyStock=Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getMinQty();
30
+ $qtyStock=$qtyStock-$orderqty;
31
+ if($num<=$qtyStock){
32
+ $email_to=Mage::getStoreConfig('trans_email/ident_sales/email');
33
+
34
+ $emailTemplate = Mage::getModel('core/email_template')
35
+ ->loadDefault('outofstock_email_template');
36
+
37
+
38
+
39
+ $expro='<table width="100%" cellpadding="10" cellspacing="10">
40
+ <tr><td>Product Id</td><td>Product Name</td><td>SKU</td><td>Product Url</td></tr>
41
+ ';
42
+
43
+ $expro .='<tr><td>'.$_product->getId().'</td><td>'.$_product->getName().'</td><td>'.$_product->getSku().'</td><td>'.$_product->getProductUrl().'</td></tr>';
44
+
45
+
46
+ $expro .='</table>';
47
+
48
+ $email_template_variables = array(
49
+ 'alertGrid' => $expro,
50
+
51
+
52
+ );
53
+
54
+
55
+ $sender_name = Mage::getStoreConfig('trans_email/ident_general/name'); ;
56
+
57
+ $sender_email = Mage::getStoreConfig('trans_email/ident_general/email');
58
+
59
+ $emailTemplate->setSenderName($sender_name);
60
+ $emailTemplate->setSenderEmail( $sender_email);
61
+
62
+ $processedTemplate = $emailTemplate->getProcessedTemplate($email_template_variables);
63
+
64
+ $emailTemplate->send($email_to,'Product Stock Alert Notification', $email_template_variables);
65
+
66
+
67
+ }
68
+
69
+
70
+ //Mage::log('pid='. $product_id." sale qty =".$orderqty." stock qty=".$qtyStock." another qty=".$num.$processedTemplate);
71
+
72
+ }
73
+
74
+ }
75
+
76
+ }
77
+ ?>
app/code/community/Uipl/Stockalert/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <general translate="title" module="stockalert">
12
+ <title>General Section</title>
13
+ <sort_order>0</sort_order>
14
+ </general>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/community/Uipl/Stockalert/etc/config.xml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Uipl_Stockalert>
5
+ <version>0.0.1</version>
6
+ </Uipl_Stockalert>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <stockalert>
11
+ <class>Uipl_Stockalert_Model</class>
12
+ <resourceModel>stockalert_mysql4</resourceModel>
13
+ </stockalert>
14
+ </models>
15
+ <events>
16
+ <sales_order_place_before>
17
+ <observers>
18
+ <uipl_stockalert_model_observer>
19
+ <type>singleton</type>
20
+ <class>Uipl_Stockalert_Model_Observer</class>
21
+ <method>getalert</method>
22
+ </uipl_stockalert_model_observer>
23
+ </observers>
24
+ </sales_order_place_before>
25
+ </events>
26
+
27
+ <template>
28
+ <email>
29
+ <outofstock_email_template module="stockalert">
30
+ <label>Out of stock email module</label>
31
+ <file>admin_stock_alert.html</file>
32
+ <type>html</type>
33
+ </outofstock_email_template>
34
+ </email>
35
+ </template>
36
+ </global>
37
+
38
+
39
+ <crontab>
40
+ <jobs>
41
+ <stockalert_sendalert>
42
+ <schedule><cron_expr>* * * * *</cron_expr></schedule>
43
+ <run><model>stockalert/cron::SendAlert</model></run>
44
+ </stockalert_sendalert>
45
+ </jobs>
46
+ </crontab>
47
+
48
+
49
+
50
+ </config>
app/code/community/Uipl/Stockalert/etc/system.xml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <general translate="label" module="stockalert">
5
+ <label>General</label>
6
+ <tab>general</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>0</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <stockalert translate="label">
14
+ <label>Stock Alert Setting</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>0</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <fields>
21
+ <active translate="label">
22
+ <label>Active</label>
23
+ <frontend_type>select</frontend_type>
24
+ <source_model>adminhtml/system_config_source_yesno</source_model>
25
+ <sort_order>0</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ <comment>Enable this extension to run stock alert notification.</comment>
30
+ </active>
31
+
32
+ </fields>
33
+ </stockalert>
34
+ </groups>
35
+ </general>
36
+ </sections>
37
+ </config>
app/etc/modules/Uipl_Stockalert.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Uipl_Stockalert>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <version>0.1.0</version>
8
+ </Uipl_Stockalert>
9
+ </modules>
10
+ </config>
app/locale/en_US/template/email/admin_stock_alert.html ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <!--@subject Products are out of stock @-->
2
+ <!--@vars
3
+ {"var customerName":"Customer Name",
4
+ "var alertGrid":"Alert Data Grid"}
5
+ @-->
6
+ Hello admin,
7
+ <p>Following products are out of stock : </p>
8
+ {{var alertGrid}}
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Uipl_Stockalert</name>
4
+ <version>1.0.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Out of stock alert for admin</summary>
10
+ <description>This module will generate out of stock alert notification for admin when product goes below minimum stock.</description>
11
+ <notes>After installation of this module you should enable cron job at cpanel for magento.</notes>
12
+ <authors><author><name>Ujjal Dutta</name><user>ujjaldutta</user><email>ujjal.dutta.pro@gmail.com</email></author></authors>
13
+ <date>2015-03-06</date>
14
+ <time>14:19:18</time>
15
+ <contents><target name="magecommunity"><dir name="Uipl"><dir name="Stockalert"><dir name="Model"><file name="Cron.php" hash="d75fe9ceeb5e9f9a4b6fd538c662b8d3"/><file name="Observer.php" hash="446283f53d2d55004c0cf69320ce366b"/></dir><dir name="etc"><file name="adminhtml.xml" hash="d39956779ec5c37a2cff0bf04c70729d"/><file name="config.xml" hash="51c340059949d28e9cfe791b18e0cb16"/><file name="system.xml" hash="ac3ac618bc2215ef914add4cdac30b77"/></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><dir name="template"><dir name="email"><file name="admin_stock_alert.html" hash="14fc57366851be80b061cf29356794eb"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Uipl_Stockalert.xml" hash="c441dfaa4fcc00683f7541f730345c0c"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>