Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I read in the plan for commerce kickstart 2 that you concidered stock levels but ran out of time.
The module http://drupal.org/project/commerce_stock seems to work ok.
It would be nice to be able to edit the stock quantities like the price is admin/commerce/products under the quick edit link.
How could I make the stock levels editable inline?
Thanks for any help
Comment | File | Size | Author |
---|---|---|---|
#7 | commerce_backoffice_snippet.txt | 16.41 KB | coyoterj |
#6 | commerce_backoffice_snippet.txt | 2.61 KB | coyoterj |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedwould love to know too!
Comment #2
Maestro232 CreditAttribution: Maestro232 commentedUpvote, but extend this further to the "Disable Stock For this Product" option.
Comment #3
jsacksick CreditAttribution: jsacksick commentedThe quick edit form is provided by the Commerce Backoffice module.
There's no UI no manage that.
Here's the code that manage that part :
If you want to alter that, you could alter the form add the fields you want and replace our submit callback.
Comment #4
Maestro232 CreditAttribution: Maestro232 commentedFair enough.
Comment #6
coyoterj CreditAttribution: coyoterj commentedHi,
I'm trying to make a patch, but when i saved the value of stock and reload the page, only the first digit was saved. Eg. enter 423 => saved 4
My code snippet:
At this moment, I don't run verification modules, etc.
Why only the one first digit is saved ?
Thanks!
Comment #7
coyoterj CreditAttribution: coyoterj commentedSolved by correcting:
To:
Now, the value of the stock can changed here.
This is my first contribution to code, so my apologies to any failure. ;)
Comment #8
rbosscher CreditAttribution: rbosscher commentedThanks coyoterj for the inspiration but I think its better to use a alter function like jsacksick suggested.
This function you can use in a custom helper module
Comment #9
coyoterj CreditAttribution: coyoterj commentedHi rbosscher,
I knew it had to do, but did not know how. :)
Well... I put the code in my module, but not worked. The field "stock" does not appear in the form :(
Yes, I cleaned all caches. :)
Then, I will study your solution and post here if I find something.
Thanks!
Comment #10
rbosscher CreditAttribution: rbosscher commentedProbably obvious, but just to be sure:
Make sure you replace YOURMODULE with your module name (its in there 3 times)
Make also sure your stock field has the machine name commerce_stock (Not sure this could be anything else but will not hurt to check)
Safe, clear caches, fingers crossed... :)
Comment #11
coyoterj CreditAttribution: coyoterj commentedYes, I replaced the name YOURMODULE.
Yes, the fields's name is the same. You can check in previous posts.
Does the problem is not here ?
$form['#submit'][] = 'YOURMODULE_commerce_backoffice_product_quick_edit_form_submit';
I say this because of ajax call:
'callback' => 'commerce_backoffice_product_quick_edit_form_ajax',
Comment #12
rbosscher CreditAttribution: rbosscher commentedOverwrites the default submit handler (commerce_backoffice_product_quick_edit_form_submit) with the new attached submit handler
I Think I know what the problem is:
replace
whit:
Comment #13
coyoterj CreditAttribution: coyoterj commentedHi rbosscher
Forgot a small detail ??
Or it was just a test with me ? :)
The problem is here:
Replace with:
1.
function YOURMODULE_
form_commerce_backoffice_product_quick_edit_form_alter(&$form, &$form_state, &$product){
And
2.
$form['commerce_stock'] = array
with$form['stock'] = array
3.
$product->commerce_stock[LANGUAGE_NONE][0]['value'] = $form_state['values']['commerce_stock'];
with$product->commerce_stock[LANGUAGE_NONE][0]['value'] = $form_state['values']['stock'];
Yes! Now it works! :D
Thanks a lot, today I will update the module without fear :D
Comment #14
coyoterj CreditAttribution: coyoterj commentedI put the full patch here:
https://gist.github.com/coyoterj/6247377
Comment #15
candelas CreditAttribution: candelas commentedi am going to try this code, but i need it for two different forms, one for one worker that only can change stock and other for the director that can change price. for what i understand, this formula will affect both forms.. so should i use the same form and hide fields by permissions?
thanks for any tip ;)
Comment #16
candelas CreditAttribution: candelas commentedthanks @rbosscher and @Icoyoterj for the documentation.
at the end i my client change his mind and workers will be able to change the price and i dont have to resolve that problem.
@Icoyoterj a minor correction, you should change in line 15 from
$form['#submit'][] = YOURMODULE_commerce_backoffice_product_quick_edit_form_submit';
to
$form['#submit'][] = 'YOURMODULE_commerce_backoffice_product_quick_edit_form_submit';
i used your code and i want that product state doesnt show in the quickedit form but i get a notice:
Notice: Undefined index: status in commerce_backoffice_product_quick_edit_form_submit() (line 375 of /home/ftp/xxx/profiles/commerce_kickstart/modules/contrib/commerce_backoffice/commerce_backoffice_product.module).
my module
i will appreciate if you give to me any tip, since i am learning to work with forms in drupal :)
Comment #17
rbosscher CreditAttribution: rbosscher commentedif you add above the line
$form['stock'] = array(
the line:
unset($form['status']);
You should get rid of the notice and the field.
Comment #18
candelas CreditAttribution: candelas commented@rbosscher thanks for your fast answer, i did it but i keep getting the notice (i truncate the cache tables on the db).
the code
Comment #19
rbosscher CreditAttribution: rbosscher commentedCan you tell me what the notice is and on which line it is and give the corresponding line?
Your previous posted notice is in the submit handler commerce_backoffice_product_quick_edit_form_submit
while your custom submit handler is: ocultar_vt_commerce_backoffice_product_quick_edit_form_submit
Comment #20
candelas CreditAttribution: candelas commentedthe notice always is
Notice: Undefined index: status in commerce_backoffice_product_quick_edit_form_submit() (line 375 of /home/ftp/xxx/profiles/commerce_kickstart/modules/contrib/commerce_backoffice/commerce_backoffice_product.module).
maybe i have to unset in the MYMODULE_commerce_backoffice_product_quick_edit_form_submit?
thanks
Comment #21
candelas CreditAttribution: candelas commentedi found the solution. instead of
in
function MYMODULE_form_commerce_backoffice_product_quick_edit_form_alter(&$form, &$form_state, &$product){
i used
and the warnings went away :)
i hope someone can use it!
thanks @rbosscher
Comment #22
candelas CreditAttribution: candelas commentedComment #23
zooter626 CreditAttribution: zooter626 commentedthanks @coyoterj for #14 and @candelas for the minor correction. code works great, and it's exactly what i needed!
Comment #24
andyg5000Here's an updated example that doesn't use LANGUAGE NONE and includes validation
Comment #25
rbosscher CreditAttribution: rbosscher commentedThinking about this further.
We could do someting like:
Actually we could easely create a ui for the module so you can select wich fields to use in the quick edit form
Comment #26
lanetterm CreditAttribution: lanetterm commentedI took the andyg5000 's code from comment 24 and wrapped a module around it.
Works great, does just what I need - Thanks Andy
I uploaded it to github, thinking it might save someone else a few minutes.
https://github.com/lanette/commerce_stock_quick_edit
Comment #27
szymon.l CreditAttribution: szymon.l commentedThis functionality is great, but I have problem with the code from @andyg5000
After enabling module, and clicking "quick edit", I have an AJAX ERROR:
this line is pointing to this function:
help would be appreciated..
Comment #28
georgemastro CreditAttribution: georgemastro commentedSame problem here as #27
Comment #29
szymon.l CreditAttribution: szymon.l commentedWhen I got rid of commerce wishlist module, my error changed to:
Comment #30
shanejensen CreditAttribution: shanejensen commentedI was having the same issue reported in #29. The problem appears to have been caused by Views Bulk Operations not being enabled because the version of PHP running was lower than 5.29 which is required by VBO. Once PHP was upgrade and VBO was operational the issue went away.
Comment #31
szymon.l CreditAttribution: szymon.l commentedin my case, VBO is enabled and my php ver is 5.5.3 (one server) and 5.3.16 on the other...
Comment #32
Zekvyrin CreditAttribution: Zekvyrin commentedthx andyg5000 & lanetterm for the code
Yes it did save me some time :)
Comment #33
Collins405 CreditAttribution: Collins405 commented#26 works perfectly for me with latest commerce kickstart
Comment #34
RAWDESK CreditAttribution: RAWDESK commented#26 works for me too! thanks for the contribution!
Within a few weeks i will investigate this wrap-up to have additional fields enabled, such as split currency prices added through the Multicurrency module :
https://www.drupal.org/project/commerce_multicurrency
Comment #35
Anonymous (not verified) CreditAttribution: Anonymous commentedThis is a little old already, but I think I'm not the only one looking for a good solution for adding fields to the quick edit form.
#24 works fine, so thank you for that! Although at first I got an ajax error (500) when I clicked the quick edit -button, but it was solved by turning off the Drupal For Firebug -module. I don't know why that happened, but if someone has any kind of clue, feel free to clarify!
I think an UI for adding/removing fields would be a nice add.
Comment #36
spgd01 CreditAttribution: spgd01 commentedSWEET #26 works great! thanks. Can we add a IU for adding removing fields to the quick edit Backoffice module? Or perhaps instructions on how to edit the proper view?
thanks.
Comment #37
drakythe CreditAttribution: drakythe commented#26 does work great, with one minor exception: If you try to use the quickedit stuff outside of the provided backoffice megarow view, you get a fun error where $form_id has been converted from a string to an object. I submitted a pull request on Github to fix the issue.
Comment #38
DaleTrexelThank you lanetterm in #24 for the module version! It looks like drakythe's pull request has not been granted, but I can confirm that it is an important fix to apply, especially when using the quickedit form outside the Backoffice Product variations form.
However, I have another problem when using the module (patched) outside the Backoffice Product variations form: the form works fine the first time you use it, but if you go back and update a variant a second time without re-loading the view, the variant's values in the quickedit form gets applied to every other variant visible in the view! This is especially bad without an easy undo function.
The quickedit form seems to work fine when used in its original state (price & activity state editing only), both within the "Commerce Backoffice: Product variations (Commerce Product)" view and other views you might add the field to. (I created a view for all variants with the goal to more easily update stock and shipping details on a single page, without having to toggle forms into view.) However, once I used hook-form-alter to add fields to the form, the form started misbehaving. I tried initially with a custom module that does basically the same as what lanetterm's module does (but with shipping dimensions too), then I switched to lanetterm's module to see if the problem was general or specific to my own module. It seems to be something with the general approach.
Once the new fields and callbacks are added to the original quickedit form, something about the form changes such that each quickedit form in a list of variants works properly the first time, but if you submit a second time, the whole page reloads and the form's values are applied to each variant on the page. I presume some form property/value is not being properly re-set after the initial form submission, but so far I haven't been able to figure out what it is, or how one might fix it.
What seems weird is that the quickedit form continues to work properly on the Backoffice Product variations page; it's just the new view where the quickedit forms misbehave.