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.
If ProductA has 5 in stock, and I add 5 or less to the Cart, I can continue to add 5 or less to the cart regardless of the cart's existing quantity.
Obviously moving to Checkout or updating the cart from the cart page reveals the stock validation error, however this still means the user has more items in their cart than they can purchase, and the stock levels are not automatically reduced, meaning that the user needs to manually lower the stock levels to get around the error.
Comment | File | Size | Author |
---|---|---|---|
#13 | EntityMetadataWrapperException_v1_1290842_13.patch | 833 bytes | guy_schneerson |
#11 | line_item_type_check-1290842-11.patch | 823 bytes | hibersh |
#8 | take_cart_quantity_into_account-1290842-8.patch | 2.57 KB | guy_schneerson |
Comments
Comment #1
guy_schneerson CreditAttribution: guy_schneerson commentedHi @carn1x,
Yes i am aware of this issue. The initial goal was to make sure users cant order out of stock items and make sure the module operates securely and with no errors, i was planning of adding this functionality as part of version 2 but may try and do it before as i agree it is not the best user experience.
i am downgrading priority to Normal, as most of the issues raised so far actually stooped the module from working as described above.
Comment #2
carn1x CreditAttribution: carn1x commentedThanks a lot :)
Comment #3
carn1x CreditAttribution: carn1x commentedOk in the interests of time, I hacked the commerce_stock.module and changed the following function:
Since you're aware of this issue and working on V2, I won't bother rolling a patch, please anybody let me know if I can improve the code at all. Still very noobish regarding what functions commerce and entity API provides :)
Comment #4
guy_schneerson CreditAttribution: guy_schneerson commentedHi @carn1x,
looks good if you got time to add a patch i will include it in version 1, let me know if you don't and ill make the change when i get a chance.
Comment #5
joachim CreditAttribution: joachim commentedSeveral points:
- this fix doesn't cover the case where one product node shows multiple products -- the commerce_stock_add_to_cart_validate validator is not added to the form in this case. we probably need a new, separate validator to handler already-in-cart stock checks
- secondly, I'm not sure this is the best way to deal with the use case. What if there are two widgets, and Alice adds one to her cart, then Bob adds one to his, and Alice adds one more to her cart? Who wins? Is it whoever reaches checkout first? Admittedly, this makes the whole stock control rather more complex, because it becomes a resource allocation system, and you have to build a system for releasing resources after a certain time. Basically, adding an item to your cart would mean you decrease stock count and have it for a certain time. Also, not all sites would necessarily want this model. One for another issue, I think.
- code style in the patch: comments should be full sentences; variables shouldn't use abbreviations; run the code through Coder module for other tweaks :)
Comment #6
joachim CreditAttribution: joachim commentedAh, my second point seems to be covered here: #1182404: Allow management of stock based on in-cart status of products
Comment #7
guy_schneerson CreditAttribution: guy_schneerson commentedThanks @joachim this patch is unlikely to go into the V1 as I have now started work on version two and will review this functionality for all cases.
Comment #8
guy_schneerson CreditAttribution: guy_schneerson commentedpatch based on the stock V2 function for taking the current Cart quantity into account for the add to cart functions.
Comment #9
guy_schneerson CreditAttribution: guy_schneerson commentedcommitted http://drupalcode.org/project/commerce_stock.git/commit/4085e5f
Comment #11
hibersh CreditAttribution: hibersh commentedpatch adds line item type check, avoid exception for entitymetadata wrapper
Comment #12
guy_schneerson CreditAttribution: guy_schneerson commentedthanks @hibresh i think you solved an issue that was responsible for http://drupal.org/node/1411032#comment-5575072, I am going to look into this and a few other issues this weekend.
I think the correct way to handle this will be by making sure $line_item->type is in commerce_product_line_item_types().
missed that out :(
Comment #13
guy_schneerson CreditAttribution: guy_schneerson commentedpatch fixes the issue adds a check that the line item is a product, i am committing this for both version 1 and 2.
Comment #14
guy_schneerson CreditAttribution: guy_schneerson commentedcommitted
V1: http://drupalcode.org/project/commerce_stock.git/commit/74f61a7
V2: http://drupalcode.org/project/commerce_stock.git/commit/f612733
Comment #15
guy_schneerson CreditAttribution: guy_schneerson commentedComment #16
carn1x CreditAttribution: carn1x commentedAwesome thanks :D