Hi,
when creating a bulk product, I compose SKUs using size and color fields. When I submit the form, I get "This pattern yielded one or more duplicate SKUs, please use a different pattern." error.
Looking into code in commer_bpc.forms.inc file, I've outputed the value of $combinations array in commerce_bpc_create_bulk_form_validate function, just to see what kind of combinations were there (the array output is attached into a file).
At this point, I've seen strange values and I figured out that it could be a localization (multilingual site) problem. Can you confirm that? and how can I fix this problem?
Any help will be appreciated.
Comment | File | Size | Author |
---|---|---|---|
#9 | debug_2011_08_02.txt | 275 bytes | redna |
#8 | Issue-1233442-debug.patch | 664 bytes | sven.lauer |
#5 | debug_output.txt | 84.46 KB | redna |
commerce_bpc_array_output.txt | 3.32 KB | redna |
Comments
Comment #1
sven.lauer CreditAttribution: sven.lauer commentedI don't think this is a multilingual issue ... the structure of the array looks fine (the API docs on the combinations is completely out of date---I apologize), a combination should be a mapping from field names to complete field-api value array (i.e. the actual value for a list field would be at
$combination[field_name][language_code][delta]['value']);
The problem is the content of the array---the first three combinations are all identical:
Indeed, it seems that every combination was generated three times. Which of course leads to duplicate SKUs.
Can you post the content of the the "Allowed values" setting for both your list fields?
Comment #2
redna CreditAttribution: redna commentedThere are 4 different sizes (M,L,XL,XXL) and 5 different colors (gorria, urdina, berdia, txuria, beltza) in that product type.
But for this product there are 4 different sizes and just one color (txuria) so it was supposed to generate only 4 combinations.
Comment #3
sven.lauer CreditAttribution: sven.lauer commentedHm, I cannot reproduce the problem.
Can you tell me
- What version of core you are using?
- What version of Commerce?
- I assume you are using the alpha1 of bpc?
Ideally: Can you try to reproduce the problem on a clean install and tell me the steps you took, in order?
I also wonder where the factor three comes from (given that you have 2 fields, with 4 and 5 options and 4 and 1 selected option ...)
Comment #4
sven.lauer CreditAttribution: sven.lauer commentedAlso, could you perhaps put a
At the top of the declaration of
commerce_bpc_create_bulk_form_validate()
(in commerce_bpc.forms.inc) and attach the output here?Pondering this, with the current code, this could only happen (I think) if the values given by the
radio buttons for kolorea (Basque?) are, for some reason, repeated three times---as if you had
selected the value "txuria" three times (which is not even possible ...).
Comment #5
redna CreditAttribution: redna commentedHi,
I attach the output generared by the debug statements and the generated SKUs.
Looking at $form_state['values']['combinations'] it look like data is ok. For $form['combinations'] I'm not able to understand all it's values for now ;) but I'll try through the morning.
Comment #6
redna CreditAttribution: redna commentedI've looked at the value of $form_state['commerce_bpc'] and I've noticed that there were repeated values:
So I've searched where $form_state['commerce_bpc'] was set and I've made the following change so now the same value is only added once to the array:
Now I can succesfully create bulk products. Tell me if it is the right place to change the code.
Comment #7
redna CreditAttribution: redna commentedDue to extra debug information on my screen I haven't noticed that the previous change outputs some warnings. To avoid those warnings this might be better:
Comment #8
sven.lauer CreditAttribution: sven.lauer commentedThanks for the detective work!
Indeed, I see how the repetition you found would result in duplication of combinations.
However, while something like your change probably should be made as a failsafe measure, it does not really address the problem---for some reason, this hook gets called twice on each field in your setup. I'd like to get to the bottom of this and will leave the issue open for now ...
Could you apply the attached patch (against alpha1, assuming you are still using that) and post the debug output? The patch only adds a debug statement and can/should be reverted afterwards.
Sorry to keep asking you this, but as I cannot reproduce the problem ...
Comment #9
redna CreditAttribution: redna commentedHi,
I'm glad on helping you (and other), because I find this module very useful.
Well, I've done what you said (undo my changes to match alpha1 and add the debug line) and I think I've found the origin of the problem 'by surprise'. Let me explain:
After preparing the scenario, I went to create a bulk product and see what the debug line produced. I didn't care on what product I was creating because I thought that the duplicated SKUs error would raise and the products were not being created. But, for my surprise, the products were successfully created.
After this, I tryed to create another bulk product taking care of the values I was entering. At this time, the error raised, I was unable to create the products.
And what was the main difference between the two process: I added an image to the second bulk product. I tryed again without images and the products were sucessfully created.
So, at this point I can say that a image field using 'Media file selector' widget is creating the problem. Try it by yourself and confirm that you can also reproduce this behaviour.
I attach you also, the output for the debug line.
Hope all this helps
Comment #10
sven.lauer CreditAttribution: sven.lauer commentedHm, sadly, I still cannot reproduce the problem. But I think we are getting closer, now that we've found a way to selectively produce the issue on your system.
A question: On the two runs where the problem did not occur first and then occurred again, did you:
(a) use two distinct product types, one without an image field one with an image field OR
(b) use the same product type, but did not supply a value in the first run but did supply one in the second run?
Another thing: As you may have guessed, I screwed up when I rolled the debug patch: The line should have been
debug($form['static_values']);
. Could you change the line and run it again? I could roll another patch if it is too much of a hassle to do this by hand.Comment #11
redna CreditAttribution: redna commentedHi,
let's go with more information.
Answer B : i used the same product type but I did not suply a value in the first run but I did supply it in the second run.
Well, now, running new tests, I've realized that the problem comes when you supply more than one image into the image field. I supply two pictures for every product (T-shirt front side and T-shirt back side) so when I said that I was inserting an image (just one field in the form) I didn't realized that I was really inserting two images (sorry :( )
The 'Media file selector' widget provides "Add media" and "Add another item" buttons. And it looks like the "Add another item" button does some kind of (underliying?) form reloading when you press it: there is no need to select an image, just pressing the button the error will raise.
So, try inserting two pictures via 'media file selector' to see if you can reproduce the error
And here goes the debug line output
Comment #12
sven.lauer CreditAttribution: sven.lauer commentedAha! When I read your post, it immediately clicked. The problem is not the media module: You can reproduce the problem with any multi-value field.
The problem is that additional fields are loaded via ajax ... and in fact after every ajax-request, the form is being rebuilt (as the ajax-call submits the whole form, so it must be rebuilt in order to submit the form again later). Which means that the hook gets called again.
So, indeed, your fix above is exactly what should happen. The hook surely should run again if the form is being rebuilt, but it needs to take care to not log its activity twice.
Will roll a patch later today. Good work! This is a very general bug that surely would have bitten a large number of people!
Comment #13
sven.lauer CreditAttribution: sven.lauer commentedFixed!
Thanks again, redna, for you patient help!