With Magento, the stock of a product is not stored each time it’s changing. However, the stock may be modified in many ways (product ordered, canceled order, manual changes, imports, etc..) and it may be useful to know how and when the stock has changed. Here is a simple extension that saves over time the stock movements of your products.
Installation of Stock Movements extension
Extension is available on GitHub: https://github.com/jreinke/magento-stock-movements
You have 2 ways to install it:
- Download package here, then unzip in Magento root folder.
- Installation with modgit:
$ modgit add stock-movements https://github.com/jreinke/magento-stock-movements.git
See a full example of how to use
modgit
here.
Clear Magento cache and that’s it!
Overview
Once installed, you can see a new tab in product modification form:
Compatibility
Extension has been tested on following Magento versions: 1.5.x, 1.6.x, 1.7.x
44 Responses to “Magento: Save products stock movements”
Little change in code. Is buy goods, then usename get “-”
If we change code to
$username = ‘-‘;
if (Mage::getSingleton(‘customer/session’)->isLoggedIn()) {
$username = Mage::getSingleton(‘customer/session’)->getCustomer()->getEmail();
} elseif (Mage::getSingleton(‘admin/session’)->isLoggedIn()) {
$username = Mage::getSingleton(‘admin/session’)->getUser()->getUsername();
}
we have user email
On my new webstore (magento 1.7) i got some trouble to install the module.
I replaced :
$installer = $this;
/* @var $installer Mage_Core_Model_Resource_Setup */
$tableHistory = $this->getTable(‘cataloginventory_stock_history’);
$tableItem = $this->getTable(‘cataloginventory_stock_item’);
$tableUser = $this->getTable(‘admin/user’);
$installer->startSetup();
By :
$installer = $this;
/* @var $installer Mage_Core_Model_Resource_Setup */
// $tableHistory = $this->getTable(‘cataloginventory_stock_history’);
// $tableItem = $this->getTable(‘cataloginventory_stock_item’);
// $tableUser = $this->getTable(‘admin/user’);
$installer->startSetup();
$tableHistory = $this->getTable(‘cataloginventory_stock_history’);
$tableItem = $installer->getTable(‘cataloginventory_stock_item’);
$tableUser = $installer->getTable(‘admin/user’);
And now it works
I have no problem with 1.7 but I’ve made the changes anyway for installer consistency. Thank you.
Thanks for the Stock History Extension. Great work! 1.6.2
I am running EE 1.10 and seems to install and create the tables, but when I go to look at a product I see the following, then a big stacktrace
Warning: include(Mage/Core/Model/Resource/Db/Abstract.php): failed to open stream: No such file or directory in /Users/vtoms/dev/adoreme/adoreme/html/lib/Varien/Autoload.php on line 93
not sure how to debug this on.
Hi
I can’t see a file of mine in the warning. Have you tried disabling my module?
Thanks for creating this module. I get same error on Pro 1.10. I checked and there is no Db directory in Mage/Core/Model/Resource. So maybe it’s only compatible with community version?
Looks like that include path works only for 1.6+. In 1.5 or EE 1.10 the model is Mage_Core_Model_Mysql4_Collection_Abstract.
Hi,
I tried to install the module on Magento CE 1.3.2.4 (yeah I know it’s an old version but I’d really like to make this work on this version).
I made the change you had to make for 1.5, but when I want to go to a product, I get the error
Fatal error: Call to a member function getReadConnection() on a non-object in /var/www/magento/app/code/core/Mage/Core/Model/Mysql4/Collection/Abstract.php on line 68
Anyone know If it is possible at all to make this module work on 1.3.2.4 ?
Thanks a lot for your help.
Looks great but installed on 1.5.1.0 but get a internal server 500 error when I try to edit a product, might be the Enhanced Product Grid Extension that is installed. I think it would work on a clean install. Uninstalled and can now access the product edit pages again. Any thoughts? Thankyou.
Hi Johann,
Quick question – when I changed the stock manually to 0 in the admin page, it does not get updated in the stock history.
Any reason why?
Jason
Hi,
I’m facing same issue. Manual change doesn’t show.
I’m using 1.7.
Jakob
Update: it doesn’t show if entered stock is negative
Jakob
Ok. I had to comment out line
// if (! $stockItem->getStockStatusChangedAutomaticallyFlag()) {
in Observer::saveStockItemAfter
Will this change affect modules behavior?
f the product is disabled the 0 movement is not recorded,
but if the product is enabled it records the movement to zero
( in v 1.2.2)
Testing in Magento 1.7.2 identified that in one purchase with several items it records only the changes of the last product.
It is normal behavior or a conflict?
Thanks and sorry my bad english.
There its a minor bug which causes this:
In Model/Observer function checkoutAllSubmitAfter
change:
$this->insertStockHistory($stockItem, $data['delta'], sprintf(
‘Product ordered (order%s: %s)’,
count($data['orders']) > 1 ? ‘s’ : ”,
implode(‘, ‘, $data['orders'])
));
with:
$this->insertStockHistory($data['item'], $data['delta'], sprintf(
‘Product ordered (order%s: %s)’,
count($data['orders']) > 1 ? ‘s’ : ”,
implode(‘, ‘, $data['orders'])
));
Magento 1.7.0.2
When duplicating configurable product there is an error:
Fatal error: Call to a member function addTab() on a non-object in /app/code/community/JR/StockHistory/Model/Stock/Observer.php on line 9
Great extension
Thx
This is fixed, thanks for bug report.
Great plugin but I notice that the stock history is not recorded when a customer pays with Paypal Express. Is this a problem on my end or is this an expected outcome due to the nature of the way the payment is captured?
Hello,
Same problem for me, Paypal Express order don’t update stock movement.
Regards.
Hi Johann. First of all, thank you very much! You’ve really help me out with this module.
I’ve installed it and all seems to be working fine, but for one behaviour: all movements are recorded either twice or three times. Is this normal?
For eg. this is the log of a product of mine:
7 0 Sí Product ordered (order: 400000024) – 07/05/2013 16:29:41
7 -1 Sí Product ordered (order: 400000024) – 07/05/2013 16:29:41
8 0 Sí Product ordered (order: 400000022-1) maxicooper 07/05/2013 16:25:17
8 0 Sí Product restocked after order cancellation (order: 400000022) maxicooper 07/05/2013 16:25:17
8 -2 Sí Stock saved manually maxicooper 07/05/2013 16:25:17
10 +16 Sí Stock saved manually maxicooper 07/05/2013 16:24:06
-6 0 No Product ordered (order: 400000022) maxicooper 07/05/2013 16:21:57
-6 0 No Product ordered (order: 400000022) maxicooper 07/05/2013 16:21:57
-6 0 No Product ordered (order: 400000022) maxicooper 07/05/2013 16:21:56
-6 – No Stock saved manually maxicooper 07/05/2013 16:21:55
Any ideas why? Thanks again!
Same as Maxi.
We have many lines repeated. twice or three times for each actions.
even four.
Hello,
The bug has been fixed (multiple/duplicate lines).
Update the source code from GitHub: https://github.com/jreinke/magento-stock-movements/tree/legacy
Hello,
It’s possible to add an “edit” button on “message” in admin ? I try but I can’t go to the good url :'(
Your extension is better than mine but I don’t use the same way to print data so I can’t add anything.
Regards,
Aurélien
I have found an issue in your MustHaveExtention. Posted on a github.
https://github.com/jreinke/magento-stock-movements/issues/13
Anyone try to install this in magento 1.8?
Yes, we’d like to know if it works on CE 1.8.1. Anybody done it?
To Ricardo and bbaccessories; I have it up and running on CE 1.9 but so far only dev with manual changes to the stock but those look fine. Let me know if you have had a chance to try it out on a production site yet?
@Johann
On first stock update for each product there seem to be an error that either sets the movement to the same as the target quantity or nothing, just a dash. Any clue what that could be?
Thanks in advance
I have used this before thanks!
Now I am trying it with another extension that has multiple stock locations ( Innoexts Multi-warehouse Plus)
Looks like you assume all stock is in stock_id zero, which works for Magento out of the box.
What would it take to lok at he stock_id?
last line s/b
What would it take to look at the stock_id?
hu!
I am getting
SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘movement’ in ‘order clause’
With magento 1.7
It didn’t install it well?
Dave
Hey there! I know this is kinda off topic nevertheless I’d figured I’d ask. Would you be interested in exchanging links or maybe guest authoring a blog post or vice-versa? My blog discusses a lot of the same topics as yours and I think we could greatly benefit from each other. If you are interested feel free to send me an email. I look forward to hearing from you! Awesome blog by the way!
Hi Dear.
I used this extension and it’s good works.
Thanks a lot.
one question.
How to use tab Stock Movement in another attribute set?
At the moment, there is only in attribute set default.
Thanks,
Thanks a lot! Thats a big part of what we’re looking for! Now we just need to figure out how to pass a user along when we update stock levels with our custom php-code using the setData-function – any ideas…?
Hi, does this still work on Magento ver. 1.9.0.1?
Thank you very much! The extension works like a charm!
The last element on page, don’t has a changes value, and in the multi-product grid the changes column has wrong values (related to previous row, and sometimes with different product)
Thanks a lot. Nice work
Hi,
Did anyone try to install this on Magento 1.3.2.4 ? For the author : do you know if it works on this (old, I know…) version of Magento ?
Thanks I would really like to use this extension.
Jerome
Hi, is it possible to ask for small addition? In stock movement INTO the warehouse to have the price of the unit so we can later generate PROFIT report?
thank!
Hi, Is it possible to record stock history when customer pays with PayPal Express.
Thanks
After I upload this extension to a couple of my magento sites, I get this error.
SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘shopsorg_wzt5koj.bubble_stock_movement’ doesn’t exist
Can you help me out? It works wonderfully on all of my other stores. I don’t see why it wouldn’t work on these stores.
Hi, I successfully copied the files and cleared the cache but I’m still getting the old classic Stock History screen in the admin product page.
I have a new Stock Movements option in the catalog section but not in the product itself. Any thoughts? Many thanks.
forgot to mention, I’m on Magento 1.9.2
Is this compatible with 1.8 magento? This will be very handy for us.
Thanks for creating such an awesome extension! We have had issues with inventory numbers inexplicably changing. This will help us identify the cause. You are THE MAN!