Skip to content

Adding Customer Custom attributes creating document files#446

Open
mtmmahi wants to merge 3 commits intoAdobeDocs:mainfrom
mtmmahi:add-custom-attributes
Open

Adding Customer Custom attributes creating document files#446
mtmmahi wants to merge 3 commits intoAdobeDocs:mainfrom
mtmmahi:add-custom-attributes

Conversation

@mtmmahi
Copy link
Copy Markdown

@mtmmahi mtmmahi commented Apr 23, 2026

Purpose of this pull request

This pull request (PR) will add tutorials for 3 additional custom customer attribute types.

The types are boolean,dropdown and multiselect attributes

Affected pages

https://developer.adobe.com/commerce/php/tutorials/admin/custom-text-field-attribute
The page above is used as a template, three new pages will created in the same space.

Links to Magento Open Source code

  • ...

@github-project-automation github-project-automation Bot moved this to 📋 Needs Review in Commerce - Pull Requests Apr 23, 2026
@mtmmahi mtmmahi closed this Apr 23, 2026
@github-project-automation github-project-automation Bot moved this from 📋 Needs Review to 🏁 Done in Commerce - Pull Requests Apr 23, 2026
@mtmmahi mtmmahi reopened this Apr 23, 2026
@github-project-automation github-project-automation Bot moved this from 🏁 Done to 🧑‍💻 In Progress in Commerce - Pull Requests Apr 23, 2026
@@ -0,0 +1,419 @@
---
title: Add a Custom boolean Field Attribute | Commerce PHP Extensions
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.

boolean should be capitalised. Should be:

title: Add a Custom Boolean Field Attribute | Commerce PHP Extensions

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ttitle Updated

The factory is stored rather than a single `CustomerSetup` instance, because both `apply()` and `revert()` need to create their own instance.

```php
<?php declare(strict_types=1);
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.

This snippet is a method-level excerpt, not a complete PHP file. The <?php declare(strict_types=1); opening tag should not appear here — it is only appropriate at the top of a full file. Please remove this line from the snippet.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed it from code snippet

### Code reference

```php
<?php declare(strict_types=1);
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.

<?php and declare(strict_types=1); must each be on their own line, consistently across the document.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated as per the comment

@@ -0,0 +1,412 @@
---
title: Add a Custom dropdown Field Attribute | Commerce PHP Extensions
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.

dropdown should be capitalised. Should be:

title: Add a Custom Dropdown Field Attribute | Commerce PHP Extensions

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ttitle Updated


![Custom attribute in the customer grid](../../images/tutorials/custom-attribute-customer-grid.png)

To remove the attribute, run `bin/magento setup:rollback` and target this patch. The `revert()` method will execute and delete the attribute from the system.
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.

<?php and declare(strict_types=1); must each be on their own line, consistently across the document.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated the code

@@ -0,0 +1,416 @@
---
title: Add a Custom boolean Field Attribute | Commerce PHP Extensions
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.

The title says boolean — copied from the boolean file and not updated. Should be:

title: Add a Custom Multiselect Field Attribute | Commerce PHP Extensions

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated the title

@@ -0,0 +1,416 @@
---
title: Add a Custom boolean Field Attribute | Commerce PHP Extensions
description: Follow this tutorial to create a custom boolean field attribute for Adobe Commerce or Magento Open Source.
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.

The description also says boolean field attribute — copied from the boolean file and not updated. Should be:

description: Follow this tutorial to create a custom multiselect field attribute for Adobe Commerce or Magento Open Source.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated the Description


This tutorial describes how a developer can create a custom multiselect attribute for the Customer entity using code. This will reflect in both the [Customer Grid](https://experienceleague.adobe.com/en/docs/commerce-admin/customers/customer-accounts/manage/manage-account) and the [Customer Form](https://experienceleague.adobe.com/en/docs/commerce-admin/customers/customer-accounts/manage/update-account) in the Admin.

Use a multiselect attribute when you need to store multiple simultaneous values for a single customer field — for example, eligible shipping methods, allowed sales channels, or subscription preferences. Unlike the [dropdown attribute](custom-dropdown-attribute.md), which stores a single selected option ID as an integer, a multiselect attribute stores a comma-separated list of option IDs as a `varchar` value, handled by the `ArrayBackend` backend model. This tutorial also implements `PatchRevertableInterface`, which allows the attribute to be cleanly removed by running `bin/magento setup:rollback`.
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.

Broken internal link: custom-dropdown-attribute.md does not exist in this PR — the dropdown file is named custom-dropdown-field-attribute.md. This will resolve automatically if the file naming issue is fixed by removing -field- from all filenames.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated the internal link

### Code reference

```php
<?php declare(strict_types=1);
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.

<?php and declare(strict_types=1); must each be on their own line, consistently across the document.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated as per comment

$this->moduleDataSetup->getConnection()->endSetup();
}
}
``` No newline at end of file
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.

File is missing a trailing newline character. This will cause a MD047/single-trailing-newline markdownlint failure in CI. Please add a newline after the closing code fence.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added new line et the end of the php snippet

@github-project-automation github-project-automation Bot moved this from 🧑‍💻 In Progress to 🛠 Changes Requested in Commerce - Pull Requests Apr 23, 2026
@mtmmahi
Copy link
Copy Markdown
Author

mtmmahi commented Apr 24, 2026

Implemented all changes as per the comments

Create a data patch class called `AddCustomerAttributeBoolean` under the `\ExampleCorp\Customer\Setup\Patch\Data` namespace. This makes the application execute the data patch automatically when `bin/magento setup:upgrade` is run. This class implements both `\Magento\Framework\Setup\Patch\DataPatchInterface` and `\Magento\Framework\Setup\Patch\PatchRevertableInterface`. Adding the revertable interface requires implementing a `revert()` method that removes the attribute when the patch is rolled back.

```php
namespace ExampleCorp\Customer\Setup\Patch\Data;
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.

Overfixed. This is a class, not a snippet, so the header must be present.

Suggested change
namespace ExampleCorp\Customer\Setup\Patch\Data;
<?php
declare(strict_types=1);
namespace ExampleCorp\Customer\Setup\Patch\Data;

The factory is stored rather than a single `CustomerSetup` instance, because both `apply()` and `revert()` need to create their own instance.

```php

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.

Unnecessary blank line.

Suggested change

Create a data patch class called `AddCustomerAttributeMultipleOptions` under the `\ExampleCorp\Customer\Setup\Patch\Data` namespace. This makes the application execute the data patch automatically when `bin/magento setup:upgrade` is run. This class implements both `\Magento\Framework\Setup\Patch\DataPatchInterface` and `\Magento\Framework\Setup\Patch\PatchRevertableInterface`.

```php

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.

Overfixed. This is a class, not a snippet, so the header must be present.

Suggested change
<?php
declare(strict_types=1);

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

Labels

None yet

Projects

Status: 🛠 Changes Requested

Development

Successfully merging this pull request may close these issues.

3 participants