For some unique customization, we need to create category attributes to fulfil client requirements. Magento introduce data patch to create attributes after version Magento 2.3. So, We need to create category attribute using data patch in magento2.
This Blog for Magento version >= 2.4.4 && PHP >= 8.1
Here I created simple category attribute with datatype text
Create file: app/code/MageDad/Module/Setup/Patch/Data/AddCodeCategoryAttribute.php
<?php
declare(strict_types=1);
namespace MageDad\Module\Setup\Patch\Data;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Catalog\Model\Category;
class AddCodeCategoryAttribute implements DataPatchInterface
{
public function __construct(
private ModuleDataSetupInterface $moduleDataSetup,
private EavSetupFactory $eavSetupFactory,
) {
}
/**
* {@inheritdoc}
*/
public function apply()
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->addAttribute(\Magento\Catalog\Model\Category::ENTITY, 'code', [
'type' => 'text',
'label' => 'Category Code',
'note' => 'Akeneo code entity',
'input' => 'text',
'default' => '',
'sort_order' => 5,
'required' => false,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
'visible_on_front' => true
]);
}
/**
* {@inheritdoc}
*/
public static function getDependencies()
{
return [];
}
/**
* {@inheritdoc}
*/
public function getAliases()
{
return [];
}
}
We need to run magento setup upgrade command to run this data patch.php bin/magento setup:upgrade
Create file – app/code/MageDad/Module/view/adminhtml/ui_component/category_form.xml
<?xml version="1.0" ?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="general">
<field name="code">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="required" xsi:type="boolean">false</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">false</item>
</item>
<item name="sortOrder" xsi:type="number">100</item>
<item name="dataType" xsi:type="string">string</item>
<item name="formElement" xsi:type="string">input</item>
<item name="label" translate="true" xsi:type="string">Category Code</item>
</item>
</argument>
</field>
</fieldset>
</form>
We can see catrgory attribute in admin like below screenshot.

