Magento2 Attribute Option Code
snowio/magento2-attribute-option-code
Adds a unique code to attribute options, allowing remote clients to create and reference options by code. Enables saving products with attribute option codes instead of IDs.
Build Tests
Code Quality
Tested on Magento 2.4.8-p3
Recent Test History
Each release is tested against the latest Magento version at that time.
Looking for Contributors
Dependency injection compilation fails. Your contribution could help the entire Magento community!
Share This Module's Status
README
Loaded from GitHubMagento 2 Attribute Option Code
Description
Magento 2 module that that adds a unique code to an attribute option. Attribute options can now be created by remote clients with an identifier (attribute option code) that the client can specify and later reference during product saves. Attribute options that were created with the client can also be deleted by specifing the attribute option code that belongs to the attribute option. Please refer to the endpoint table for uri endpoint paths.
Magento Versions
- 2.3.x use 2.x tags
- 2.4.x use master
Prerequisites
- PHP 5.6 or newer
- Composer (https://getcomposer.org/download/).
-
magento/framework100 or newer -
magento/module-eav100 or newer -
magento/module-catalog101 or newer
Installation
composer require snowio/magento2-attribute-option-code
php bin/magento module:enable SnowIO_AttributeOptionCode
php bin/magento setup:upgrade
Usage
Endpoint table
| HTTP Method | URI Path | Description |
|-------------|------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| POST | /V1/coded-attribute-options | Creates an Attribute option with a corresponding option code. See Creating a coded attribute option |
| DELETE | /V1/coded-attribute-options/entity-type/:entityType/attribute-code/:attributeCode/option-code/:optionCode| Deletes an attribute option code. See Deleting attribute options for more information. |
| PUT | /V1/products-with-option-codes/:sku | Saves a product with attribute option codes specified instead of attribute option IDs'. See Specifying attribute options in products for more information |
Creating a coded attribute option
Request message body (JSON)
{
"entity_type" : 4,
"attribute_code" : "testAttribute",
"option" : {
"label": "foo",
"value": "bar",
"sort_order": 0,
"is_default": true,
"store_labels": [
{
"store_code" : "testStore",
"label": "Foo Label Test"
}
]
}
}
Message body description
-
entity_typeinteger : The entity type that the attribute option corresponds to. -
attribute_codestring : The attribute code of the that corresponds to the option -
option:-
labelstring : The option label -
valuestring : The option code -
sort_orderinteger : The option's sort order -
is_defaultboolean : default option flag -
store_labels1..n :-
store_codestring : The store code for the option -
labelstring : The option label
-
-
Deleting attribute options
-
:entityTypeinteger : The entity type that the attribute option corresponds to. -
:attributeCodestring : The attribute code that the attribute option corresponds to. -
:optionCodestring : The attribute option code.
Specifying attribute options in products
URI parameters
-
:skustring : The products sku.
Request message body (JSON)
{
"product": {
"type_id": "simple",
"sku": "test-from-snowio-simple",
"attribute_set_id": 4,
"name": "test from snow.io simple",
"price": 10,
"visibility": 4,
"status": 1,
"custom_attributes": {
"testAttribute": "bar"
}
}
}
NOTE that the value of the custom attribute testAttribute is the attribute option code bar.
License
This software is licensed under the MIT License. View the license
This content is fetched directly from the module's GitHub repository. We are not the authors of this content and take no responsibility for its accuracy, completeness, or any consequences arising from its use.