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;
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
add a comment |
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
add a comment |
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
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
magento2 model extension-attributes interface
edited Apr 27 '17 at 9:36
Ankit Shah
5,0061067145
5,0061067145
asked Apr 27 '17 at 9:32
mag777mag777
185
185
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
MagentoGiftMessageModelPluginOrderGetand
MagentoGiftMessageModelPluginOrderSavefor an example.
Thank you. I will have a look at it and then see what happens.
– mag777
Apr 27 '17 at 11:22
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
MagentoGiftMessageModelPluginOrderGetand
MagentoGiftMessageModelPluginOrderSavefor an example.
Thank you. I will have a look at it and then see what happens.
– mag777
Apr 27 '17 at 11:22
add a comment |
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
MagentoGiftMessageModelPluginOrderGetand
MagentoGiftMessageModelPluginOrderSavefor an example.
Thank you. I will have a look at it and then see what happens.
– mag777
Apr 27 '17 at 11:22
add a comment |
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
MagentoGiftMessageModelPluginOrderGetand
MagentoGiftMessageModelPluginOrderSavefor an example.
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
MagentoGiftMessageModelPluginOrderGetand
MagentoGiftMessageModelPluginOrderSavefor an example.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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