Service Contracts

Magento is a modular system that enables third-party developers to customize and overwrite 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


Planning to implement Magento 2

Our Magento-certified experts come up with best-in-class solutions to improve conversions, increase sales and also provide a great user experience.

Get In Touch


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

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


Be the first to Know

Subscribe to our blog to get the latest articles directly to your inbox.


Request a Quote Today

Request a Quote

Leave a Reply

1 Comment on "Extension Attributes in Magento2"

negin nickparsa
3 months 6 days ago

Thank you for the article! This is nice!