How to get Extension Attribute in a model in Magento 2?Magento 2 - Losing data with extension attributes in bundle options collectionHow can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Can't get extension attributes in observer - Magento 2Magento 2.1 Rest API - Adding to Extension Attributes for VI/Orders/?searchcriteriaMagento 2 copy extension attribute value from quote to orderMagento 2.2.5: Overriding Admin Controller sales/orderShipping method returns zero amountMagento 2 Save custom customer address attribute in customer edit form using extension attributes

Function pointer with named arguments?

Is there really no use for MD5 anymore?

How do I reattach a shelf to the wall when it ripped out of the wall?

Minor Revision with suggestion of an alternative proof by reviewer

Do I have an "anti-research" personality?

Aligning equation numbers vertically

How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?

How to write a column outside the braces in a matrix?

Is Diceware more secure than a long passphrase?

How much cash can I safely carry into the USA and avoid civil forfeiture?

How to not starve gigantic beasts

How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?

Is the claim "Employers won't employ people with no 'social media presence'" realistic?

Like totally amazing interchangeable sister outfits II: The Revenge

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

Does tea made with boiling water cool faster than tea made with boiled (but still hot) water?

What happened to Captain America in Endgame?

Which big number is bigger?

Check if a string is entirely made of the same substring

"The cow" OR "a cow" OR "cows" in this context

Apply MapThread to all but one variable

As an international instructor, should I openly talk about my accent?

Can an Area of Effect spell cast outside a Prismatic Wall extend inside it?

What makes accurate emulation of old systems a difficult task?



How to get Extension Attribute in a model in Magento 2?


Magento 2 - Losing data with extension attributes in bundle options collectionHow can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Can't get extension attributes in observer - Magento 2Magento 2.1 Rest API - Adding to Extension Attributes for VI/Orders/?searchcriteriaMagento 2 copy extension attribute value from quote to orderMagento 2.2.5: Overriding Admin Controller sales/orderShipping method returns zero amountMagento 2 Save custom customer address attribute in customer edit form using extension attributes






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I have added an extension attribute by creating extension_attributes.xml file in etc. Its content is:



<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="MagentoQuoteApiDataAddressInterface">
<attribute code="custom_field" type="string" />
</extension_attributes>
</config>


Now when I try to get extension attribute in model I use following code:



 $objectManager = MagentoFrameworkAppObjectManager::getInstance();
$address = $objectManager->get('MagentoQuoteApiDataAddressInterface');
echo $address->getExtensionAttributes()->getCustomField();


But the problem is $address->getExtensionAttributes() return NULL. What am I doing wrong here?










