Problem using uc_importer to Import Adjustments

Posts: 25
Joined: 12/19/2007

I'm using ubercart alpha 8. I have a single test product which has a few adjustments applied to about half of the options. When I import the product the adjustments don't get associated with the correct option. The steps I'm doing:

  1. I use the exporter module to generate a dump of the product
  2. I delete the product from drupal
  3. I use the importer module to re-create the product using the XML file from step 1
  4. The adjustments are all associated to different options on the new product

Looking in the database I see this in the uc_product_adjustments module:
Original product:

44  a:1:{i:3;s:1:"5";}  NK-0105-GF2
44 a:1:{i:3;s:1:"1";} NK-0105-GF
44 a:1:{i:3;s:2:"17";} NK-0110-22
44 a:1:{i:3;s:1:"3";} NK-0102-SS

New, imported product:

47  a:1:{i:3;s:1:"9";}  NK-0105-GF2
47 a:1:{i:3;s:1:"4";} NK-0110-22
47 a:1:{i:3;s:1:"3";} NK-0105-GF
47 a:1:{i:3;s:1:"1";} NK-0102-SS

It seems to be just setting the adjustments to the first 4 options it finds instead of setting it to the option specified in the xml file. Am I doing something wrong for importing adjustments or is this a bug?

Posts: 2244
Joined: 08/07/2007
AdministratoreLiTe!

Are you getting duplicate options when you import? Since you're exporting and importing from the same site, the option IDs and names ought to be the same.

Posts: 25
Joined: 12/19/2007

No, I'm not getting any duplicate options. I'm not sure where/how those duplicate option ids are coming from.

Posts: 25
Joined: 12/19/2007

Well, I've tracked it down. Basically the form data gets mangled when drupal creates the post data. From what I can see I don't think importing adjustments should be working for anybody using alpha8 or above.

Anyhow, the flow of the problem looks like this:

First, in the uc_importer.module drupal_execute is called to simulate the submitting of the adjustments form. The $adjustments data going into the function looks like:

[body] => Array
   [0] => Array
                                        (
                                            [combo_array] => a:1:{i:3;s:1:"5";}
                                            [model] => NK-01
                                        )

But, by the time it gets to the uc_product_adjustments_form_submit function the submit data looks like:

body] => Array
                                (
                                    [0] => Array
                                        (
                                            [combo_array] => a:1:{i:3;s:1:"3";}
                                            [model] => test
                                        )

                                    [1] => Array
                                        (
                                            [combo_array] => a:1:{i:3;s:1:"1";}
                                            [model] => NK-01
                                        )

                                    [2] => Array
                                        (
                                            [combo_array] => a:1:{i:3;s:1:"5";}
                                            [model] => NK-01
                                        )

Basically, because not every adjustment is set in $adjustments drupal merges them which results in messed up data.

The solution I came up with may not be completely "correct" as it calls the submit function directly. But it beats trying to reproduce the array of default adjustments. What I did:
Replace this line (~1154 in uc_importer.module):

drupal_execute('uc_product_adjustments_form', $adjustments, $product->nid);

With:

uc_product_adjustments_form_submit('uc_product_adjustments_form', $adjustments);