Skip to content

Fix category image backend normalization for store-view saves - #5623

Open
addison74 with Copilot wants to merge 2 commits into
mainfrom
copilot/bugfix-array-to-string-conversion
Open

Fix category image backend normalization for store-view saves#5623
addison74 with Copilot wants to merge 2 commits into
mainfrom
copilot/bugfix-array-to-string-conversion

Conversation

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Saving a category in a non-default store view could trigger an Array to string conversion when an image was already assigned. The image field posts as an array (value/delete), but the category image backend only handled delete, leaving array data to reach persistence.

  • Root cause

    • Mage_Catalog_Model_Category_Attribute_Backend_Image::afterSave() handled ['delete' => 1] but did not normalize ['value' => '...'].
    • On store-view save, that array could remain on the model and be treated as a scalar attribute value.
  • Change

    • Updated category image backend to normalize array payloads before save:
      • keep existing delete behavior unchanged
      • map non-delete array payloads to the scalar image filename ($value['value'] ?? '')
  • Scope

    • Single-file surgical update:
      • app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Image.php
if (is_array($value)) {
    if (!empty($value['delete'])) {
        $object->setData($name, '');
        $this->getAttribute()->getEntity()->saveAttribute($object, $name);
        return $this;
    }

    $object->setData($name, $value['value'] ?? '');
}

Copilot AI changed the title [WIP] Fix array to string conversion error when saving category Fix category image backend normalization for store-view saves Jun 1, 2026
Copilot AI requested a review from addison74 June 1, 2026 13:24
@sonarqubecloud

sonarqubecloud Bot commented Jun 1, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot added the Component: Catalog Relates to Mage_Catalog label Jun 1, 2026
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Test Results

    1 files  ±0  3 446 suites  ±0   18s ⏱️ -1s
1 180 tests ±0  1 166 ✅ ±0     14 💤 ±0  0 ❌ ±0 
4 379 runs  ±0  1 193 ✅ ±0  3 186 💤 ±0  0 ❌ ±0 

Results for commit 1b7abf3. ± Comparison against base commit aee0061.

♻️ This comment has been updated with latest results.

@addison74
addison74 marked this pull request as ready for review June 1, 2026 14:10
Copilot AI review requested due to automatic review settings June 1, 2026 14:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes category image attribute normalization when saving a category in a non-default store view. It ensures that when the image field posts as an array payload ([value]/[delete] from Varien_Data_Form_Element_Image), the backend converts it back to a scalar filename (or clears it on delete), preventing “Array to string conversion” errors during/after the save flow.

Changes:

  • Extend Mage_Catalog_Model_Category_Attribute_Backend_Image::afterSave() to handle non-delete array payloads by mapping them to $value['value'] ?? ''.
  • Preserve existing delete behavior (clear attribute + saveAttribute() + early return).
  • Ensure the category model holds a scalar image value before subsequent processing (e.g., file upload handling and post-save observers).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Catalog Relates to Mage_Catalog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Array to string conversion on saving category in store view

4 participants