Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 02bd601

Browse files
author
Dinesh V B
committed
issue-8347-made the requested changes
1 parent 0e4587c commit 02bd601

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/_videos/fundamentals/add-new-product-attribute.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,26 +340,30 @@ It should be visible and in bold text.
340340

341341
## Product Attribute Option Creation
342342

343-
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.
343+
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.
344344

345345
### ADD OPTIONS ALONG WITH A NEW PRODUCT ATTRIBUTE {#AddOptionsAlongNewProductAttribute}
346346

347347
Basic instructions for creating a product attribute by setup or upgrade script can be found [in DevDocs](#CreateProductAttributeByUpgradeScript). Before scripting the attribute creation, pick one of these two use cases for your options:
348348

349-
* 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.
350-
* You want a set of options which can be modified, added, or deleted through the admin panel by any user with admin access and proper authorization.
349+
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.
350+
1. You want a set of options which can be modified, added or deleted through the admin panel by any user with admin access and proper authorization.
351351

352-
In the case of Use Case 1 (an 'immutable' set of options), follow Magento's instructions entitled ["Add a source model"](#AddSourceModel) You will create a model that contains and dynamically, on block rendering, returns your attribute's selectable options to the client.
352+
For use case `1` (an 'immutable' set of options), follow Magento's instructions entitled ["Add a source model"](#AddSourceModel) You will create a model that contains and dynamically, on block rendering, returns your attribute's selectable options to the client.
353353

354-
In the case of Use Case 2 (a 'mutable' set of options), review Magento's article entitled ["EAV and extension attributes"](_site/guides/v2.4/extension-dev-guide/attributes.html), noting especially the attribute option entitled option. Also make certain 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.
354+
For use case `2` (a 'mutable' set of options), review Magento's article entitled ["EAV and extension attributes"](_site/guides/v2.4/extension-dev-guide/attributes.html), noting especially the attribute option entitled option. Also make certain 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.
355355

356356
Investigating \Magento\Eav\Setup\EavSetup.php::addAttribute() and \Magento\Eav\Setup\EavSetup.php::addAttributeOptions() reveals that you may add a series of options with the following array:
357357

358+
```
358359
'option' => ['values' => ['Option 1', 'Option 2', 'Option 3', etc.]]
360+
```
359361

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

364+
```
362365
'option' => ['values' => [8 => 'Option 1', 3 => 'Option 2', 11 => 'Option 3', etc.]]
366+
```
363367

364368
It's worth noting that store_id is hardcoded by default to 0 with no good way to change this other than overriding the class or using the plugin to intercept the database insert method, which would probably be a performance killer as often as that gets called.
365369

@@ -373,12 +377,18 @@ For relevant background, review the [preceding section](#AddOptionsAlongNewProdu
373377

374378
Assign an array of new options to a variable:
375379

380+
```
376381
$options = ['attribute_id' => null, 'values' => 'Option 1', 'Option 2', etc]];
382+
```
377383

378384
Update your array with the attribute ID from the database:
379385

386+
```
380387
$options['attribute_id'] = $eavSetup->getAttributeId($eavSetup->getEntityTypeId('catalog_product'), 'your_attribute_code');
388+
```
381389

382390
Add your options:
383391

392+
```
384393
$eavSetup->addAttributeOption($options);
394+
```

0 commit comments

Comments
 (0)