I'm a bit lost regarding the Magento 2 extension attributes. It's clear they offer a flexible way to extend the API/interfaces with your own attributes, but what I don't get is how to save the value to a custom database. If I look at the documentation at http://devdocs.magento.com/guides/v2.0/extension-dev-guide/attributes.html it would seem like an automatic system is in place to automatically join your data, but it doesn't work. What am I missing to actually save and get the values?

I'm trying to add a new attribute to shipmentItems's. My extension_attributes.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="\Magento\Sales\Model\Order\Shipment\Item">
        <attribute code="imei_codes" type="string">
            <join reference_table="custom_shipment_item" reference_field="item_id" join_on_field="shipment_item_id">

Next in my code I'm saving the custom attribute like this:

$extensionAttributes = $shipmentItem->getExtensionAttributes();

My custom database gets installed like this:

$table = $installer->getConnection()
         ['primary' => true, 'identity' => true, 'nullable' => false],
         'Primary ID of table'
         ['nullable' => true],
         'IMEI Codes'
     ->setComment('Custom Extended Shipment item Table');


The table is properly installed, but the data is not saved automatically to this table. What do I need in order to have this working? Is this the way to go to save some attribute related to shipment items?

Thank you very mucht for you assistance!

1 Answer 1


Currently, extension attributes are only about Web API. You need to save extension attributes manually using plugins on appropriate services.

Your Answer

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

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