When you have multiple price fields for the same product and you have only tax rates of one type, you get an warring when you load the product form. The previously selected tax rate is unselected.

Here the error:

Warning: Invalid argument supplied for foreach() in commerce_tax_field_attach_form() (line 309 of /var/www/drupal7.dev.customweb.ch/modules/contribution/commerce/modules/tax/commerce_tax.module).

The problem is that you flat the $options array with the taxes for the first field, because you have no other tax type. For the next field we try to access an already flatted $options array (line 309). This leads to a warring and the wrong $default value. So we need to flat it and store it in another array. We should not touch the other full $option array, because then we need to double check in which form the array is. This is much more complicated then using a separate array for the form element.

The following change resolves the problem:

<?php
            // If there is only one option group, flatten the options array.
            $form_options = $options;
            if (count($form_options) == 1) {
              $form_options = reset($form_options);
            }
?>

We set then the form options with the new $form_options array.

See the patch for more information.

CommentFileSizeAuthor
#1 1136866.patch1.21 KBmikejoconnor
muliple-prices.patch1.07 KBhunziker

Comments

mikejoconnor’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new1.21 KB

I rebuilt the patch with git diff.

This looks good.

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

Ahh, checked this over with Mike earlier but just decided we don't need the intermediate step at all. I just made this an inline if statement in the form element definition. : )

Committed! http://drupalcode.org/project/commerce.git/commitdiff/e50cc25

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.