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
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
add a comment |
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
Did you try $custom = $order->getMediabasebestellnummer();
– Sukumar Gorai
Jul 17 '18 at 10:48
add a comment |
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
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
magento2 custom-attributes
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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();`
is there also a possibility to Set?
– k33n
Jul 17 '18 at 10:53
@L.Klmnsetis 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
add a comment |
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>
where should I place that?
– k33n
Jul 17 '18 at 11:18
@L.Klmn it is used when you have column in bothquoteandordertable.
– 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
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%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
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();`
is there also a possibility to Set?
– k33n
Jul 17 '18 at 10:53
@L.Klmnsetis 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
add a comment |
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();`
is there also a possibility to Set?
– k33n
Jul 17 '18 at 10:53
@L.Klmnsetis 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
add a comment |
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();`
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();`
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.Klmnsetis 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
add a comment |
is there also a possibility to Set?
– k33n
Jul 17 '18 at 10:53
@L.Klmnsetis 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
add a comment |
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>
where should I place that?
– k33n
Jul 17 '18 at 11:18
@L.Klmn it is used when you have column in bothquoteandordertable.
– 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
add a comment |
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>
where should I place that?
– k33n
Jul 17 '18 at 11:18
@L.Klmn it is used when you have column in bothquoteandordertable.
– 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
add a comment |
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>
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>
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 bothquoteandordertable.
– 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
add a comment |
where should I place that?
– k33n
Jul 17 '18 at 11:18
@L.Klmn it is used when you have column in bothquoteandordertable.
– 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
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%2f234823%2fmagento-2-access-custom-order-attribute%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
Did you try $custom = $order->getMediabasebestellnummer();
– Sukumar Gorai
Jul 17 '18 at 10:48