Hello Magento Friends,

In this Magento tutorial, we will find out How to Add Dynamic Field in Admin Product Edit Form.

Magento provides flexibility to customize product attributes and forms according to specific business needs. By adding dynamic fields in admin product edit form you can tailor your product information to match your unique requirements without modifying the core code.

So let’s get started.

Steps to Add Dynamic Field in Product Create/Edit Form in Magento 2:

Here city and related shipping cost is saved on product. We can use this data on phtml file, controller file . 

Step 1: Create product attribute using below code. Using attributes we can save data of dynamic fields.

Add code at the below path

{{magento_root}}/app/code/Vendor/Extension/Setup/Patch/Data/Shippingdataattribute.php

Step 2: Add code in the Model file

{{magento_root}}/app/code/Vendor/Extension/Model/System/Config/Shipingmethod.php

Step 3: Create di.xml file at the following path.

{{magento_root}}/app/code/Vendor/Extension/etc/di.xml

And add the below-mentioned code.

Step 4: Create ui component file at the following path 

{{magento_root}}/app/code/Vendor/Extension/Ui/DataProvider/Product/Form/Modifier/AdvancedSupplierPrices.php

Now, add the below code snippet

Step 5: Create an event file at the path as follows to save attribute data. 

{{magento_root}}/app/code/Vendor/Extension/etc/events.xml

And include the following piece of code

Step 6: Create observer file at the following path to save attribute data

{{magento_root}}/app/code/Vendor/Observer/Saveshippingdata.php

Then add the below code

Output:

You can add multiple fields by clicking “Add Shipping Price”. 

custom field product edit form

Conclusion:

So this way, you can add dynamic fields in the product edit form in Magento 2. Utilize this capability to enhance your e-commerce store’s product management experience and gain a competitive edge in the market.

Happy Coding!

Click to rate this post!
[Total: 4 Average: 4]