0

I have a question in my mind what is the exact difference between Extension Attributes and Custom Attributes with the example?

Is anyone here who can provide me with some ideas ?!

3 Answers 3

0

In Magento 2, both Extension Attributes and Custom Attributes are used to add additional fields to entities like products, orders, customers, etc. However, there are some differences between them.

Extension Attributes are used to extend the functionality of a module without changing the core code. They are used to add custom fields to an entity without affecting the database schema. Extension Attributes are defined in a separate file, and their values are stored in a separate table. For example, the Magento_Customer module uses an extension attribute to add a "reward points balance" field to customer objects.

Custom Attributes, on the other hand, are used to add custom fields to an entity by modifying the database schema. Custom Attributes are defined in the setup script of a module, and their values are stored in the entity's main table. For example, if you want to add a "shoe size" field to the product entity, you would define a custom attribute in a setup script, and its value would be stored in the catalog_product_entity_varchar table.

In summary, the main difference between Extension Attributes and Custom Attributes is that Extension Attributes are used to add custom fields without modifying the database schema, while Custom Attributes require modification of the database schema.

1

Extension Attributes and Custom Attributes are used to extend the functionality of Magento 2, but they serve slightly different purposes.

Extension Attributes are used to add additional fields to an existing API request or response, without modifying the core code. For example, you might use an Extension Attribute to add a "discount amount" field to the cart API response, so that third-party applications can retrieve the discount information easily.

Here's an example of how Extension Attributes might be used in Magento 2:

Let's say you want to add a custom field to the order API response to indicate whether the customer has opted-in for marketing emails. Instead of modifying the core Magento code, you can create an Extension Attribute that adds the new field to the API response.

Custom Attributes, on the other hand, are used to add custom fields to Magento's existing database tables. For example, you might use a Custom Attribute to add a "favorite color" field to the customer database table, so that you can store additional information about your customers.

Here's an example of how Custom Attributes might be used in Magento 2:

Let's say you want to add a custom field to the customer registration form to allow customers to enter their favorite color. You can create a Custom Attribute that adds the new field to the customer database table, and then modify the registration form template to include the new field.

In summary, Extension Attributes are used to extend the functionality of Magento's APIs, while Custom Attributes are used to add custom fields to Magento's database tables.

Thanks !!

0

The main difference between Extension Attributes and Custom Attributes is that Extension Attributes are added by the system developer to extend the system's functionality, while Custom Attributes are added by end-users to customize the system to meet their specific needs.

1
  • That’s not corect! There are many cases developer need to add custom attributes programmatically.
    – Tu Van
    Apr 2, 2023 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.