Attributes that share same SKU as product does not work
| Project: | Ubercart Out of stock Notification |
| Version: | 6.x-1.3 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
When a product has attribute options that have the same sku as main product then the stock is not checked correctly against the main product and the module allows to add as many items as attribute options to the shopping cart.
.i.e.
Product ABC SKU# 1
Atribute 1 - option A SKU# 1
option B SKU# 1
Stock Level
Product ABC SKU#1 Quantitiy 1 Threshold 1
The module will allow two items to be added to the cart one for each attribute option A & B even though the Quantity for SKU 1 is set to 1.
Solution:
In file uc_out_of_stock.module
function uc_out_of_stock_getstockinfo add
$stockinfo['mainproduct'] = FALSE; at
if ($row->active) {
$stockinfo['stock'] = $row->stock;
$stockinfo['model'] = $row->model;
$stockinfo['mainproduct'] = FALSE;
}
also add
$stockinfo['mainproduct'] = TRUE; at
while ($row = db_fetch_object($result)) {
$stockinfo['stock'] = $row->stock;
$stockinfo['model'] = $row->model;
$stockinfo['mainproduct'] = TRUE;
}
In function uc_out_of_stock_validate_addtocart(...) change the if statement in the foreach look to
if ($item->nid == $nid && (!count($attrs) || !$stockinfo['mainproduct'] && count($attrs) && $item->data['model']==$stockinfo['model'] || $stockinfo['mainproduct'] && !$item->data['model'])) { ... }

#1
I will have to take a look at this, better if you can provide a patch. I really went through all of this cases, but may be these one went through.
#2
I created this patch file with WinMerge as a unified patch. please let me know if you need anything else.
#3
I think this is a strange use case, but a nice catch anyway. However, I believe that this still needs work. Your logic only assumes that this may happen for a main product, while this also may happen if the options share an SKU but not related to the main one. I am gonna investigate this a little bit more.
#4
OK, I think I have fixed the issue with a better approach, see if you can try the -dev version of today and see if that fixes yours. There's a bug I believe in ubercart, not 100% related to this, but definitely may lead to some incongruences. Just leaving it here for reference #374079: Numeric keyed SKUs handled improperly by hook_uc_product_models()..
#5
I looked at your changes on line 180 of uc_out_of_stock.module and I only made a small change before applying in my test environment and it is working great.
if ($item->nid == $nid && (( !count($attrs) || count($attrs) && $item->data['attributes'] == $attrs) || $stockinfo['model'] == $item->model) ) {
I added an extra parenthesis before !count($attrs) and after $item->model.
Thanks for such a great job with this module!!!
#6
Right, it would make sense. instead of the extra parenthesis I just enclosed them in the previous one:
if ($item->nid == $nid && (!count($attrs) || count($attrs) && $item->data['attributes'] == $attrs || $stockinfo['model'] == $item->model)) {
Thanks,
a.=
#7
Automatically closed -- issue fixed for 2 weeks with no activity.