Wyomind_RealInventory - Version 1.0.0

Version Notes

First Release

Download this release

Release Info

Developer Magento Core Team
Extension Wyomind_RealInventory
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Wyomind/Realinventory/Block/Renderer/Qty.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Wyomind_Realinventory_Block_Renderer_qty extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
4
+
5
+ public function render(Varien_Object $row) {
6
+
7
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($row->getId());
8
+ if (!$stock->getIsQtyDecimal())
9
+ return round($stock->getReservedQty());
10
+
11
+ return $stock->getReservedQty();
12
+ }
13
+
14
+ }
15
+
app/code/community/Wyomind/Realinventory/Helper/Data.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Wyomind_Realinventory_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ public function getOrderedItems($order) {
6
+ $orderedItems = array();
7
+ $items = $order->getAllItems();
8
+ $i = 0;
9
+ foreach ($items as $itemId => $item) {
10
+ if ($item->getQtyOrdered() > 0) {
11
+ $orderedItems[$i]["sku"] = $item->getSku();
12
+ $orderedItems[$i]["qty"] = $item->getQtyOrdered();
13
+ $orderedItems[$i]["id"] = Mage::getModel("catalog/product")->getIdBySku($orderedItems[$i]["sku"]);
14
+ $orderedItems[$i]["name"] = $item->getName();
15
+ $i++;
16
+ }
17
+ }
18
+
19
+ return $orderedItems;
20
+ }
21
+
22
+ public function incrementReservedStocks($orderedItems) {
23
+
24
+
25
+
26
+ $temp = array();
27
+
28
+ foreach ($orderedItems as $orderedItem) {
29
+
30
+ if (!in_array($orderedItem["id"], $temp)) {
31
+ $temp[] = $orderedItem["id"];
32
+ $stock = Mage::getModel("cataloginventory/stock_item")->loadByProduct($orderedItem["id"]);
33
+
34
+ if ($stock->getManageStock() || (Mage::getStoreConfig("cataloginventory/item_options/manage_stock") && $stock->getUseConfigManageStock())) {
35
+ $data["reserved_qty"] = $stock->getReservedQty() + $orderedItem["qty"];
36
+ $stock->setReservedQty($data["reserved_qty"])->save();
37
+ //Mage::getSingleton("core/session")->addSuccess("LOG:: +++ " . $orderedItem["id"] . " => " . $orderedItem["qty"] . "<br>");
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ public function decrementReservedStocks($orderedItems) {
44
+ $temp = array();
45
+ foreach ($orderedItems as $orderedItem) {
46
+
47
+ if (!in_array($orderedItem["id"], $temp)) {
48
+ $temp[] = $orderedItem["id"];
49
+ $stock = Mage::getModel("cataloginventory/stock_item")->loadByProduct($orderedItem["id"]);
50
+ if ($stock->getManageStock() || (Mage::getStoreConfig("cataloginventory/item_options/manage_stock") && $stock->getUseConfigManageStock())) {
51
+ $data["reserved_qty"] = $stock->getReservedQty() - $orderedItem["qty"];
52
+ $stock->setReservedQty($data["reserved_qty"])->save();
53
+ //Mage::getSingleton("core/session")->addSuccess("LOG:: --- " . $orderedItem["id"] . " => " . $orderedItem["qty"] . "<br>");
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ }
app/code/community/Wyomind/Realinventory/Model/Observer.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Wyomind_Realinventory_Model_Observer {
4
+
5
+ public function addActionColumn(Varien_Event_Observer $observer) {
6
+
7
+ $block = $observer->getEvent()->getBlock();
8
+ $this->_block = $block;
9
+
10
+ if (get_class($block) == Mage::getStoreConfig("realinventory/system/grid")) {
11
+
12
+ $actions = array();
13
+
14
+
15
+ $block->addColumnAfter("reserved_qty", array(
16
+ "header" => Mage::helper("realinventory")->__("Reserved qty"),
17
+ "width" => "50px",
18
+ "type" => "text",
19
+ "align" => "center",
20
+ "filter" => false,
21
+ "sortable" => true,
22
+ "renderer" => "Wyomind_Realinventory_Block_Renderer_qty",
23
+ ), "qty");
24
+ }
25
+
26
+
27
+ return $observer;
28
+ }
29
+
30
+ public function reserve($observer) {
31
+ $order = $observer->getEvent()->getOrder();
32
+ $orderedItems = Mage::helper("realinventory/data")->getOrderedItems($order);
33
+ Mage::helper("realinventory/data")->incrementReservedStocks($orderedItems);
34
+ //Mage::getSingleton("core/session")->addSuccess("LOG::reserve");
35
+ }
36
+
37
+ public function cancel($observer) {
38
+ $order = $observer->getEvent()->getPayment()->getOrder();
39
+
40
+ $orderedItems = Mage::helper("realinventory/data")->getOrderedItems($order);
41
+ Mage::helper("realinventory/data")->decrementReservedStocks($orderedItems);
42
+
43
+ //Mage::getSingleton("core/session")->addSuccess("LOG::cancel");
44
+ }
45
+
46
+ public function refund($observer) {
47
+ $creditmemo = $observer->getEvent()->getCreditmemo();
48
+
49
+ $items = array();
50
+
51
+ foreach ($creditmemo->getAllItems() as $item) {
52
+ if (!in_array(Mage::getModel("catalog/product")->load($item->getProductId())->getTypeId(), array("configurable", "bundle", "grouped"))) {
53
+ $return = false;
54
+ if ($item->hasBackToStock()) {
55
+ if ($item->getBackToStock() && $item->getQty()) { //qtyRefunded ?
56
+ $return = true;
57
+ }
58
+ } elseif (Mage::helper("cataloginventory")->isAutoReturnEnabled()) {
59
+ $return = true;
60
+ }
61
+ if ($return) {
62
+ Mage::helper("realinventory/data")->decrementReservedStocks(array(array("qty" => $item->getQty(), "id" => $item->getProductId())));
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ public function shipped($observer) {
69
+ $shipment = $observer->getEvent()->getShipment();
70
+ $items = $shipment->getItemsCollection();
71
+ foreach ($items as $item) {
72
+ if (!in_array(Mage::getModel("catalog/product")->load($item->getProductId())->getTypeId(), array("configurable", "bundle", "grouped"))) {
73
+ Mage::helper("realinventory/data")->decrementReservedStocks(array(array("qty" => $item->getQty(), "id" => $item->getProductId())));
74
+ }
75
+ }
76
+ //Mage::getSingleton("core/session")->addSuccess("LOG::shipped");
77
+ }
78
+
79
+ }
80
+
app/code/community/Wyomind/Realinventory/controllers/LicenseController.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Wyomind_Realinventory_LicenseController extends Mage_Core_Controller_Front_Action {
4
+
5
+ public function activationAction() {
6
+ foreach ($_POST as $key => $value)
7
+ $$key = $value;
8
+ $activation_key = Mage::getStoreConfig("realinventory/license/activation_key");
9
+ $base_url = Mage::getStoreConfig("web/secure/base_url");
10
+ $registered_version = Mage::getStoreConfig("realinventory/license/version");
11
+
12
+ if (isset($wgs_activation_key) && $wgs_activation_key == Mage::getStoreConfig("realinventory/license/activation_key")) {
13
+ if (isset($wgs_status)) {
14
+ switch ($wgs_status) {
15
+ case "success" : Mage::getConfig()->saveConfig("realinventory/license/version", $wgs_version, "default", "0");
16
+ Mage::getConfig()->saveConfig("realinventory/license/activation_code", $wgs_activation, "default", "0");
17
+ Mage::getConfig()->cleanCache();
18
+ Mage::getSingleton("core/session")->addSuccess(Mage::helper("realinventory")->__($wgs_message));
19
+ break;
20
+ case "error" : Mage::getSingleton("core/session")->addError(Mage::helper("realinventory")->__($wgs_message));
21
+ Mage::getConfig()->saveConfig("realinventory/license/activation_code", "", "default", "0");
22
+ Mage::getConfig()->cleanCache();
23
+ break;
24
+ case "uninstall" : Mage::getSingleton("core/session")->addError(Mage::helper("realinventory")->__($wgs_message));
25
+ Mage::getConfig()->saveConfig("realinventory/license/activation_key", "", "default", "0");
26
+ Mage::getConfig()->saveConfig("realinventory/license/activation_code", "", "default", "0");
27
+ Mage::getConfig()->cleanCache();
28
+ echo " <form action='http://www.wyomind.com/license_activation/?method=post' id='license_uninstall' method='post'> <input type='hidden' type='action' value='uninstall' name='action'> <input type='hidden' value='" . $base_url . "' name='domain'> <input type='hidden' value='" . $activation_key . "' name='activation_key'> <input type='hidden' value='" . $registered_version . "' name='registered_version'> <button type='submit'>If nothing happens click here !</button> <script language='javascript'> document.getElementById('license_uninstall').submit(); </script> </form> ";
29
+ die();
30
+ break;
31
+ default : Mage::getSingleton("core/session")->addError(Mage::helper("realinventory")->__("An error occurs while retrieving license activation (500)"));
32
+ Mage::getConfig()->saveConfig("realinventory/license/activation_code", "", "default", "0");
33
+ Mage::getConfig()->cleanCache();
34
+ break;
35
+ }
36
+ } else {
37
+ Mage::getSingleton("core/session")->addError(Mage::helper("realinventory")->__("An error occurs while retrieving license activation (404)."));
38
+ }
39
+ } else
40
+ Mage::getSingleton("core/session")->addError(Mage::helper("realinventory")->__("Invalid activation key."));
41
+ $this->loadLayout();
42
+ $this->renderLayout();
43
+ }
44
+
45
+ }
app/code/community/Wyomind/Realinventory/etc/config.xml ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+
4
+ <config>
5
+ <modules>
6
+ <Wyomind_Realinventory>
7
+ <version>1.0.0</version>
8
+ </Wyomind_Realinventory>
9
+ </modules>
10
+ <default>
11
+ <realinventory>
12
+ <system>
13
+ <grid>Mage_Adminhtml_Block_Product_Grid</grid>
14
+ </system>
15
+ </realinventory>
16
+ </default>
17
+ <admin>
18
+ <routers>
19
+ <realinventory>
20
+ <use>admin</use>
21
+ <args>
22
+ <module>Wyomind_Realinventory</module>
23
+ <frontName>realinventory</frontName>
24
+ </args>
25
+ </realinventory>
26
+ </routers>
27
+ </admin>
28
+ <frontend>
29
+ <routers>
30
+ <use>standard</use>
31
+ <realinventory>
32
+ <args>
33
+ <module>Wyomind_Realinventory</module>
34
+ <frontName>realinventory</frontName>
35
+ </args>
36
+ </realinventory>
37
+ </routers>
38
+ <events>
39
+
40
+ <checkout_submit_all_after>
41
+ <observers>
42
+ <wyomind_realinventory_checkout_submit_all_after_observer>
43
+ <type>singleton</type>
44
+ <class>Wyomind_Realinventory_Model_Observer</class>
45
+ <method>reserve</method>
46
+ </wyomind_realinventory_checkout_submit_all_after_observer>
47
+ </observers>
48
+ </checkout_submit_all_after>
49
+ <sales_order_payment_cancel>
50
+ <observers>
51
+ <wyomind_realinventory_sales_order_payment_cancel_observer>
52
+ <type>singleton</type>
53
+ <class>Wyomind_Realinventory_Model_Observer</class>
54
+ <method>cancel</method>
55
+ </wyomind_realinventory_sales_order_payment_cancel_observer>
56
+ </observers>
57
+ </sales_order_payment_cancel>
58
+
59
+ </events>
60
+ </frontend>
61
+ <adminhtml>
62
+
63
+ <acl>
64
+ <resources>
65
+ <all>
66
+ <title>Allow Everything</title>
67
+ </all>
68
+ <admin>
69
+ <children>
70
+ <system>
71
+ <children>
72
+ <config>
73
+ <children>
74
+ <realinventory>
75
+ <title>Real Inventory</title>
76
+ </realinventory>
77
+ </children>
78
+ </config>
79
+ </children>
80
+ </system>
81
+ </children>
82
+ </admin>
83
+ </resources>
84
+ </acl>
85
+
86
+ <events>
87
+ <core_block_abstract_to_html_before>
88
+ <observers>
89
+ <wyomind_realinventory_catalog_product_grid_column>
90
+ <type>model</type>
91
+ <class>Wyomind_Realinventory_Model_Observer</class>
92
+ <method>addActionColumn</method>
93
+ </wyomind_realinventory_catalog_product_grid_column>
94
+ </observers>
95
+ </core_block_abstract_to_html_before>
96
+ <checkout_submit_all_after>
97
+ <observers>
98
+ <wyomind_realinventory_checkout_submit_all_after_observer>
99
+ <type>singleton</type>
100
+ <class>Wyomind_Realinventory_Model_Observer</class>
101
+ <method>reserve</method>
102
+ </wyomind_realinventory_checkout_submit_all_after_observer>
103
+ </observers>
104
+ </checkout_submit_all_after>
105
+ <sales_order_payment_cancel>
106
+ <observers>
107
+ <wyomind_realinventory_sales_order_payment_cancel_observer>
108
+ <type>singleton</type>
109
+ <class>Wyomind_Realinventory_Model_Observer</class>
110
+ <method>cancel</method>
111
+ </wyomind_realinventory_sales_order_payment_cancel_observer>
112
+ </observers>
113
+ </sales_order_payment_cancel>
114
+ <sales_order_creditmemo_refund>
115
+ <observers>
116
+ <wyomind_realinventory_sales_creditmemo_item_save_after>
117
+ <type>singleton</type>
118
+ <class>Wyomind_Realinventory_Model_Observer</class>
119
+ <method>refund</method>
120
+ </wyomind_realinventory_sales_creditmemo_item_save_after>
121
+ </observers>
122
+ </sales_order_creditmemo_refund>
123
+ <sales_order_shipment_save_after>
124
+ <observers>
125
+ <wyomind_realinventory_sales_order_shipment_save_after>
126
+ <type>singleton</type>
127
+ <class>Wyomind_Realinventory_Model_Observer</class>
128
+ <method>shipped</method>
129
+ </wyomind_realinventory_sales_order_shipment_save_after>
130
+ </observers>
131
+ </sales_order_shipment_save_after>
132
+ </events>
133
+ </adminhtml>
134
+ <global>
135
+ <resources>
136
+ <realinventory_setup>
137
+ <setup>
138
+ <module>Wyomind_Realinventory</module>
139
+ </setup>
140
+ <connection>
141
+ <use>core_setup</use>
142
+ </connection>
143
+ </realinventory_setup>
144
+
145
+ </resources>
146
+ <helpers>
147
+ <realinventory>
148
+ <class>Wyomind_Realinventory_Helper</class>
149
+ </realinventory>
150
+ </helpers>
151
+ </global>
152
+ </config>
153
+
154
+
155
+
156
+
157
+
158
+
app/code/community/Wyomind/Realinventory/etc/system.xml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <WYOMIND translate="label">
5
+ <label>WYOMIND</label>
6
+ <sort_order>1000000</sort_order>
7
+ </WYOMIND>
8
+ </tabs>
9
+ <sections>
10
+ <realinventory translate="label">
11
+ <label>Real Inventory</label>
12
+ <tab>WYOMIND</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>1010</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+
20
+ <system translate="label">
21
+ <label><![CDATA[ Core setting <span class="notice"> // Advanced users //</span>]]>
22
+ </label>
23
+ <frontend_type>text</frontend_type>
24
+ <sort_order>300</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ <fields>
29
+ <grid translate="label comment">
30
+ <label>Orders grid to display </label>
31
+ <comment>
32
+ <![CDATA[ <span class="notice"> Default value : `Mage_Adminhtml_Block_Product_Grid`</span>]]>
33
+ </comment>
34
+ <validate>required-entry validate-address</validate>
35
+ <frontend_type>text</frontend_type>
36
+ <sort_order>1</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>0</show_in_website>
39
+ <show_in_store>0</show_in_store>
40
+ </grid>
41
+ </fields>
42
+ </system>
43
+ </groups>
44
+ </realinventory>
45
+ </sections>
46
+ </config>
47
+
48
+
49
+
50
+
app/code/community/Wyomind/Realinventory/sql/realinventory_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+ $installer->run("ALTER TABLE {$this->getTable('cataloginventory/stock_item')} ADD `reserved_qty` decimal(12,4) NOT NULL DEFAULT '0.0000';");
5
+ $installer->endSetup();
app/etc/modules/Wyomind_Realinventory.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+
2
+ <config>
3
+ <modules>
4
+ <Wyomind_Realinventory>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Wyomind_Realinventory>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Wyomind_RealInventory</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Keep your inventory updated until the orders are shipped. Display your stock level in two distinct columns : one for the saleable remaining products and one other for the already paid but not shipped products.</summary>
10
+ <description>+ Show the saleable remaining product stocks and the already paid but not shipped product stock&#xD;
11
+ + Keep your Magento inventory synchronized with your real inventory&#xD;
12
+ + See in one glance which products must be shipped&#xD;
13
+ + Can be used with any tiers extension already installed that overrides the default products grid such as "Enhanced Admin Product Grid"</description>
14
+ <notes>First Release</notes>
15
+ <authors><author><name>Wyomind</name><user>auto-converted</user><email>contact@wyomind.com</email></author></authors>
16
+ <date>2013-03-13</date>
17
+ <time>09:04:28</time>
18
+ <contents><target name="magecommunity"><dir name="Wyomind"><dir name="Realinventory"><dir name="Block"><dir name="Renderer"><file name="Qty.php" hash="718c4f1ff654d06e820a1b27d3f041a5"/></dir></dir><dir name="Helper"><file name="Data.php" hash="ad19841c1add221eed126808a17a080d"/></dir><dir name="Model"><file name="Observer.php" hash="8811ee2ec4c4bfb300e9a63942fb9b3e"/></dir><dir name="controllers"><file name="LicenseController.php" hash="831a4b2ca0d4404f74fdb210eea6fac8"/></dir><dir name="etc"><file name="config.xml" hash="b516c4b95f67f7a713aedb7f76d3898e"/><file name="system.xml" hash="27d09f2467c37901a96a29de8dce5d06"/></dir><dir name="sql"><dir name="realinventory_setup"><file name="mysql4-install-1.0.0.php" hash="281ce389c4960100c21039539d601c60"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Wyomind_Realinventory.xml" hash="a55d4da5dc0000c556e72e4e648f26b2"/></dir></target></contents>
19
+ <compatible/>
20
+ <dependencies/>
21
+ </package>