Ajax Cart and the Out of Stock Notification are two great modules, so it would be great to get them to work together. Out of Stock Notification works until Ajax Cart is installed, but I'm not sure what module is causing the error.

Here are the issues I see with both 6.x-2.0-rc2 or 6.x-2.x-dev of Ajax Cart, and 6.x-1.x-dev version of Out of Stock Notification (the stable version is from 2009)
- With Ajax Cart enabled, a user can add-to-cart more product that is in stock (using the qty field and attributes).
- Then once the products (that are not really in stock) are in the cart, the user is trapped via a popup error out-of-stock message when they try to change qty (even to qty that is in-stock), OR try to remove the product from the cart. The error message stating something like "There are only x number of xyz product available" references another product in the cart, not the product trying to remove (see screenshot).
- The user cannot even checkout with an error message stating the products are not in stock. Sometimes the checkout page is presented un-themed (see screenshot), if they try to checkout right after trying to remove the product from the cart.
- Basically, by allowing the user to add more product than is available traps them, unable to make any changes to their cart, or checkout.

Thanks... I'm available immediately to test any updates.
Image1 - show what happend when I click to remove the "Medium" size, note the message references the "Small"
Image2 - screenshot after I try to remove product from cart, get the error message popup, then try to checkout.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nelslynn’s picture

The above seems only an issue when you have two models (or SKUs: ie: small, medium) of the same product in the shopping cart.

tunic’s picture

Assigned: Unassigned » tunic

Thanks for your detailed report and your availability to test. I'll try to have look soon.

marcus178’s picture

I'm experiencing the same problem as well. Even when only adding one product to the cart it seem to completely ignore uc_out_of_stock and still allow the user to add the item to their cart

tunic’s picture

Status: Active » Postponed (maintainer needs more info)

I'm afraid but it seems that there's something wrong with UC Out of Stock Notification module. I've trid to enable uc_stock and uc_out_of_stock and disable uc_ajax_cart and you can add as many items as you want without error (using Ubercart 2.4 and 2.6).

Also I couldn't reproduce your first screenshot error. Are you using antoher Ubercart and stock related modules?

nvl.sateesh’s picture

Dear nelslynn et all,

I experienced the same issue and tried debugging. Here is what I found.

In the uc_out_of_stock.module file, in uc_out_of_stock_validate_form_addtocart() function, there is a condition that checks for the class of the button from which the add to cart is triggered.

  $class = $form_state['clicked_button']['#attributes']['class'];

and performs stock validation only on specific classes

  if ($class == 'node-add-to-cart' || $class == 'list-add-to-cart') {
    $attrs = $form_state['values']['attributes'];
    $nid = $form_state['values']['nid'];
    $error = uc_out_of_stock_validate_addtocart($nid, $attrs);
    if ($error !== FALSE) {
      form_set_error('uc_out_of_stock', $error);
    }
  }

I noticed that when Ubercart Ajax Cart is installed, the $form_state['clicked_button'] is not passing any values and hence the if condition is return false, and no stock validation is being done.

I did not have time to check why it is not returning the clicked_button variable. For time being, i just removed that if condition and it works fine.

nvl.sateesh’s picture

I am not sure if this issue is applicable for the Drupal 6 also, but a mention is here about the $form_state['clicked_button'] with ajax submissions: http://drupal.org/node/1049462

tunic’s picture

Status: Postponed (maintainer needs more info) » Needs review

Thanks sateesh.nvl, I'll have a look to this issue ASAIC.

hanoii’s picture

Maintainer of the uc_out_of_stock module here. I am about to try a site with both modules enabled, so I might try to sort this out.

hanoii’s picture

I have looked into this, however, this is not a straightforward fix.

Attach is a patch that adds clicked_button to the submitted form as explained in #5. Although this now prevents the form to be added because of uc_out_of_stock validation, it doesn't give any indication of doing so. And this is not something I can fix easily on this module or mine. Actually is more of a fix to this module than mine.

I will, however, post related thoughts about this on #837176: Less Intrusive Status Update for Customer, because it has to do with proper status messages.

As far as the original report of this issue, I'd like to comment on each of the issues:

- With Ajax Cart enabled, a user can add-to-cart more product that is in stock (using the qty field and attributes).

As explained, this should be now fixed.

- Then once the products (that are not really in stock) are in the cart, the user is trapped via a popup error out-of-stock message when they try to change qty (even to qty that is in-stock), OR try to remove the product from the cart. The error message stating something like "There are only x number of xyz product available" references another product in the cart, not the product trying to remove (see screenshot).
- The user cannot even checkout with an error message stating the products are not in stock. Sometimes the checkout page is presented un-themed (see screenshot), if they try to checkout right after trying to remove the product from the cart.
- Basically, by allowing the user to add more product than is available traps them, unable to make any changes to their cart, or checkout.

I believe this is because of how the ajax thing works. Basically if you remove the actual product that is out of stock and you reload the page, this remove the out of stock errors because the item is actually removed from the cart, but there are issues here that I haven't followed in detail, but I think it should work fine if you try to work the cart in a non-ajax way, even with out of stock items in the cart.

hanoii’s picture

Aha, forgot the patch.

I'd suggest to mark this one as fixed and continue status message discussions later. But maybe leave this one open for references as it's not 100% fixed.

tunic’s picture

Status: Needs review » Fixed

Thanks for your help hanoii, your patch seems ok and allows uc_out_of_stock to perform its validation.

I thought is was incomplete because you can still add more items that available using the cart page form, but I you can do it without Ajax cart, so I suppose is not an Ajax Cart issue.

I close this issue an d let discuss notifications in the other issue:
#837176: Less Intrusive Status Update for Customer

I've tested this patch very quickly, don't hestiate to corect me if there's something wrong.

Status: Fixed » Closed (fixed)

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

ledom’s picture

Thank you for the patch hanoii, just tested and it works like a charm.
A status message would be good when buyer add more products than stock level and none are added to cart, or just add the maximum quantity.

I think we could open a new issue for this, no? because it is much specific than "less intrusive status update..."

hanoii’s picture

Version: 6.x-2.0-rc2 » 7.x-2.x-dev
Status: Closed (fixed) » Active
FileSize
1.2 KB

This is also an issue on the D7 branch. This got accepted on D6 a while ago but it's not on D7 and now that uc_out_of_stock is for D7 as well, the same issue is there.

Attached is the same patched rolled out for D7.

hanoii’s picture

Status: Active » Needs review
Neo13’s picture

Status: Needs review » Reviewed & tested by the community

I tried this patch and it works great!

himagarwal’s picture

This patch should be applied to the D7 core of Ubercart AJAX Cart.

tunic’s picture

Status: Reviewed & tested by the community » Fixed

Seems ok, committed to dev.

Status: Fixed » Closed (fixed)

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