If a user puts an item into their cart and then while shopping the item goes out of stock it can be impossible for them to remove the item from their cart because when they do an error message will be given: "We're sorry. The product X is out of stock."

Attached patch ensures stock validation is not run when items are being removed from cart by remove button or by updating qty to 0.

Comments

hanoii’s picture

Would this patch still works with the checkbox approach of ubercart 2.4?

jrust’s picture

It certainly wouldn't break things in 2.4, because it just makes sure not to run the validation if the remove button is clicked. If there is no remove button in the form, then this patch doesn't affect anything. However, it could be that out-of-stock items in UC 2.4 might not be able to be removed via the checkbox method, but they could still change the qty to 0.

hanoii’s picture

hanoii’s picture

+++ b/uc_out_of_stock.moduleundefined
@@ -391,7 +391,9 @@ function uc_out_of_stock_validate_form_checkout($form, &$form_state) {
+  if (!empty($form_state['clicked_button']['#name']) && substr($form_state['clicked_button']['#name'], 0, 7) != 'remove-') {

Do you think is there any chance form_state['clicked_button']['#name'] is empty and that I might have to actually run validation.

I don't think so, but I prefer to only add the conditions that are necessary.

Maybe

substr($form_state['clicked_button']['#name'], 0, 7) != 'remove-'

is enough.

I am going with that, see if you have any opinions. I have changed/added some comments and also move the qty > 0 condition you have added a little bit above the code for not running a function that's not necessary, can you try this patc

hanoii’s picture

StatusFileSize
new2.96 KB

I am committing this patch, can you please try it out, if it works I will release a new version with this and another bug fixes reported since 1.6

jrust’s picture

Patch looks good -- I just added the !empty() check to avoid an undefined index notice out of habit, but I doubt it's necessary unless running E_STRICT. Thanks for committing.

hanoii’s picture

Status: Needs review » Fixed
dsbrianwebster’s picture

Tested this patch. It applied smoothly and the issue was resolved.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.