This is an example module creation development that creates a Product Custom Attribute and adds several related functionality for development practising purposes.
- Installation of Product custom attribute (
lcouget_custom_attribute) and automatically set intoDefaultAttribute Set. - Custom Attribute is shown on Product Detail Page.
- It also includes a custon Attribute rule validation form for rule validation testing purposes only. It validates the following rules:
- required.
- no-whitespaces.
- alphanumeric.
- Admin Page:
- On admin side, custom Attribute is added on all products inside Default Attribute Set.
- Feature toggle: Enable/Disable custom attribute usability and display with System Flag.
- CLI module handle:
- There is a console command to handle module via CLI (see CLI section)
- Vanilla Magento version 2.4.6 or above (tested on 2.4.7-p1 version).
- To check Magento versions, please visit Official Adobe site.
- Install Vanilla Magento 2.4.6 or above.
- To ensure correct testing, it is recommended to install Sample Data by using this command:
bin/magento sampledata:deploy. You can also create just a catalog with few products. - Get Custom Attribute module code from github. (Download here)
- Unzip downloaded file and go inside
m2-customattribute-masterfolder. - Copy
Lcougetfolder inside your Magento instanceapp/codefolder. - At this point, you can check if module is detected bu using the command:
php bin/magento module:status --disabled- The module
Lcouget_CustomAttributeshould appear as disabled.
- Proceed to install the module by using this commands on your Magento
rootfolder:php bin/magento module:enable Lcouget_CustomAttributephp bin/magento setup:upgradephp bin/magento setup:di:compilephp bin/magento setup:static-content:deployphp bin/magento cache:flush
- Done! The module is ready to use!
- Option 1: Feature Toggle
After Module installation, inside admin page you should see a new menu option Lcouget. Click on
Custom Attribute Settings options an go to General Configuration section. Then set Enable option to Yes
and click on Save Config button.
The clear Configuration cache to see the changes.
- Option 2: CLI command
You can also enable/disable the module by using custom-attribute:manage CLI command (See CLI section).
By default, custom attribute is added to all products, so you can set custom attribute inside Product Attribute Page on adminhtml.
After custom attribute value set, click on Save button. You should see changes on Frontend Product Detail Page.
As mentioned before, custom attribute is added on Product Attributes Page.
This new attribute is also added on Catalog product grid.
Custom attribute is shown on Product Detail Page on Frontend.
It also adds a small form for validation testing purposes only.
Note: this form doesn't change custom attribute value, it only retun an error if some validation rule fails.
There is also a Console command to execute via CLI. To see all available options, run
php bin/magento custom-attribute:manage [options] new_custom_attribute_value
- Update attribute - all products (default): With no options, the default behavior is to update custom attribute value to all products. Note: this process could take a while to finish depending on Catalog size.
Example: php bin/magento custom-attribute:manage NewValue
-
Update Attribute - All products (asyncrhonously --async or -a): Update custom attribute value to all products asynchronously. (AMQP/RabbitMQ installation required)
Example:
php bin/magento custom-attribute:manage --async NewValue -
Update attribute - selected product (--sku or -s): You can just update custom attribute on selected product by setting sku option.
Example: php bin/magento custom-attribute:manage --sku=24-MB01 NewValue
- Feature toggle: You can enable/disable module with --enable (or -e) and --disable (or -d) option
Example: php bin/magento custom-attribute:manage --enable
Note: on all options, caches are automatically refreshed.
Note 2: New attribute value is also validated with same validation rules applied on frontend.
- 1.0.0:
- Initial Release.
- 1.0.1:
- uptateAllProducts Console method optimized.
- added AMQP to perform updateAllProducts option asynchronously.
- 1.0.2:
- Replaced Constant helper class with enum.
- Removed Constant types (php <8.3 compatibility).






