Closed (fixed)
Project:
Ubercart
Version:
6.x-2.0-rc3
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
13 Feb 2009 at 19:00 UTC
Updated:
7 Jul 2009 at 14:08 UTC
Jump to comment: Most recent file
I have a membership product with several options depending on length of membership. I've created different SKUs for these options in Adjustments and a separate role assignment feature for each of them. But the role is not assigned when I buy either of these products. On Features screen, SKUs for these role assignments are listed incorrectly, looks like this may be the problem. I've browsed the code but so far haven't been able to find out where these model numbers are coming from came from.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 374079.uc_product_get_models.fix_.patch | 500 bytes | hanoii |
| #7 | 374079.uc_product_get_models.2.x.patch | 2.43 KB | cha0s |
| #5 | uc_product.get_models.patch | 2.39 KB | cha0s |
Comments
Comment #1
julia_g commentedOK, I've figured out what's going on.
My adjustment SKUs are all numeric. The function array_merge_recursive in module_invoke_all takes the correct model array and merges it with empty array, and in the process numeric keys are lost and start with 0. See comments at http://us.php.net/manual/en/function.array-merge-recursive.php .
I've solved the problem by adding letters to my SKUs, but someone may want to write a patch to avoid this issue.
Comment #2
julia_g commentedThis may cause problems in other modules, so I'll resubmit is as Drupal core bug.
Comment #3
Island Usurper commentedI don't really think Drupal is wrong to use array_merge_recursive() in module_invoke_all(). It's behavior with numeric keys is well known and documented, so we should be able to work around it. Where is this call to module_invoke_all() where the SKUs are used as keys?
Comment #4
cha0s commentedI have identified the problem, and offer a solution.
hook_uc_product_models() has been updated. Now, you do not map the array keys to the values here. You just create an array of values, and return that. The work of mapping the values to respective keys is now handled by uc_product_models(), using drupal_map_assoc().
On top of that fix, I also organized the logic better, so that any model that comes before 'Any' alphabetically won't supplant it as the first option.
Added an entry in hooks.php as well, noticed there was no doc of this (new) hook yet.
Comment #5
cha0s commentedEr, oops. :)
Comment #6
Island Usurper commentedActually use "hook_uc_product_models()" in hooks.php. This keeps api.module from getting confused with two functions of the same name, and people will actually search for "hook_". Keep the actual code from uc_attribute_uc_product_models() as an example, though.
Comment #7
cha0s commentedGood call, missed that one.
Comment #8
Island Usurper commentedLooks good. Committed.
Comment #10
hanoiiSorry to bring this one up to life, but I have found a problem in the committed patch, causing a bug which have been annoying me for a while and now I was able to locate the problem, which pointed me to this issue after some search.
I was noticing that with certain combinations of SKU I was always missing one on the STOCK edition page.
The patch should be self-explanatory, but to explain what I found:
Say you have a product with its main SKU = 2
Then you have a Color attribute with three different colors and its respective SKU adjustments:
BLUE: 2b
RED: 2r
YELLOW:2y
Then if you go to the stock edition screen, you won't three the four SKUs (main + 3 from colors), but you would see only three (main + two of the adjustments). I first figured that this was intentionally but then, and while working with my uc_out_of_stock module I found it's not. The problem is that the uc_product_get_models() that was improved by this patch is not expecting an associative array from $models = module_invoke_all('uc_product_models', $node); but rather a linear one, but after invoking that hook, there's a line who arbitrary changes the array using the $node->model as a key for the array. As in this case, $node->model would be 2, what's really happening is that it's overwriting the second item of the array, thus, loosing one of the adjustments.
My proposed solution should not mess anything as drupal_map_assoc() below should do the same but properly.
Anyway, patch attached with just one line changed which I think solve this.
Comment #11
hanoiiComment #12
Island Usurper commentedIt looks like that change has already been done: #479856: Stock table missing SKUs