We try to create quality blog with tested code. You can see github commit with same code.
I hope this blog is useful to create category attribute using data patch in magento2. In case, I missed anything or need to add some more information, Don’t heisted to leave a comment in this blog, I’ll get back with some positive approach.
Keep loving ❤️ Keep inspiring 🤩 Keep liking 👍 No sharing 😂
92 Comments
**breathe**
breathe is a plant-powered tincture crafted to promote lung performance and enhance your breathing quality.
https://t.me/s/Top_BestCasino/132
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://www.binance.info/lv/register?ref=SMUBFN5I
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Getting the jljl55download app was a breeze. No hassle, no weird permissions. Just straight to the games. Worth the download if you’re looking for some fun. jljl55download
Với mục tiêu mang đến sân chơi an toàn, 188v con áp dụng công nghệ mã hóa SSL tiên tiến, đảm bảo thông tin cá nhân và giao dịch luôn được bảo vệ tuyệt đối. Đây là yếu tố then chốt giúp nền tảng này giữ được uy tín trên thị trường cá cược. TONY12-30
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Right, gonna be honest…the name ‘xxaaslot’ caught my eye. Slots look pretty standard though. Maybe some hidden gems? Worth a browse: xxaaslot
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
W88is… hmmm, sounds familiar. I think I saw some ads for them. Is it just me, or does anyone else find their website kinda confusing? Anyway, take a peek yourself! w88is.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Khuyến mãi sinh nhật và các dịp lễ lớn tại 888slot trang chủ luôn mang đậm giá trị vật chất lẫn tinh thần, tạo nên một cộng đồng giải trí văn minh và gắn kết. TONY01-29O
**balmorex**
balmorex is an exceptional solution for individuals who suffer from chronic joint pain and muscle aches.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your article helped me a lot, is there any more related content? Thanks! https://accounts.binance.info/register-person?ref=IHJUI7TF
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Your article helped me a lot, is there any more related content? Thanks! https://www.binance.info/register?ref=IHJUI7TF
**finessa**
Finessa is a natural supplement made to support healthy digestion, improve metabolism, and help you achieve a flatter belly.
Slot tại Trang Chủ Đăng Ký 188v.com +88k Uy Tín 2025 có biểu tượng “phổ biến” được gắn trên những game có lượt chơi cao nhất tuần – giúp bạn nhanh chóng bắt trend và tham gia đúng thời điểm. TONY02-26H
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I don’t think the title of your enticle matches the content lol. Just kidding, mainly because I had some doubts after reading the enticle.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://accounts.binance.com/register-person?ref=IHJUI7TF
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://www.binance.bh/register?ref=QCGZMHR6
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Backbiome is an advanced daily wellness supplement formulated to help support spinal comfort, reduce feelings of built-up tension, and promote freer, smoother movement throughout backbiome everyday life.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://www.binance.com/en/register?ref=JHQQKNKN
Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://accounts.binance.bh/tr/register-person?ref=MST5ZREF
Boostaro is a modern men’s wellness boostaro formula created to support daily vitality, stamina, and confidence through a practical, natural routine.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your article helped me a lot, is there any more related content? Thanks!
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://www.binance.bh/register?ref=QCGZMHR6
Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://accounts.binance.bh/id/register-person?ref=OMM3XK51
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Here’s exactly the kind of clear breakdown I was looking for.
Too many sites overcomplicate everything, but you kept it simple.
Appreciate you putting this together!
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
[9425]bet368 | Link Vào Chính Thức – Tải App APK và Cổng Game Uy Tín,bet368 cung cấp hướng dẫn chi tiết luật chơi baccarat và cách nạp tiền casino nhanh chóng. Trải nghiệm cổng game slots uy tín ngay hôm nay để nhận ưu đãi hấp dẫn. visit: bet368
It really felt like my lucky day when I joined this site. The graphics are great and the gameplay is very addictive. Five stars from me! luckyday33
The login process is secure and fast. I never have issues accessing my account which is a huge plus for me. Visit jilibet777login for a great time
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://accounts.binance.com/register/person?ref=JW3W4Y3A
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Finally found a place that actually delivers on its promises. The download process was easy and I was playing in minutes. Go to pk68vipdownload to get started.
The APK installation was a breeze and it works perfectly on my Android device. No crashes so far and the performance is steady. Cheers for z999gamedownloadapk
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Love the selection of live dealer games. It really feels like I am at a real casino without leaving my living room. Cheers to rk88bet for the great setup.
This platform has everything I was looking for. The layout is user-friendly and the features are top-notch. Definitely spending more time on 777ggplataforma from now on.
I’ve tried a few sites but this one feels the most professional. No lag and the graphics are crisp. Love spending time on phgamezonelogin.
The app version is just seamless. Everything is so organized and easy to navigate. I’m really enjoying my time on bd4999betapk.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
I love the layout and the overall vibe of this site. It feels professional and trustworthy. I am spending a lot of my free time on idasia128 lately.
Fast deposits and even faster withdrawals. That is all I really care about and this site delivers every time. Check out kr10bet now.
Finally found a version that actually works on my phone without crashing. The interface is very user friendly. Just download the phjuan365apk and start winning.
Really impressed with the payout speed here. I had a great run last night and the withdrawal was processed almost instantly. Keep it up brd333bet!
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Best platform I have encountered in a long time. The bonuses are generous and the support team is very helpful. Log in to brazino777entrar now
Your article helped me a lot, is there any more related content? Thanks!
I’ve been looking for a smooth app experience and this one delivers. The loading speed is impressive and the interface is very intuitive. Highly recommend 5777betloginapp for anyone who hates lagging.
Just signed up yesterday and the welcome bonus is actually generous. The graphics are crisp and the gameplay is very intuitive. Love 777games55 so far!
This site is a hidden gem. The rewards system is very generous for new players. I am loving my time on idlogika300.
The betting odds on this site are much better than others I have used. The app is very responsive and easy to navigate. Give bdbolbybol a try!
Azeroth Survivors is a free survivors-style game set in the World of Warcraft world. b76a7cd7.
Love the vibe of this platform. It feels very fair and the payouts are consistent. I’m really enjoying my time at ktwin33 so far.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Really impressed with the transparency and the odds. I will be spending most of my free time on idrusia777 from now on.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Finally found a site that doesn’t lag during peak hours. The interface is super clean and getting in is a breeze. Highly recommend ph7777login for a hassle-free session.
I’ve tried a few sites lately and this one is definitely the smoothest. The login process is a breeze and the games load instantly. Highly recommend checking out 7e777gamelogin for a great experience.
Finally found a place where the login process is actually seamless. No more endless loading screens. Great experience so far with jili356comlogin.
Really sleek design and very user friendly. I can access my account in seconds without any hassle. phplusloginapp is simply the best.
This place has the best variety of games I have seen in a long time. Every spin feels exciting. Give slotpiala88 a go
The best platform I have encountered in the region. Very user friendly and the promotions are actually useful for players. Big thanks to ph39jiliph.
I’ve been looking for a reliable spot like this for a while. The interface is super smooth and the payouts are fast. Definitely worth checking out idsenopati2
The registration process was a breeze and I was playing in under two minutes. Everything is very professional and secure. Glad I found the ap999login portal.
The customer support is actually helpful which is rare these days. I had a small issue with my deposit and they sorted it in minutes. Give au8802com a go.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://www.binance.com/en-IN/register?ref=WTOZ531Y
Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.bh/futures/ref?code=MBLCVVZG
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.