New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue-8347 - added new product attribute documentation #8395
Issue-8347 - added new product attribute documentation #8395
Conversation
…dd-new-product-attribute-documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great addition! Just a few formatting & punctuation suggestions
|
||
## Product Attribute Option Creation | ||
|
||
A product attribute of type multiselect or select will present selectable options to the user. These options may be added manually through the admin panel, or by upgrade script. The script process is slightly different depending on whether the options are being added at the moment of attribute creation or whether the options are being added at a later time to an existing attribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A product attribute of type multiselect or select will present selectable options to the user. These options may be added manually through the admin panel, or by upgrade script. The script process is slightly different depending on whether the options are being added at the moment of attribute creation or whether the options are being added at a later time to an existing attribute. | |
A product attribute of type multiselect or select will present selectable options to the user. These options may be added manually through the admin panel or by upgrade script. The script process is slightly different depending on whether the options are being added at the moment of attribute creation or whether the options are being added at a later time to an existing attribute. |
Basic instructions for creating a product attribute by setup or upgrade script can be found [above](#CreateProductAttributeByUpgradeScript). Before scripting the attribute creation, pick one of these two use cases for your options: | ||
|
||
* You want a set of options which cannot be modified by a user through the admin panel, and which can only be changed through a future code push. | ||
* You want a set of options which can be modified, added, or deleted through the admin panel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* You want a set of options which can be modified, added, or deleted through the admin panel. | |
1. You want a set of options which can be modified, added or deleted through the admin panel. |
|
||
Basic instructions for creating a product attribute by setup or upgrade script can be found [above](#CreateProductAttributeByUpgradeScript). Before scripting the attribute creation, pick one of these two use cases for your options: | ||
|
||
* You want a set of options which cannot be modified by a user through the admin panel, and which can only be changed through a future code push. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to numbered as each are referred to this way further down
* You want a set of options which cannot be modified by a user through the admin panel, and which can only be changed through a future code push. | |
1. You want a set of options which cannot be modified by a user through the admin panel and which can only be changed through a future code push. |
* You want a set of options which cannot be modified by a user through the admin panel, and which can only be changed through a future code push. | ||
* You want a set of options which can be modified, added, or deleted through the admin panel. | ||
|
||
In the case of use case 1 (an 'immutable' set of options), follow the above instructions ["Add a source model"](#AddSourceModel). You will create a model that contains and dynamically returns the attribute's selectable options to the client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of use case 1 (an 'immutable' set of options), follow the above instructions ["Add a source model"](#AddSourceModel). You will create a model that contains and dynamically returns the attribute's selectable options to the client. | |
For use case `1` (an 'immutable' set of options), follow the above instructions ["Add a source model"](#AddSourceModel). You will create a model that contains and dynamically returns the attribute's selectable options to the client. |
|
||
In the case of use case 1 (an 'immutable' set of options), follow the above instructions ["Add a source model"](#AddSourceModel). You will create a model that contains and dynamically returns the attribute's selectable options to the client. | ||
|
||
In use case 2 (a 'mutable' set of options), see ["EAV and extension attributes"]({{ site.baseurl }}/guides/v2.4/extension-dev-guide/attributes.html). Make sure to declare 'Magento\Eav\Model\Entity\Attribute\Source\Table' as the value for the 'source' attribute option. This ensures that Magento will store options in the appropriate database table. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In use case 2 (a 'mutable' set of options), see ["EAV and extension attributes"]({{ site.baseurl }}/guides/v2.4/extension-dev-guide/attributes.html). Make sure to declare 'Magento\Eav\Model\Entity\Attribute\Source\Table' as the value for the 'source' attribute option. This ensures that Magento will store options in the appropriate database table. | |
For use case `2` (a 'mutable' set of options), see ["EAV and extension attributes"]({{ site.baseurl }}/guides/v2.4/extension-dev-guide/attributes.html). Make sure to declare 'Magento\Eav\Model\Entity\Attribute\Source\Table' as the value for the 'source' attribute option. This ensures that Magento will store options in the appropriate database table. |
In use case 2 (a 'mutable' set of options), see ["EAV and extension attributes"]({{ site.baseurl }}/guides/v2.4/extension-dev-guide/attributes.html). Make sure to declare 'Magento\Eav\Model\Entity\Attribute\Source\Table' as the value for the 'source' attribute option. This ensures that Magento will store options in the appropriate database table. | ||
|
||
With `\Magento\Eav\Setup\EavSetup.php::addAttribute()` and `\Magento\Eav\Setup\EavSetup.php::addAttributeOptions()` you can add a series of options with the following array: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would suggest enclosing the two array segments in ```php for formatting clarity
|
||
1. Assign an array of new options to a variable: | ||
|
||
`$options = ['attribute_id' => null, 'values' => 'Option 1', 'Option 2', etc]];` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would suggest enclosing the three code segments in ```php for formatting clarity
@magento run all tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also check linting - it failed last time for some reason (not clear)
|
||
With `\Magento\Eav\Setup\EavSetup.php::addAttribute()` and `\Magento\Eav\Setup\EavSetup.php::addAttributeOptions()` you can add a series of options with the following array: | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
```php |
|
||
Alternatively, you may designate a specific option sorting order as follows: | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
```php |
|
||
1. Assign an array of new options to a variable: | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
```php |
|
||
1. Update your array with the attribute ID from the database: | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
```php |
|
||
1. Add your options: | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
```php |
Hi @BarnyShergold , is this good to be approved? |
Hi @rogyar , is this good to be approved? |
running tests |
Hi @dineshvb, thank you for your contribution! |
Purpose of this pull request
This pull request (PR) covers #8347
Affected DevDocs pages
whatsnew
Added the 'Product Attribute Option Creation' section to the How to Add a New Product Attribute topic.