I'm trying to add a custom track url to the trackings, using extension attributes, i added these in extension_attributes.xml

  <extension_attributes for="Magento\Sales\Api\Data\ShipmentTrackInterface">
    <attribute code="track_url" type="string"/>
    <extension_attributes for="Magento\Sales\Api\Data\ShipmentTrackCreationInterface">
        <attribute code="track_url" type="string"/>

Cleared the generated codes and caches, interfaces are populating correctly, I used \Magento\Sales\Api\ShipOrderInterface::execute to save the shipment:


and the $data->getTracking() has data looking like this:

    "track_number": "1Z37X3X41217934386",
    "title": "ups",
    "carrier_code": "ups",
    "extension_attributes": {
      "track_url": "blah"

So everything looks fine and the extension attributes data are passed fine down to Magento\Framework\Model\AbstractExtensibleModel, however in Magento\Framework\Api\AbstractSimpleObject which is what Magento\Sales\Api\Data\ShipmentTrackExtension extends from, $data becomes an empty array, i still can’t figure out why this is happening, i’m in dev mode and shouldn’t need to run DI or something like that, any ideas?

  • 1
    Actually, you should provide all the files or at least describe what have you've done so far. From your description I couldn't see how you retrieve and save the data – Jimmy Apr 7 at 1:51
  • @Jimmy updated my question with how i'm saving the shipment. Since i'm using scalar attributes i don't think i'll need to add any plugins? When i dove into the code, it should be able to save the data but somehow extension_attributes got stripped at Magento\Framework\Api\AbstractSimpleObject constructor – Long M K Nguyễn Apr 7 at 18:34
  • 1
    "Since i'm using scalar attributes i don't think i'll need to add any plugins?" this is not correct, you have to manually touch the extension_attributes, they don't get saved into db automatically – Jimmy Apr 8 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.