Creating extension attributes

Creating a new extension attribute for an existing entity is usually a case of doing the following:

  1. Using setup scripts to set the attribute, column, or table for persistence
  2. Defining the extension attribute via <VendorName>/<ModuleName>/etc/extension_attributes.xml
  3. Adding an after and/or before plugin to the save, get, and getList methods of an entity repository

Moving forward, we are going to create extension attributes for the order entity, that is, customer_note and merchant_note.

We can imagine customer_note as an attribute that does not persist its value(s) in the sales_order table as order entity does, whereas merchant_note attribute does. This is why we created the sales_order.merchant_note column earlier ...

Get Magento 2 Development Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.