Magento 2 | Access custom order attribute The Next CEO of Stack OverflowHow to access custom attribute added to a product?main.CRITICAL: Plugin class doesn't existMagento 2.1: Not add table into databaseMagento2 : Problem in block creationMagento 2 Add new field to Magento_User admin formAdd custom attribute in order emailI have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento offline custom Payment method with drop down listMagento 2.2.5: Custom Checkout Place Order ErrorCron deleting expired quotes

Extending anchors in TikZ

Disadvantage of gaining multiple levels at once in a short milestone-XP game

Why am I allowed to create multiple unique pointers from a single object?

Interfacing a button to MCU (and PC) with 50m long cable

Is there an analogue of projective spaces for proper schemes?

Does it take more energy to get to Venus or to Mars?

Workaholic Formal/Informal

Won the lottery - how do I keep the money?

Can we say or write : "No, it'sn't"?

How did people program for Consoles with multiple CPUs?

What connection does MS Office have to Netscape Navigator?

Return the Closest Prime Number

Why do airplanes bank sharply to the right after air-to-air refueling?

Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis

Why has the US not been more assertive in confronting Russia in recent years?

How to make a variable always equal to the result of some calculations?

Is it professional to write unrelated content in an almost-empty email?

WOW air has ceased operation, can I get my tickets refunded?

How to solve a differential equation with a term to a power?

MessageLevel in QGIS3

How do we know the LHC results are robust?

Inappropriate reference requests from Journal reviewers

How fast would a person need to move to trick the eye?

Indicator light circuit



Magento 2 | Access custom order attribute



The Next CEO of Stack OverflowHow to access custom attribute added to a product?main.CRITICAL: Plugin class doesn't existMagento 2.1: Not add table into databaseMagento2 : Problem in block creationMagento 2 Add new field to Magento_User admin formAdd custom attribute in order emailI have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento offline custom Payment method with drop down listMagento 2.2.5: Custom Checkout Place Order ErrorCron deleting expired quotes










4















I created an custom attribute for orders:




UpgradeSchema.php




<?php



use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;

class UpgradeSchema implements UpgradeSchemaInterface

