You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: src/_videos/fundamentals/add-new-product-attribute.md
+15-5Lines changed: 15 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -340,26 +340,30 @@ It should be visible and in bold text.
340
340
341
341
## Product Attribute Option Creation
342
342
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.
344
344
345
345
### ADD OPTIONS ALONG WITH A NEW PRODUCT ATTRIBUTE {#AddOptionsAlongNewProductAttribute}
346
346
347
347
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:
348
348
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.
351
351
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.
353
353
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.
355
355
356
356
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:
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.
365
369
@@ -373,12 +377,18 @@ For relevant background, review the [preceding section](#AddOptionsAlongNewProdu
0 commit comments