I get this error message when I edit or create a subscription

Notice: Undefined offset: 2 in uc_price_per_role_form_alter() (line 227 of xxx/modules/new/uc_price_per_role/uc_price_per_role.module).
Notice: Undefined offset: 1 in uc_price_per_role_form_alter() (line 227 of xxx/modules/new/uc_price_per_role/uc_price_per_role.module).

And doesn't assign the role to the paid user

Thanks

Comments

3rdLOF’s picture

I get a similar error when viewing a product.


Notice: Undefined offset: 27 in uc_price_per_role_form_alter() (line 227 of /Users/xxx/Sites/xxx/sites/all/modules/contrib/uc_price_per_role/uc_price_per_role.module).
Notice: Undefined offset: 26 in uc_price_per_role_form_alter() (line 227 of /Users/xxx/Sites/xxx/sites/all/modules/contrib/uc_price_per_role/uc_price_per_role.module).
Notice: Undefined offset: 28 in uc_price_per_role_form_alter() (line 227 of /Users/xxx/Sites/xxx/sites/all/modules/contrib/uc_price_per_role/uc_price_per_role.module).
Notice: Undefined offset: 25 in uc_price_per_role_form_alter() (line 227 of /Users/xxx/Sites/xxx/sites/all/modules/contrib/uc_price_per_role/uc_price_per_role.module).

goodeit’s picture

I have this issue as well. It appears that going to the option prices page (node/#/edit/option_prices) and filling in all the empty boxes with 0s will make most of the messages go away. I'm looking into a way to fix this and make the values default to 0.

goodeit’s picture

One of the messages I was getting was an undefined offset: with an empty offset. This is due to the attributes array #options index including "Please select" as an empty offset:

    [attributes] => Array
        (
            [1] => Array
                (
                    [#type] => select
                    [#default_value] => 
                    [#options] => Array
                        (
                            [] => Please select
                            [3] => Large
                            [2] => Medium
                            [1] => Small
                        )

                    [#title] => Size
                    [#description] => 
                    [#required] => 1
                )

            [#theme] => uc_attribute_add_to_cart
            [#tree] => 1
            [#weight] => -1
        )

To work around this, I changed line 227 to the following:

              if(is_numeric($oid)) {
				$price = uc_price_per_role_find_price($role_prices[$oid]);
			  }
			  else {
				$price = FALSE;
			  }

I'm still working on setting the default values if the options are not in the database.

goodeit’s picture

Status: Active » Needs review

I realized that instead of setting default values for every attribute option for every role, it's much better to let the existing defaults take over when the option price for a particular role is blank.

Thus, the fix is very simple, and in fact can be found another place in the price per role module (line 369): simply check if the uc_price_per_role_load_option_prices() call returned a new price for that particular option using isset($role_prices[$oid]).

Here is a solution that takes care of both the empty offset message mentioned in #3, and the errors from #1 and #2. This code replaces line 227:

  if(isset($role_prices[$oid])) {
	$price = uc_price_per_role_find_price($role_prices[$oid]);
  }
  else {
	$price = FALSE;
  }
DanZ’s picture

Status: Needs review » Fixed

Committed #4, thanks!

Status: Fixed » Closed (fixed)

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