/**
* Upgrades DB schema for a module
*
* @param SchemaSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)

$setup->startSetup();

$quote = 'quote';
$orderTable = 'sales_order';

$setup->getConnection()
->addColumn(
$setup->getTable($quote),
'mediabasebestellnummer',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'comment' =>'MediabaseNummer'
]
);
//Order table
$setup->getConnection()
->addColumn(
$setup->getTable($orderTable),
'mediabasebestellnummer',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'comment' =>'MediabaseNummer'
]
);

$setup->endSetup();




Right now my question is how get the custom attribute when I have an order.
This is NOT working:



$custom = $order->getCustomAttribute('mediabasebestellnummer');


Thanks for any help!










share|improve this question
























  • Did you try $custom = $order->getMediabasebestellnummer();

    – Sukumar Gorai
    Jul 17 '18 at 10:48















4















I created an custom attribute for orders:




UpgradeSchema.php




<?php



use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;

class UpgradeSchema implements UpgradeSchemaInterface

/**
* Upgrades DB schema for a module
*
* @param SchemaSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)

$setup->startSetup();

$quote = 'quote';
$orderTable = 'sales_order';

$setup->getConnection()
->addColumn(
$setup->getTable($quote),
'mediabasebestellnummer',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'comment' =>'MediabaseNummer'
]
);
//Order table
$setup->getConnection()
->addColumn(
$setup->getTable($orderTable),
'mediabasebestellnummer',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'comment' =>'MediabaseNummer'
]
);

$setup->endSetup();




Right now my question is how get the custom attribute when I have an order.
This is NOT working:



$custom = $order->getCustomAttribute('mediabasebestellnummer');


Thanks for any help!










share|improve this question
























  • Did you try $custom = $order->getMediabasebestellnummer();

    – Sukumar Gorai
    Jul 17 '18 at 10:48













4












4








4








I created an custom attribute for orders:




UpgradeSchema.php




<?php



use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;

class UpgradeSchema implements UpgradeSchemaInterface

/**
* Upgrades DB schema for a module
*
* @param SchemaSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)

$setup->startSetup();

$quote = 'quote';
$orderTable = 'sales_order';

$setup->getConnection()
->addColumn(
$setup->getTable($quote),
'mediabasebestellnummer',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'comment' =>'MediabaseNummer'
]
);
//Order table
$setup->getConnection()
->addColumn(
$setup->getTable($orderTable),
'mediabasebestellnummer',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'comment' =>'MediabaseNummer'
]
);

$setup->endSetup();




Right now my question is how get the custom attribute when I have an order.
This is NOT working:



$custom = $order->getCustomAttribute('mediabasebestellnummer');


Thanks for any help!










share|improve this question
















I created an custom attribute for orders:




UpgradeSchema.php




<?php



use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;

class UpgradeSchema implements UpgradeSchemaInterface

/**
* Upgrades DB schema for a module
*
* @param SchemaSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)

$setup->startSetup();

$quote = 'quote';
$orderTable = 'sales_order';

$setup->getConnection()
->addColumn(
$setup->getTable($quote),
'mediabasebestellnummer',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'comment' =>'MediabaseNummer'
]
);
//Order table
$setup->getConnection()
->addColumn(
$setup->getTable($orderTable),
'mediabasebestellnummer',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'comment' =>'MediabaseNummer'
]
);

$setup->endSetup();




Right now my question is how get the custom attribute when I have an order.
This is NOT working:



$custom = $order->getCustomAttribute('mediabasebestellnummer');


Thanks for any help!







magento2 custom-attributes






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 mins ago







k33n

















asked Jul 17 '18 at 10:47









k33nk33n

455110




455110












  • Did you try $custom = $order->getMediabasebestellnummer();

    – Sukumar Gorai
    Jul 17 '18 at 10:48

















  • Did you try $custom = $order->getMediabasebestellnummer();

    – Sukumar Gorai
    Jul 17 '18 at 10:48
















Did you try $custom = $order->getMediabasebestellnummer();

– Sukumar Gorai
Jul 17 '18 at 10:48





Did you try $custom = $order->getMediabasebestellnummer();

– Sukumar Gorai
Jul 17 '18 at 10:48










2 Answers
2






active

oldest

votes


















5














check if the column is created in sales_order table



Now getting the values



 $order->getMediabasebestellnummer();


Or



$order->getData('mediabasebestellnummer');


For adding the data



 $order->setMediabasebestellnummer('test value')->save();


or



 $order->setData('mediabasebestellnummer','test value')->save();


or



$data = array('mediabasebestellnummer'=>'test');
$order->setData($data)->save();`





share|improve this answer

























  • is there also a possibility to Set?

    – k33n
    Jul 17 '18 at 10:53











  • @L.Klmn set is use to assign the value not for fetching.

    – Qaisar Satti
    Jul 17 '18 at 10:54











  • yes I also need that. :)

    – k33n
    Jul 17 '18 at 10:55











  • @L.Klmn added the possible solutions ..

    – Qaisar Satti
    Jul 17 '18 at 10:59


















3














Make sure you have file fieldset.xml in your module to convert data from quote to order.



<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
<fieldset id="sales_convert_quote">
<field name="mediabasebestellnummer">
<aspect name="to_order" />
</field>
</fieldset>
</scope>
</config>





share|improve this answer























  • where should I place that?

    – k33n
    Jul 17 '18 at 11:18











  • @L.Klmn it is used when you have column in both quote and order table.

    – Qaisar Satti
    Jul 17 '18 at 11:24











  • @L.Klmn You could place that in etc folder, and yes, if you have column in both table, it will convert from quote table to sales_order table

    – Quan Le
    Jul 17 '18 at 11:27











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%2f234823%2fmagento-2-access-custom-order-attribute%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














check if the column is created in sales_order table



Now getting the values



 $order->getMediabasebestellnummer();


Or



$order->getData('mediabasebestellnummer');


For adding the data



 $order->setMediabasebestellnummer('test value')->save();


or



 $order->setData('mediabasebestellnummer','test value')->save();


or



$data = array('mediabasebestellnummer'=>'test');
$order->setData($data)->save();`





share|improve this answer

























  • is there also a possibility to Set?

    – k33n
    Jul 17 '18 at 10:53











  • @L.Klmn set is use to assign the value not for fetching.

    – Qaisar Satti
    Jul 17 '18 at 10:54











  • yes I also need that. :)

    – k33n
    Jul 17 '18 at 10:55











  • @L.Klmn added the possible solutions ..

    – Qaisar Satti
    Jul 17 '18 at 10:59















5














check if the column is created in sales_order table



Now getting the values



 $order->getMediabasebestellnummer();


Or



$order->getData('mediabasebestellnummer');


For adding the data



 $order->setMediabasebestellnummer('test value')->save();


or



 $order->setData('mediabasebestellnummer','test value')->save();


or



$data = array('mediabasebestellnummer'=>'test');
$order->setData($data)->save();`





share|improve this answer

























  • is there also a possibility to Set?

    – k33n
    Jul 17 '18 at 10:53











  • @L.Klmn set is use to assign the value not for fetching.

    – Qaisar Satti
    Jul 17 '18 at 10:54











  • yes I also need that. :)

    – k33n
    Jul 17 '18 at 10:55











  • @L.Klmn added the possible solutions ..

    – Qaisar Satti
    Jul 17 '18 at 10:59













5












5








5







check if the column is created in sales_order table



Now getting the values



 $order->getMediabasebestellnummer();


Or



$order->getData('mediabasebestellnummer');


For adding the data



 $order->setMediabasebestellnummer('test value')->save();


or



 $order->setData('mediabasebestellnummer','test value')->save();


or



$data = array('mediabasebestellnummer'=>'test');
$order->setData($data)->save();`





share|improve this answer















check if the column is created in sales_order table



Now getting the values



 $order->getMediabasebestellnummer();


Or



$order->getData('mediabasebestellnummer');


For adding the data



 $order->setMediabasebestellnummer('test value')->save();


or



 $order->setData('mediabasebestellnummer','test value')->save();


or



$data = array('mediabasebestellnummer'=>'test');
$order->setData($data)->save();`






share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 17 '18 at 10:58

























answered Jul 17 '18 at 10:51









Qaisar SattiQaisar Satti

27k1256109




27k1256109












  • is there also a possibility to Set?

    – k33n
    Jul 17 '18 at 10:53











  • @L.Klmn set is use to assign the value not for fetching.

    – Qaisar Satti
    Jul 17 '18 at 10:54











  • yes I also need that. :)

    – k33n
    Jul 17 '18 at 10:55











  • @L.Klmn added the possible solutions ..

    – Qaisar Satti
    Jul 17 '18 at 10:59

















  • is there also a possibility to Set?

    – k33n
    Jul 17 '18 at 10:53











  • @L.Klmn set is use to assign the value not for fetching.

    – Qaisar Satti
    Jul 17 '18 at 10:54











  • yes I also need that. :)

    – k33n
    Jul 17 '18 at 10:55











  • @L.Klmn added the possible solutions ..

    – Qaisar Satti
    Jul 17 '18 at 10:59
















is there also a possibility to Set?

– k33n
Jul 17 '18 at 10:53





is there also a possibility to Set?

– k33n
Jul 17 '18 at 10:53













@L.Klmn set is use to assign the value not for fetching.

– Qaisar Satti
Jul 17 '18 at 10:54





@L.Klmn set is use to assign the value not for fetching.

– Qaisar Satti
Jul 17 '18 at 10:54













yes I also need that. :)

– k33n
Jul 17 '18 at 10:55





yes I also need that. :)

– k33n
Jul 17 '18 at 10:55













@L.Klmn added the possible solutions ..

– Qaisar Satti
Jul 17 '18 at 10:59





@L.Klmn added the possible solutions ..

– Qaisar Satti
Jul 17 '18 at 10:59













3














Make sure you have file fieldset.xml in your module to convert data from quote to order.



<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
<fieldset id="sales_convert_quote">
<field name="mediabasebestellnummer">
<aspect name="to_order" />
</field>
</fieldset>
</scope>
</config>





share|improve this answer























  • where should I place that?

    – k33n
    Jul 17 '18 at 11:18











  • @L.Klmn it is used when you have column in both quote and order table.

    – Qaisar Satti
    Jul 17 '18 at 11:24











  • @L.Klmn You could place that in etc folder, and yes, if you have column in both table, it will convert from quote table to sales_order table

    – Quan Le
    Jul 17 '18 at 11:27















3














Make sure you have file fieldset.xml in your module to convert data from quote to order.



<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
<fieldset id="sales_convert_quote">
<field name="mediabasebestellnummer">
<aspect name="to_order" />
</field>
</fieldset>
</scope>
</config>





share|improve this answer























  • where should I place that?

    – k33n
    Jul 17 '18 at 11:18











  • @L.Klmn it is used when you have column in both quote and order table.

    – Qaisar Satti
    Jul 17 '18 at 11:24











  • @L.Klmn You could place that in etc folder, and yes, if you have column in both table, it will convert from quote table to sales_order table

    – Quan Le
    Jul 17 '18 at 11:27













3












3








3







Make sure you have file fieldset.xml in your module to convert data from quote to order.



<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
<fieldset id="sales_convert_quote">
<field name="mediabasebestellnummer">
<aspect name="to_order" />
</field>
</fieldset>
</scope>
</config>





share|improve this answer













Make sure you have file fieldset.xml in your module to convert data from quote to order.



<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
<fieldset id="sales_convert_quote">
<field name="mediabasebestellnummer">
<aspect name="to_order" />
</field>
</fieldset>
</scope>
</config>






share|improve this answer












share|improve this answer



share|improve this answer










answered Jul 17 '18 at 11:10









Quan LeQuan Le

1,3401717




1,3401717












  • where should I place that?

    – k33n
    Jul 17 '18 at 11:18











  • @L.Klmn it is used when you have column in both quote and order table.

    – Qaisar Satti
    Jul 17 '18 at 11:24











  • @L.Klmn You could place that in etc folder, and yes, if you have column in both table, it will convert from quote table to sales_order table

    – Quan Le
    Jul 17 '18 at 11:27

















  • where should I place that?

    – k33n
    Jul 17 '18 at 11:18











  • @L.Klmn it is used when you have column in both quote and order table.

    – Qaisar Satti
    Jul 17 '18 at 11:24











  • @L.Klmn You could place that in etc folder, and yes, if you have column in both table, it will convert from quote table to sales_order table

    – Quan Le
    Jul 17 '18 at 11:27
















where should I place that?

– k33n
Jul 17 '18 at 11:18





where should I place that?

– k33n
Jul 17 '18 at 11:18













@L.Klmn it is used when you have column in both quote and order table.

– Qaisar Satti
Jul 17 '18 at 11:24





@L.Klmn it is used when you have column in both quote and order table.

– Qaisar Satti
Jul 17 '18 at 11:24













@L.Klmn You could place that in etc folder, and yes, if you have column in both table, it will convert from quote table to sales_order table

– Quan Le
Jul 17 '18 at 11:27





@L.Klmn You could place that in etc folder, and yes, if you have column in both table, it will convert from quote table to sales_order table

– Quan Le
Jul 17 '18 at 11:27

















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%2f234823%2fmagento-2-access-custom-order-attribute%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

Best approach to update all entries in a list that is paginated?Best way to add items to a paginated listChoose Your Country: Best Usability approachUpdate list when a user is viewing the list without annoying themWhen would the best day to update your webpage be?What should happen when I add a Row to a paginated, sorted listShould I adopt infinite scrolling or classical pagination?How to show user that page objects automatically updateWhat is the best location to locate the comments section in a list pageBest way to combine filtering and selecting items in a listWhen one of two inputs must be updated to satisfy a consistency criteria, which should you update (if at all)?

Вунгтау (аеропорт) Загальні відомості | Див. також | Посилання | Навігаційне меню10°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.0833310°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.083337731608Vinh AirportVinh airport facelift improves serviceвиправивши або дописавши їївиправивши або дописавши їїр

Тонконіг бульбистий Зміст Опис | Поширення | Екологія | Господарське значення | Примітки | Див. також | Література | Джерела | Посилання | Навігаційне меню1114601320038-241116202404kew-435458Poa bulbosaЭлектронный каталог сосудистых растений Азиатской России [Електронний каталог судинних рослин Азіатської Росії]Малышев Л. Л. Дикие родичи культурных растений. Poa bulbosa L. - Мятлик луковичный. [Малишев Л. Л. Дикі родичи культурних рослин. Poa bulbosa L. - Тонконіг бульбистий.]Мятлик (POA) Сем. Злаки (Мятликовые) [Тонконіг (POA) Род. Злаки (Тонконогові)]Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Description from Flora of China) [Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Опис від Флора Китаю)]Poa bulbosa L. – lipnice cibulkatá / lipnica cibulkatáPoa bulbosa в базі даних Poa bulbosa на сайті Poa bulbosa в базі даних «Global Biodiversity Information Facility» (GBIF)Poa bulbosa в базі даних «Euro + Med PlantBase» — інформаційному ресурсі для Євро-середземноморського розмаїття рослинPoa bulbosa L. на сайті «Плантариум»