With stock tracking enabled on a product, I am still able to use the quantity input field on a view to add a large quantity to my cart, exceeding the available stock. I can complete the order and the stock level ends up being large and negative.
The way the commerce_stock module works is to provide validation functions for the checkout and add to cart forms, but of course it doesn't do anything to the form created by commerce_add_to_cart_extras_handler_field_quantity.inc.
I'm not sure whether writing a stock check into that file is the right approach, or if there's a better way that this module could be made to respect stock limits.
Comment | File | Size | Author |
---|---|---|---|
#5 | commerce_add_to_cart_extras-validate_stock-1440944.patch | 2.45 KB | AaronBauman |
Comments
Comment #1
AaronBaumanbump
Comment #2
mglamanFor the curious, here's how I implemented the stock check via form_alter() in a custom module.
Comment #3
lsolesen CreditAttribution: lsolesen commentedAny reason why it is not added to this module with a check for whether the stock module exists?
Comment #4
mglamanI only posted snippet because I have a feeling one of the RTBC'd patches will cause this patch to fail. Was going to see if RTBC could get pushed through then write proper patch.
Comment #5
AaronBaumanHere's a patch.
Comment #6
joelpittetWould providing a hook here be useful so we can provide integration a bit better?
Comment #7
bisonbleu CreditAttribution: bisonbleu commentedI copy-pasted the code snippet in #2 in a custom module but it does not stop someone from adding more products than available in stock. I do realize it dates from 3 years ago. That being said, the checkout validation prevents that. I also tried the patch without success.
Comment #8
bisonbleu CreditAttribution: bisonbleu commentedAh! I think I get it now. The code does not validate if there's enough stock to satisfy the bulk Add-to-cart form. But it will disable the quantity field in the bulk Add-to-cart form when the product is out of stock.
So we first need to be out of stock before this code kicks in.
But let's say product A has a stock level of 5. Any ideas how I could strop the Add-to-Cart from submitting if Quantity for product A is set to 6 or more?