Hello I'm trying to add custom data to shipping method (image url, to be exact). Following this example I managed to add extension attribute to interface and show field named 'image' in extension attributes (in JSON view). So now I'm stuck on how to populate that extension attribute when creating method.

For example I would need to do something like this:

    $method = $this->_rateMethodFactory->create();

The problem is in this line:

// I also tried using this

But either way I can't get that because it doesn't exist when I list all data from shipping method in front controller. I tried using:

// I also tried

And when I try:


it returns null.

Could you please help me how set some data when creating method and pass it to extension attribute.

  • try using $method->addData() instead of $method->setData()
    – simple guy
    Oct 3 '17 at 8:56
  • This doesn't seem to work either. addData requires array and once array is passed it doesn't show it using getData(). Oct 3 '17 at 9:36

It's not that easy to pass data as extension attribute. Please refer to this question https://stackoverflow.com/q/34202497/2536631

  • Thank you for this link, but in the end I've solved it using Magento Registry since that data doesn't need to be stored anyway, just displayed at frontend. Jul 23 '18 at 14:55
  • how can you solve this? please let me know.
    – Akash
    Sep 17 '18 at 13:26

Your Answer

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

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