share|improve this question






























    2















    I have added an extension attribute by creating extension_attributes.xml file in etc. Its content is:



    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="MagentoQuoteApiDataAddressInterface">
    <attribute code="custom_field" type="string" />
    </extension_attributes>
    </config>


    Now when I try to get extension attribute in model I use following code:



     $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $address = $objectManager->get('MagentoQuoteApiDataAddressInterface');
    echo $address->getExtensionAttributes()->getCustomField();


    But the problem is $address->getExtensionAttributes() return NULL. What am I doing wrong here?










    share|improve this question


























      2












      2








      2








      I have added an extension attribute by creating extension_attributes.xml file in etc. Its content is:



      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
      <extension_attributes for="MagentoQuoteApiDataAddressInterface">
      <attribute code="custom_field" type="string" />
      </extension_attributes>
      </config>


      Now when I try to get extension attribute in model I use following code:



       $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $address = $objectManager->get('MagentoQuoteApiDataAddressInterface');
      echo $address->getExtensionAttributes()->getCustomField();


      But the problem is $address->getExtensionAttributes() return NULL. What am I doing wrong here?










      share|improve this question
















      I have added an extension attribute by creating extension_attributes.xml file in etc. Its content is:



      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
      <extension_attributes for="MagentoQuoteApiDataAddressInterface">
      <attribute code="custom_field" type="string" />
      </extension_attributes>
      </config>


      Now when I try to get extension attribute in model I use following code:



       $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $address = $objectManager->get('MagentoQuoteApiDataAddressInterface');
      echo $address->getExtensionAttributes()->getCustomField();


      But the problem is $address->getExtensionAttributes() return NULL. What am I doing wrong here?







      magento2 model extension-attributes interface






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 27 '17 at 9:36









      Ankit Shah

      5,0061067145




      5,0061067145










      asked Apr 27 '17 at 9:32









      mag777mag777

      185




      185




















          1 Answer
          1






          active

          oldest

          votes


















          0














          As also written here (different question but same answer):




          The documentation for extension attributes is not quite clear on
          what's the right way to use them and it seems like each entity type
          does it in a slightly different way.



          That being said, from my experience you have to create plugins to
          populate the extension attributes, and also to save them. It is not
          done automatically.



          Take a look at MagentoGiftMessageModelPluginOrderGet and
          MagentoGiftMessageModelPluginOrderSave for an example.







          share|improve this answer























          • Thank you. I will have a look at it and then see what happens.

            – mag777
            Apr 27 '17 at 11:22











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f172013%2fhow-to-get-extension-attribute-in-a-model-in-magento-2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          As also written here (different question but same answer):




          The documentation for extension attributes is not quite clear on
          what's the right way to use them and it seems like each entity type
          does it in a slightly different way.



          That being said, from my experience you have to create plugins to
          populate the extension attributes, and also to save them. It is not
          done automatically.



          Take a look at MagentoGiftMessageModelPluginOrderGet and
          MagentoGiftMessageModelPluginOrderSave for an example.







          share|improve this answer























          • Thank you. I will have a look at it and then see what happens.

            – mag777
            Apr 27 '17 at 11:22















          0














          As also written here (different question but same answer):




          The documentation for extension attributes is not quite clear on
          what's the right way to use them and it seems like each entity type
          does it in a slightly different way.



          That being said, from my experience you have to create plugins to
          populate the extension attributes, and also to save them. It is not
          done automatically.



          Take a look at MagentoGiftMessageModelPluginOrderGet and
          MagentoGiftMessageModelPluginOrderSave for an example.







          share|improve this answer























          • Thank you. I will have a look at it and then see what happens.

            – mag777
            Apr 27 '17 at 11:22













          0












          0








          0







          As also written here (different question but same answer):




          The documentation for extension attributes is not quite clear on
          what's the right way to use them and it seems like each entity type
          does it in a slightly different way.



          That being said, from my experience you have to create plugins to
          populate the extension attributes, and also to save them. It is not
          done automatically.



          Take a look at MagentoGiftMessageModelPluginOrderGet and
          MagentoGiftMessageModelPluginOrderSave for an example.







          share|improve this answer













          As also written here (different question but same answer):




          The documentation for extension attributes is not quite clear on
          what's the right way to use them and it seems like each entity type
          does it in a slightly different way.



          That being said, from my experience you have to create plugins to
          populate the extension attributes, and also to save them. It is not
          done automatically.



          Take a look at MagentoGiftMessageModelPluginOrderGet and
          MagentoGiftMessageModelPluginOrderSave for an example.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 27 '17 at 9:44









          Fabian SchmenglerFabian Schmengler

          55.5k21139354




          55.5k21139354












          • Thank you. I will have a look at it and then see what happens.

            – mag777
            Apr 27 '17 at 11:22

















          • Thank you. I will have a look at it and then see what happens.

            – mag777
            Apr 27 '17 at 11:22
















          Thank you. I will have a look at it and then see what happens.

          – mag777
          Apr 27 '17 at 11:22





          Thank you. I will have a look at it and then see what happens.

          – mag777
          Apr 27 '17 at 11:22

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f172013%2fhow-to-get-extension-attribute-in-a-model-in-magento-2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

          Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

          Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림