Skip to content
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

Conversation

dineshvb
Copy link
Contributor

@dineshvb dineshvb commented Dec 16, 2020

Purpose of this pull request

This pull request (PR) covers #8347

Affected DevDocs pages

  • /videos/fundamentals/add-new-product-attribute.html

whatsnew
Added the 'Product Attribute Option Creation' section to the How to Add a New Product Attribute topic.

@dineshvb dineshvb marked this pull request as ready for review December 21, 2020 09:32
@dobooth dobooth added the Major Update Significant original updates to existing content label Jan 6, 2021
Copy link
Contributor

@BarnyShergold BarnyShergold left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* 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.
Copy link
Contributor

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

Suggested change
* 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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:

Copy link
Contributor

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]];`
Copy link
Contributor

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

@BarnyShergold
Copy link
Contributor

@magento run all tests

Copy link
Contributor

@BarnyShergold BarnyShergold left a 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:

```
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```
```php


Alternatively, you may designate a specific option sorting order as follows:

```
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```
```php


1. Assign an array of new options to a variable:

```
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```
```php


1. Update your array with the attribute ID from the database:

```
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```
```php


1. Add your options:

```
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```
```php

@dineshvb
Copy link
Contributor Author

Hi @BarnyShergold , is this good to be approved?

@m2-community-project m2-community-project bot moved this from Changes Requested to Reviewer Approved in Pull Request Progress Jan 20, 2021
@dineshvb
Copy link
Contributor Author

Hi @rogyar , is this good to be approved?

@dobooth
Copy link
Contributor

dobooth commented Jan 20, 2021

running tests

@dobooth dobooth merged commit 71eb452 into magento:master Jan 20, 2021
@ghost
Copy link

ghost commented Jan 20, 2021

Hi @dineshvb, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@m2-community-project m2-community-project bot moved this from Reviewer Approved to Done in Pull Request Progress Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Major Update Significant original updates to existing content Partner: EY partners-contribution PR created by Magento partner Progress: done
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants