uc_stock Change how the query works

Project: 
Ubercart
Category: 
bug report
Priority: 
normal
Status: 
active

There is an issue that I have encountered using the uc_stock module to create a contribution that prevents people from adding items to the cart if they are tracked and no longer have stock.

<?php
function uc_stock_level($sku) {
  return
db_result(db_query("SELECT stock FROM {uc_product_stock} WHERE sku = '%s'", $sku));
}
?>

This is the function in uc_stock.module currently. The issue subtle, say you have inventory for a product and it is tracked, and then you want to stop tracking it, but still sell it. This will always return the stock amount even though it is not being tracked anymore.

I changed the function above as follows to allow some logic in my module to work:

<?php
function uc_stock_check_level($sku) {
  return
db_result(db_query("SELECT stock FROM {uc_product_stock} WHERE active = 1 AND sku = '%s'", $sku));
}
?>

If this change can be made in core I have a module that I can contribute to prevent shoppers from adding more than is available, and also correct if the quantity has changed before they checkout.

Cheers,
Gord.

Re: uc_stock Change how the query works

Hmm... I'll have to consider what the purpose of that function should be. It might just be better for you to use your query directly when necessary and leave the core function as is, at least for Ubercart 1.0.

Re: Re: uc_stock Change how the query works

I checked this out briefly yesterday and came down on leaving it as is in core. At this point, I just don't have the time to fully scope the module and see how we can improve its API. However, if you or someone else were to take the stock module on as their pet project, I'd be happy to review and commit feature patches in the next round of development.