Disclaimer: This is a user generated content submitted by a member of the WriteUpCafe Community. The views and writings here reflect that of the author and not of WriteUpCafe. If you have any complaints regarding this post kindly report it to us.

In the previous blog, I introduced the declarative schema in Magento 2.3. In this blog, I am going to elaborate on the Data Patch. It is a new concept in the Declarative Schema approach. A data patch is a class that contains the data modification instruction.

The patch is defined in VendorModuleSetupPatchDataPatch_Name.php file and implements MagentoFrameworkSetupPatchDataPatchInterface.

The declarative schema approach removes the version from the setup_module table, leaving only the Composer version. Therefore, you can create all-new patches and modules without specifying a setup_module version.

Create EAV Attribute using Declarative Schema in Magento 2.3

I was stuck in the moments of creating product attributes using declarative schema. So I came to know that, however declarative schema script doesn’t apply to creating product attributes. For that, we need to implement patches that will create attributes.

We need to create a class that implements DataPatchInterface and instantiates the EavSetupFactory class within the constructor.

The naming convention for the patch file is, that if we are trying to add a single attribute named custom_size, we name our class AddCustomSizeAttribute.

Following are the steps to create eav attribute using the data patch in the declarative schema.

Create SetupPatchData within your module. Create file AddCustomSizeAttribute.php inside the Data folder.

For More Information, Visit:- https://stagebit.com/magento-2/declarative-schema-data-patch-in-magento-2-3/?utm_source=writeupcafe&utm_medium=article&utm_campaign=july-2022

https://stagebit.com/
Do you like StageBit's articles? Follow on social!

Login

Welcome to WriteUpCafe Community

Join our community to engage with fellow bloggers and increase the visibility of your blog.
Join WriteUpCafe