* Multiple stock edit (http://www.ubercart.org/contrib/5411) - This was originally built for Drupal 5 and Ubercart 1 and as of today there is still no official version for Ubercart 2. Users have been maintaining it bit by bit (see that page) but another issue with it is that it is overkill for what I want - a simple stock editor.
* Stock & Price updater (http://www.ubercart.org/contrib/12428) - This does allow for bulk updating but it's designed for use with a CSV file. I wanted something that would allow me to edit values directly through the webpage.
* Views Bulk Operations (http://drupal.org/project/views_bulk_operations) - This seemed unable to expose the stock level as and update-able field. Also it's sense of bulk-editing involves setting the same value for all products, rather than per-product values.
My solution is modelled on the 'Stock report' page displayed by the uc_stock module. However it makes the stock level editable in place and utilises AJAX (jQuery) to provide instant submission of the updated value (with error/success feedback) to the server. The user can choose to view all products on a single page or opt for a paged view of products (the default view) in case their product catalogue is very large.
I've tested my module on a client website and have placed the code available for download at this page: http://www.hiddentao.com/code/drupal-bulk-stock-updater/
Thankyou.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | uc_bulk_stock_updater.zip | 5.68 KB | hiddentao |
| #8 | uc_bulk_stock_updater-6.x-1.0.zip | 7.34 KB | hiddentao |
| #6 | uc_bulk_stock_updater-6.x-1.0.zip | 7.23 KB | hiddentao |
| #7 | uc_bulk_stock_updater-6.x-1.0.zip | 7.26 KB | hiddentao |
| #1 | uc_bulk_stock_updater.zip | 6.21 KB | hiddentao |
Comments
Comment #1
hiddentao commentedPlease find attached the full code for the module.
Instructions available here -> http://www.hiddentao.com/code/drupal-bulk-stock-updater/
Comment #2
hiddentao commentedComment #3
avpadernoHello, and thanks for applying for a CVS account. I am adding the review tags, and some volunteers will review your code, pointing out what needs to be changed.
As per http://drupal.org/cvs-application/requirements, the motivation message should be expanded to contain more details about the features of the proposed module, and it should include also a comparison with the existing solutions.
Comment #4
hiddentao commentedHow my solution works:
My solution is a bulk product stock level updater for Ubercart 2.x running on Drupal 6.x. Its interface is modelled on the 'Stock report' page displayed by the uc_stock module. It adds a menu item:
Store administration > Stock > Bulk update
To view the page the user must have the 'administer products' permission (same as for editing Ubercart products).
The page lists all products along with their stock levels and minimum stock thresholds. The stock levels are shown as editable text fields. When the user changes the value within a text field and then takes the focus away from it an AJAX call is made to the server (and handled by uc_bulk_stock_updater) to update the stock level for that particular product with what the user entered.
A progress indicator is shown whilst the AJAX call is taking place and the user is given success/error feedback once complete. If the call fails or the update on the server-side fails then the stock level for the product is set back to its original value. The user can choose to view all products on a single page or opt for a paged view of products (the default view) in case their product catalogue is very large.
The benefit of using AJAX to perform the update rather than the standard form submission mechanism is that it minimises the chances of a HTTP call timeout (due to lots of data having to be updated) and it is also quicker since less data needs to be passed between client and server.
Comparing uc_bulk_stock_updater to existing solutions:
* Multiple stock edit (http://www.ubercart.org/contrib/5411) - This supports the editing of stock levels of multiple products in one go. However the official version is only for Ubercart 1.x running on Drupal 5. Forum users have tried to provide patches now and then to make it work with Ubercart 2.x however it is still not fully functional on this newer version. What's more the stock editing form utilises the standard Drupal form mechanism whereby the user enters the updated stock levels for 30+ items and then saves them by submitting the form. When updating such a large number of items there is potential for a HTTP timeout to occur if, for instance, the database accesses are being particularly slow at that point. The approach taken in my module avoids this problem and it also works quicker because it uses AJAX (meaning less data needs to be passed between client adn server).
* Stock & Price updater (http://www.ubercart.org/contrib/12428) - This does allow for bulk updating but it's designed for use with a CSV file. The user uploads a CSV file which then gets imported line by line. The problem with this is that it doesn't allow you to quickly update a few stock levels without first having to create a CSV file to upload. It's designed more for updating stock levels in Ubercart from an existing supply spreadsheet that the business may be using. My solution allows for updates on the webpage itself so you can choose how many to update in any one go whilst at the same time avoiding problems due to corrupt CSV files. If a user wishes to do a CSV-style update they can simply use this module instead of mine.
* Views Bulk Operations (http://drupal.org/project/views_bulk_operations) - This claims to be able to provide a bulk stock level updater. I tested it out and was unable to expose the stock level as an update-able field. What's more, its idea of bulk updating involves setting the same value for all the items in the list. My solution allows for each product to have a different stock level set for it and it's also more intuitive to get going with.
Ubercart project page -> http://www.ubercart.org/project/uc_bulk_stock_updater
Comment #5
avpadernoComment #6
hiddentao commentedComment #7
hiddentao commentedMost recent code attached.
Comment #8
hiddentao commentedBulk stock updater now uses the 'bulk update stock' permission.
Comment #9
calbasiSubscriving (I'll test it later ;-) ). Thanks for the ubercart bulk stock comparing :-)
Comment #10
hiddentao commentedComment #11
hiddentao commentedComment #12
avpadernohook_uninstall()is not implemented; the module needs to remove the Drupal variables it defines.Form fields needs to be output using the FAPI functions provided by Drupal. Avoid escaping the string delimiter inside strings; if you need to use one of the string delimiters inside a string, then use the other delimiter for the string.
See http://drupal.org/coding-standards to understand how a module should be written. In particular, see which Unicode functions should be used, and how the code should be formatted.
SQL reserved words are written in uppercase letters; the reserved words include
AS(see http://drupal.org/node/141051 for a more complete list of reserved words).Also the copyright information would not be correct when you accept patches provided from other users; in such cases, the code is not copyrighted by Ramesh Nair anymore.
I would not suggest to use the implementation of
hook_perm()in that way; if the module would define more than one permission, the code would probably fail to verify if the user has the permission to access the menu callback. Then, that code could not be used for Drupal 7.[Edited by kiamlaluno to remove an extraneous tag.]
Comment #13
hiddentao commentedHi kiamlaluno, thanks for the reply.
I've made changes according to your suggestions and attached the latest code to this comment. Please let me know if these are sufficient.
Comment #14
hiddentao commentedJust came across the #ahah keyword: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....
I'm going to try and make my forms work this way.
Comment #15
hiddentao commentedAccording to http://drupal.org/node/305747:
I'm only performing a POST operation via AJAX and not recieving any content back except an error message (in case the server-side update failed). So I don't think #ahax is appropriate for my functionality.
Comment #16
hiddentao commentedRegarding
hook_uninstall() is not implemented; the module needs to remove the Drupal variables it defines., the module does not define any variables of its own. It re-uses theuc_reports_table_sizevariable from the uc_reports module.Do I still need to implement
hook_uninstall()?Comment #17
avpadernouc_bulk_stock_updater_stock_update()should probably use a theme function, as it is outputting HTML.Why is the module defining a menu callback to just redirect the user to a different page?
Thank you for your contribution! I am going to update your account.
These are some recommended readings to help with excellent maintainership:
You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
I thank all the dedicated reviewers as well.
Comment #20
avpaderno