Skip to content

Multi-Currency funnel smart-codes use a string key, breaking the automation email editor ("fcrm_funnel_context_codes is not iterable") #74

Description

@bergy10

Which plugin?

Multi-Currency (fchub-multi-currency)

What happened?

Opening the email block of ANY FluentCRM automation (funnel) throws a JS error and the editor won't load:

TypeError: (window.fcrm_funnel_context_codes || []) is not iterable

It affects every automation site-wide, not only ones that use Multi-Currency codes.

Root cause: in app/Integration/FluentCrmSmartCodes.php, registerFunnelSmartCodes() adds its group under a STRING key:

$groups['mc_order'] = [ ... ];   // lines 38 and 57

Because that key is a string, the array returned by the fluent_crm_funnel_context_smart_codes filter becomes associative. FluentCRM localises the merged result to the editor as composer_context_codes (window.fcrm_funnel_context_codes), and an associative PHP array encodes to a JS object rather than an array — so the editor's iteration over it throws "not iterable".

Confirmed by dumping the filter output: the top-level keys were ["mc_order", 0, 1, 2] (mixed string + int → associative). Every other group (Cart Order, Cart Customer, Membership) appends correctly with $groups[] = [...].

Minor, same file: the filter is registered with accepted_args = 2 (line 28) but it is dispatched with 3 args ($codes, $trigger_name, $funnel).

Steps to reproduce

  1. Have FluentCRM + FCHub Multi-Currency active.
  2. Open (or create) any FluentCRM automation that sends an email.
  3. Open the email action to edit its content.
  4. The editor fails to load with: fcrm_funnel_context_codes is not iterable.

Expected vs actual behaviour

Expected: the email editor opens and lists the smart-code groups.

Actual: it crashes, and no automation email can be edited while Multi-Currency is active.

Fix: append the group instead of keying it by a string —

$groups[] = [ 'key' => 'mc_order', 'title' => ..., 'shortcodes' => [...] ];

so the returned array stays a sequential list. (And register the filter with accepted_args = 3 to match the dispatch, if the callback needs the trigger name / funnel.)

Workaround until then — a late filter that reindexes the list:

add_filter('fluent_crm_funnel_context_smart_codes', fn($c) => is_array($c) ? array_values($c) : $c, 99999);

WordPress version

7.0.2

PHP version

8.5.8

FluentCart version

1.5.5

Plugin version

1.4.0

Screenshots or logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions