When trying to add a NEW email conditional action on a failed renewal I get the following error:

Fatal error: Unsupported operand types in modules/uc_recurring/uc_recurring.ca.inc on line 391

Conditionally combining the arrays if $settings is not empty seems to have fixed the problem, but there is probably a more finessed way to do it and I have no idea if this will cause problems down the road.

Thanks for your great work!

Comments

miche’s picture

Version: 6.x-2.0-alpha5 » 6.x-2.0-alpha6

Experienced same issue in alpha6. Still investigating.

univate’s picture

miche’s picture

Status: Closed (duplicate) » Active

Reopening. I do not think this is a duplicate. Although the same fatal error happens, a very different line of code is the culprit.

To replicate error:
/admin/store/ca/uc_recurring_renewal_email_failed/edit/actions
in "Available Actions" select box, choose "Send an order email regarding order renewal"
click "Add Action"

I propose changing

$settings += array(
  //stuff
);

to

if (!$settings) {
  $settings = array(
    //stuff
  );
}

This will insure that if there is existing content in the form fields, it gets preserved on save and also prefill the fields when creating a new action.

Additionally, we can complete remove the following lines because ca_build_email_form() has been moved out of uc_roles.ca as of the dev release.

// ca_build_email_form() function seems to be incorrectly part of uc_roles so
// we add this hack to include the uc_roles.ca.inc here.
module_load_include('inc', 'uc_roles', 'uc_roles.ca');
univate’s picture

The operand + on arrays is a union, so those two blocks of code do completely different things.

miche’s picture

In my testing, when editing and saving an existing action, you don't need to specify what the settings are so that it pulls in what has already been saved. However, when adding a new one, you need to specify what to prefil the form elements with.

To accomplish this testing:

If I completely remove the code about the settings array
--If I change an existing action, everything is saved as expected.
--If I add a new one, it loads as empty without the tokens.

If I change the += to just =
--If I change an existing one, nothing saves and it uses the content from the settings array in code.
--If I add a new one, it loads as expected with filled fields from the settings array.

This has led me to believe that we need a conditional statement.
- If editing/saving an existing, don't do anything.
- If creating a new one, define the contents for the fields.

miche’s picture

I have attached a patch with my proposed code. I would appreciate if someone could test if the logic change works as desired. Thanks!

tinker’s picture

@miche - Your patch has incorrect logic and does not match the original operation of the code. You could try something like:

if (is_array($settings)) {
  $settings += array(
    'from' => uc_store_email_from(),
    'addresses' => '[order-email]',
    'subject' => uc_get_message('uc_recurring_renewal_completed_subject'),
    'message' => uc_get_message('uc_recurring_renewal_completed_message'),
    'format' => 1,
  );
} else {
  $settings = array(
    'from' => uc_store_email_from(),
    'addresses' => '[order-email]',
    'subject' => uc_get_message('uc_recurring_renewal_completed_subject'),
    'message' => uc_get_message('uc_recurring_renewal_completed_message'),
    'format' => 1,
  );
}

This is not tested, I have not looked at the code, just suggesting different logic. Really we should know why $settings is not an array.

univate’s picture

What tinker has posted is what we will need to do, we can't just ignore the $settings when something is passed to this function as it may not include all required variables.

I am also interest in understanding why $settings is not an array?, if nothing is passed is should be an empty array, if something is passed then by definition it should be array(). Where in ubercart is it try to pass something other then an array.

univate’s picture

Status: Active » Needs work
miche’s picture

Status: Needs work » Needs review
StatusFileSize
new1.47 KB

Thank you for the code snippet. I have tested this locally and confirmed that a fatal error no longer happens, existing/modified emails are preserved, new ones are prefilled with the template.

agileware’s picture

The patch in #10 fixes the error for me.

agileware’s picture

Title: Error When attempting to send an email on failed renewal » Fatal error: Unsupported operand types when adding order renewal email action
Version: 6.x-2.0-alpha6 » 6.x-2.x-dev
StatusFileSize
new712 bytes

This patch also fixes it a different way - I forgot I had seen this before :(.

The issue is that when you add the action through the UI, the ca_actions_form() function passes in the actions, which are NULL.

I would expect this NULL is the only case where you won't have an array because the settings have not yet been saved.

Other modules that provide actions like uc_order do not do this same sort of array merging so don't run into the problem.

mattcasey’s picture

#12 works for me, I am using the previous dev and the error goes away

westwesterson’s picture

Status: Needs review » Reviewed & tested by the community

Tested the fix in 12. This works for me too!

daveparrish’s picture

#12 also worked for me. I am using version 6.x-2.0-alpha6.

univate’s picture

Status: Reviewed & tested by the community » Fixed

committed #12

Status: Fixed » Closed (fixed)

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