Service Contracts

Magento is a modular system that enables third-party developers to customize and overwrite the core parts of its framework. This flexibility, however, comes at a price. Business logic tends to leak across the layers of the Magento system, which manifests as a duplicated and inconsistent code.

Merchants might be reluctant to upgrade Magento because customized extensions that they have purchased might not be compatible with new versions of Magento. Also, Magento and third-party developers can find it difficult to track and report the dependencies that customized extensions have on other extensions.

To address these issues, the Magento system introduces service contracts.

Extension Attributes

Extension attributes are new in Magento 2. They are used to extend functionalities and often use more complex data types than custom attributes. Extension Attributes are used to allow for customization of the strict Service Contracts. These attributes do not appear on the GUI.

How to define Extension Attributes?


How to use extension attributes in Magento 2 Checkout?

1. Create a module.xml and registration.php to register your module.

For example, app/code/Dckap/ExtensionAttributes /etc/module.xml


2. Create the install script in the Setup directory.


3. Define the extension attribute in XML


4. Create the field for extension attributes in knockout HTML

Migrate To Magento 2

5. Assigning the value for  extension attributes in knockout  js


Observe the input field in initialize function

Set the value to extension attributes in shipping information


6. Save the extension attribute value using the plugin

Define the plugin in di.xml


Save the value of extension attributes in qoute address


7. Retrieve the extension attributes value using observer

Define the observer in events.xml


Get the value of extension attributes and save in order using the observer
app/code/Dckap/ExtensionAttributes/Observer/ Observeorder.php

I hope the article was useful. Please let us know if you have any queries or comments.


Magento development services include extensions which can be customized according to the store owner needs. Learn about extension attributes in Magento 2


  • Sridevi

    Sridevi Murugaraj, a junior software engineer, started her career in Magento eCommerce platform. Within months she gained extensive knowledge and now she is exemplar of developers building Magento solutions and Android applications. She craves to cook her own recipes and rejoices in listening to world music.


Ready to drive online revenue

Get In Touch

2 thoughts on “Extension Attributes in Magento2

Leave a Reply

Your email address will not be published. Required fields are marked *