Skip to content

fix: array to string conversion#383

Open
ahuininga-orisha wants to merge 1 commit into
developfrom
fix/array-to-string-conversion
Open

fix: array to string conversion#383
ahuininga-orisha wants to merge 1 commit into
developfrom
fix/array-to-string-conversion

Conversation

@ahuininga-orisha

@ahuininga-orisha ahuininga-orisha commented May 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

See issue EmicoEcommerce/Magento2TweakwiseHyva#91

When the Tweakwise API returns a facet's title as an array instead of a string (malformed or unexpected API response), calling getName() on a Filter triggered an Array to string conversion PHP warning. This could happen for any facet — including Tweakwise-only facets that have no corresponding Magento EAV attribute — and would produce a PHP warning on the storefront.

The suggested fix in the issue report patched Filter::getName(), but that treats the symptom rather than the cause. SettingsType::getTitle() is declared to return string and is called in multiple places — fixing the data contract at the source protects all callers.

  • Replaced the @method string getTitle() magic docblock in SettingsType with an explicit getTitle(): string method, consistent with how all other getters in that class are implemented (e.g. getUrlKey(), getSelectionType()).
  • The explicit method casts the raw API value to string, and returns an empty string if the API unexpectedly returns an array.
  • Removed the now-redundant (string) cast in Filter::getName() since getTitle() is now guaranteed to return a string.

How to test

Scenario 1 — Normal API response (regression check)

  1. Load a category page that has Tweakwise layered navigation active.
  2. Verify that all filter names render correctly in the sidebar.
  3. Verify no PHP warnings appear in the Magento logs (var/log/exception.log, var/log/system.log).

Scenario 2 — Malformed API response with array title

  1. Temporarily mock or intercept the Tweakwise API response so that a facet's title field is an array (e.g. ["Color"] instead of "Color").
  2. Load a category page with layered navigation.
  3. Verify no Array to string conversion PHP warning is triggered.
  4. Verify the affected filter renders with an empty name rather than causing an error.

@ahuininga-orisha ahuininga-orisha changed the base branch from master to develop May 20, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant