Adding Customer Custom attributes creating document files#446
Adding Customer Custom attributes creating document files#446mtmmahi wants to merge 3 commits intoAdobeDocs:mainfrom
Conversation
| @@ -0,0 +1,419 @@ | |||
| --- | |||
| title: Add a Custom boolean Field Attribute | Commerce PHP Extensions | |||
There was a problem hiding this comment.
boolean should be capitalised. Should be:
title: Add a Custom Boolean Field Attribute | Commerce PHP Extensions
| 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); |
There was a problem hiding this comment.
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.
| ### Code reference | ||
|
|
||
| ```php | ||
| <?php declare(strict_types=1); |
There was a problem hiding this comment.
<?php and declare(strict_types=1); must each be on their own line, consistently across the document.
| @@ -0,0 +1,412 @@ | |||
| --- | |||
| title: Add a Custom dropdown Field Attribute | Commerce PHP Extensions | |||
There was a problem hiding this comment.
dropdown should be capitalised. Should be:
title: Add a Custom Dropdown Field Attribute | Commerce PHP Extensions
|
|
||
|  | ||
|
|
||
| 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. |
There was a problem hiding this comment.
<?php and declare(strict_types=1); must each be on their own line, consistently across the document.
| @@ -0,0 +1,416 @@ | |||
| --- | |||
| title: Add a Custom boolean Field Attribute | Commerce PHP Extensions | |||
There was a problem hiding this comment.
The title says boolean — copied from the boolean file and not updated. Should be:
title: Add a Custom Multiselect Field Attribute | Commerce PHP Extensions
| @@ -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. | |||
There was a problem hiding this comment.
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.
|
|
||
| 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`. |
There was a problem hiding this comment.
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.
| ### Code reference | ||
|
|
||
| ```php | ||
| <?php declare(strict_types=1); |
There was a problem hiding this comment.
<?php and declare(strict_types=1); must each be on their own line, consistently across the document.
| $this->moduleDataSetup->getConnection()->endSetup(); | ||
| } | ||
| } | ||
| ``` No newline at end of file |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Added new line et the end of the php snippet
|
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; |
There was a problem hiding this comment.
Overfixed. This is a class, not a snippet, so the header must be present.
| 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 | ||
|
|
There was a problem hiding this comment.
Unnecessary blank line.
| 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 | ||
|
|
There was a problem hiding this comment.
Overfixed. This is a class, not a snippet, so the header must be present.
| <?php | |
| declare(strict_types=1); | |
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