Skip to content

[5.x] Fix custom field mass assignment in VariantCollection#3946

Merged
nfourtythree merged 6 commits into5.xfrom
bugfix/variant-collection-mass-assignment
Mar 19, 2025
Merged

[5.x] Fix custom field mass assignment in VariantCollection#3946
nfourtythree merged 6 commits into5.xfrom
bugfix/variant-collection-mass-assignment

Conversation

@nfourtythree
Copy link
Copy Markdown
Contributor

Description

Trying to assign values to custom fields when making a VariantCollection could cause the data to be dropped.

This fix will ensure the custom field data is set on the element when passing in the data using one of the following methods (where myCustomField is the handle of the custom field:

// Top level
$variant = [
    'title' => 'My Variant',
    // ...
    'myCustomField' => 'Foo',
];

// Prefixed
$variant = [
    'title' => 'My Variant',
    // ...
    'field:myCustomField' => 'Foo',
];

// Nested
$variant = [
    'title' => 'My Variant',
    // ...
    'fieldValues' => [
        'myCustomField' => 'Foo',
    ],
];

Related issues

#3931
#3927

Copy link
Copy Markdown
Member

@lukeholder lukeholder left a comment

Choose a reason for hiding this comment

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

LGTM!

@nfourtythree nfourtythree merged commit fdaf80d into 5.x Mar 19, 2025
@nfourtythree nfourtythree deleted the bugfix/variant-collection-mass-assignment branch March 19, 2025 10:31
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.

2 participants