Magento 2.3 - How to add custom column to customer_entity table
I'm creating a Referral Program module, and I want to create a custom column inside the customer_entity
table. The column is referred_by
and it's a foreign key that as a relation with the customer_entity
table itself. This column contains the id of the customer that sent the referral_code
. How can I implement this? How can I add this field inside the customer_entity
table? I try to add an attribute as static
type, but the new column doesn't appear inside that table. I need to declere the db_schema.xml?
customer-attribute declarative-schema
New contributor
add a comment |
I'm creating a Referral Program module, and I want to create a custom column inside the customer_entity
table. The column is referred_by
and it's a foreign key that as a relation with the customer_entity
table itself. This column contains the id of the customer that sent the referral_code
. How can I implement this? How can I add this field inside the customer_entity
table? I try to add an attribute as static
type, but the new column doesn't appear inside that table. I need to declere the db_schema.xml?
customer-attribute declarative-schema
New contributor
add a comment |
I'm creating a Referral Program module, and I want to create a custom column inside the customer_entity
table. The column is referred_by
and it's a foreign key that as a relation with the customer_entity
table itself. This column contains the id of the customer that sent the referral_code
. How can I implement this? How can I add this field inside the customer_entity
table? I try to add an attribute as static
type, but the new column doesn't appear inside that table. I need to declere the db_schema.xml?
customer-attribute declarative-schema
New contributor
I'm creating a Referral Program module, and I want to create a custom column inside the customer_entity
table. The column is referred_by
and it's a foreign key that as a relation with the customer_entity
table itself. This column contains the id of the customer that sent the referral_code
. How can I implement this? How can I add this field inside the customer_entity
table? I try to add an attribute as static
type, but the new column doesn't appear inside that table. I need to declere the db_schema.xml?
customer-attribute declarative-schema
customer-attribute declarative-schema
New contributor
New contributor
New contributor
asked Mar 20 at 9:01
Mirko RapisardaMirko Rapisarda
436
436
New contributor
New contributor
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can try using following code.
app/code/Anshu/CustomerEdit/registration.php
<?php
use MagentoFrameworkComponentComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Anshu_CustomerEdit',
__DIR__
);
app/code/Anshu/CustomerEdit/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Anshu_CustomerEdit" >
<sequence>
<module name="Magento_Customer"/>
</sequence>
</module>
</config>
app/code/Anshu/CustomerEdit/etc/db_schema.xml
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="customer_entity">
<column xsi:type="int" name="referred_by" padding="10" unsigned="true" nullable="false"
comment="Referred By"/>
<constraint xsi:type="foreign" referenceId="CUSTOMER_ENTITY_REFERRED_BY_CUSTOMER_ENTITY_ENTITY_ID" table="customer_entity"
column="referred_by" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
</table>
</schema>
Then run following command to generate db_schema_whitelist.json
bin/magento setup:db-declaration:generate-whitelist
Then run bin/magento setup:upgrade
command.
Here Anshu
is the module namespace and CustomerEdit
is the module name.
You can modify code according to your requirement.
How do you set value to this field @AnushuMishra
– Prathap Gunasekaran
Mar 20 at 9:56
@PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…
– Anshu Mishra
Mar 20 at 10:19
add a comment |
You can use InstallSchema
Script to do that. Kindly refer below code:
<?php
namespace vendormoduleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkDBDdlTable;
class InstallSchema implements InstallSchemaInterface
{
/**
* {@inheritdoc}
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$table = $setup->getConnection()->newTable(
$setup->getTable('customer_entity')
)->addColumn(
'referred_by',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
255,
['identity' => true, 'nullable' => true],
'Referred By'
)->setComment("Id of the customer that sent the Referral code");
$setup->getConnection()->createTable($table);
$setup->endSetup();
}
}
ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set
– Mirko Rapisarda
Mar 20 at 9:33
1
@magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong
– Prathap Gunasekaran
Mar 20 at 9:36
@MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.
– Prathap Gunasekaran
Mar 20 at 9:37
@PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.
– magefms
Mar 20 at 9:40
1
@PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column
– Mirko Rapisarda
Mar 20 at 9:40
add a comment |
Create new customer custom attribute for referral_code while installing referral module. here is a link to follow how to add custom attribute in customer section.
https://www.mageplaza.com/magento-2-module-development/magento-2-add-customer-attribute-programmatically.html
you can fetch custom attribute value from customer object using below code.
$customer->getCustomAttribute('FIELD_NAME')->getValue();
replace FIELD_NAME by your custom attribute name
but in this way I lost the possibility to add thereferenced_by
field as a foreign key
– Mirko Rapisarda
Mar 20 at 9:37
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
});
}
});
Mirko Rapisarda is a new contributor. Be nice, and check out our Code of Conduct.
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%2f266635%2fmagento-2-3-how-to-add-custom-column-to-customer-entity-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can try using following code.
app/code/Anshu/CustomerEdit/registration.php
<?php
use MagentoFrameworkComponentComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Anshu_CustomerEdit',
__DIR__
);
app/code/Anshu/CustomerEdit/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Anshu_CustomerEdit" >
<sequence>
<module name="Magento_Customer"/>
</sequence>
</module>
</config>
app/code/Anshu/CustomerEdit/etc/db_schema.xml
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="customer_entity">
<column xsi:type="int" name="referred_by" padding="10" unsigned="true" nullable="false"
comment="Referred By"/>
<constraint xsi:type="foreign" referenceId="CUSTOMER_ENTITY_REFERRED_BY_CUSTOMER_ENTITY_ENTITY_ID" table="customer_entity"
column="referred_by" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
</table>
</schema>
Then run following command to generate db_schema_whitelist.json
bin/magento setup:db-declaration:generate-whitelist
Then run bin/magento setup:upgrade
command.
Here Anshu
is the module namespace and CustomerEdit
is the module name.
You can modify code according to your requirement.
How do you set value to this field @AnushuMishra
– Prathap Gunasekaran
Mar 20 at 9:56
@PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…
– Anshu Mishra
Mar 20 at 10:19
add a comment |
You can try using following code.
app/code/Anshu/CustomerEdit/registration.php
<?php
use MagentoFrameworkComponentComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Anshu_CustomerEdit',
__DIR__
);
app/code/Anshu/CustomerEdit/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Anshu_CustomerEdit" >
<sequence>
<module name="Magento_Customer"/>
</sequence>
</module>
</config>
app/code/Anshu/CustomerEdit/etc/db_schema.xml
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="customer_entity">
<column xsi:type="int" name="referred_by" padding="10" unsigned="true" nullable="false"
comment="Referred By"/>
<constraint xsi:type="foreign" referenceId="CUSTOMER_ENTITY_REFERRED_BY_CUSTOMER_ENTITY_ENTITY_ID" table="customer_entity"
column="referred_by" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
</table>
</schema>
Then run following command to generate db_schema_whitelist.json
bin/magento setup:db-declaration:generate-whitelist
Then run bin/magento setup:upgrade
command.
Here Anshu
is the module namespace and CustomerEdit
is the module name.
You can modify code according to your requirement.
How do you set value to this field @AnushuMishra
– Prathap Gunasekaran
Mar 20 at 9:56
@PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…
– Anshu Mishra
Mar 20 at 10:19
add a comment |
You can try using following code.
app/code/Anshu/CustomerEdit/registration.php
<?php
use MagentoFrameworkComponentComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Anshu_CustomerEdit',
__DIR__
);
app/code/Anshu/CustomerEdit/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Anshu_CustomerEdit" >
<sequence>
<module name="Magento_Customer"/>
</sequence>
</module>
</config>
app/code/Anshu/CustomerEdit/etc/db_schema.xml
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="customer_entity">
<column xsi:type="int" name="referred_by" padding="10" unsigned="true" nullable="false"
comment="Referred By"/>
<constraint xsi:type="foreign" referenceId="CUSTOMER_ENTITY_REFERRED_BY_CUSTOMER_ENTITY_ENTITY_ID" table="customer_entity"
column="referred_by" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
</table>
</schema>
Then run following command to generate db_schema_whitelist.json
bin/magento setup:db-declaration:generate-whitelist
Then run bin/magento setup:upgrade
command.
Here Anshu
is the module namespace and CustomerEdit
is the module name.
You can modify code according to your requirement.
You can try using following code.
app/code/Anshu/CustomerEdit/registration.php
<?php
use MagentoFrameworkComponentComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Anshu_CustomerEdit',
__DIR__
);
app/code/Anshu/CustomerEdit/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Anshu_CustomerEdit" >
<sequence>
<module name="Magento_Customer"/>
</sequence>
</module>
</config>
app/code/Anshu/CustomerEdit/etc/db_schema.xml
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="customer_entity">
<column xsi:type="int" name="referred_by" padding="10" unsigned="true" nullable="false"
comment="Referred By"/>
<constraint xsi:type="foreign" referenceId="CUSTOMER_ENTITY_REFERRED_BY_CUSTOMER_ENTITY_ENTITY_ID" table="customer_entity"
column="referred_by" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
</table>
</schema>
Then run following command to generate db_schema_whitelist.json
bin/magento setup:db-declaration:generate-whitelist
Then run bin/magento setup:upgrade
command.
Here Anshu
is the module namespace and CustomerEdit
is the module name.
You can modify code according to your requirement.
answered Mar 20 at 9:42
Anshu MishraAnshu Mishra
5,51652660
5,51652660
How do you set value to this field @AnushuMishra
– Prathap Gunasekaran
Mar 20 at 9:56
@PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…
– Anshu Mishra
Mar 20 at 10:19
add a comment |
How do you set value to this field @AnushuMishra
– Prathap Gunasekaran
Mar 20 at 9:56
@PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…
– Anshu Mishra
Mar 20 at 10:19
How do you set value to this field @AnushuMishra
– Prathap Gunasekaran
Mar 20 at 9:56
How do you set value to this field @AnushuMishra
– Prathap Gunasekaran
Mar 20 at 9:56
@PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…
– Anshu Mishra
Mar 20 at 10:19
@PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…
– Anshu Mishra
Mar 20 at 10:19
add a comment |
You can use InstallSchema
Script to do that. Kindly refer below code:
<?php
namespace vendormoduleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkDBDdlTable;
class InstallSchema implements InstallSchemaInterface
{
/**
* {@inheritdoc}
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$table = $setup->getConnection()->newTable(
$setup->getTable('customer_entity')
)->addColumn(
'referred_by',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
255,
['identity' => true, 'nullable' => true],
'Referred By'
)->setComment("Id of the customer that sent the Referral code");
$setup->getConnection()->createTable($table);
$setup->endSetup();
}
}
ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set
– Mirko Rapisarda
Mar 20 at 9:33
1
@magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong
– Prathap Gunasekaran
Mar 20 at 9:36
@MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.
– Prathap Gunasekaran
Mar 20 at 9:37
@PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.
– magefms
Mar 20 at 9:40
1
@PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column
– Mirko Rapisarda
Mar 20 at 9:40
add a comment |
You can use InstallSchema
Script to do that. Kindly refer below code:
<?php
namespace vendormoduleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkDBDdlTable;
class InstallSchema implements InstallSchemaInterface
{
/**
* {@inheritdoc}
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$table = $setup->getConnection()->newTable(
$setup->getTable('customer_entity')
)->addColumn(
'referred_by',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
255,
['identity' => true, 'nullable' => true],
'Referred By'
)->setComment("Id of the customer that sent the Referral code");
$setup->getConnection()->createTable($table);
$setup->endSetup();
}
}
ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set
– Mirko Rapisarda
Mar 20 at 9:33
1
@magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong
– Prathap Gunasekaran
Mar 20 at 9:36
@MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.
– Prathap Gunasekaran
Mar 20 at 9:37
@PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.
– magefms
Mar 20 at 9:40
1
@PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column
– Mirko Rapisarda
Mar 20 at 9:40
add a comment |
You can use InstallSchema
Script to do that. Kindly refer below code:
<?php
namespace vendormoduleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkDBDdlTable;
class InstallSchema implements InstallSchemaInterface
{
/**
* {@inheritdoc}
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$table = $setup->getConnection()->newTable(
$setup->getTable('customer_entity')
)->addColumn(
'referred_by',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
255,
['identity' => true, 'nullable' => true],
'Referred By'
)->setComment("Id of the customer that sent the Referral code");
$setup->getConnection()->createTable($table);
$setup->endSetup();
}
}
You can use InstallSchema
Script to do that. Kindly refer below code:
<?php
namespace vendormoduleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkDBDdlTable;
class InstallSchema implements InstallSchemaInterface
{
/**
* {@inheritdoc}
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$table = $setup->getConnection()->newTable(
$setup->getTable('customer_entity')
)->addColumn(
'referred_by',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
255,
['identity' => true, 'nullable' => true],
'Referred By'
)->setComment("Id of the customer that sent the Referral code");
$setup->getConnection()->createTable($table);
$setup->endSetup();
}
}
answered Mar 20 at 9:18
magefmsmagefms
1,9622425
1,9622425
ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set
– Mirko Rapisarda
Mar 20 at 9:33
1
@magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong
– Prathap Gunasekaran
Mar 20 at 9:36
@MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.
– Prathap Gunasekaran
Mar 20 at 9:37
@PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.
– magefms
Mar 20 at 9:40
1
@PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column
– Mirko Rapisarda
Mar 20 at 9:40
add a comment |
ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set
– Mirko Rapisarda
Mar 20 at 9:33
1
@magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong
– Prathap Gunasekaran
Mar 20 at 9:36
@MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.
– Prathap Gunasekaran
Mar 20 at 9:37
@PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.
– magefms
Mar 20 at 9:40
1
@PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column
– Mirko Rapisarda
Mar 20 at 9:40
ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set
– Mirko Rapisarda
Mar 20 at 9:33
ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set
– Mirko Rapisarda
Mar 20 at 9:33
1
1
@magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong
– Prathap Gunasekaran
Mar 20 at 9:36
@magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong
– Prathap Gunasekaran
Mar 20 at 9:36
@MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.
– Prathap Gunasekaran
Mar 20 at 9:37
@MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.
– Prathap Gunasekaran
Mar 20 at 9:37
@PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.
– magefms
Mar 20 at 9:40
@PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.
– magefms
Mar 20 at 9:40
1
1
@PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column
– Mirko Rapisarda
Mar 20 at 9:40
@PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column
– Mirko Rapisarda
Mar 20 at 9:40
add a comment |
Create new customer custom attribute for referral_code while installing referral module. here is a link to follow how to add custom attribute in customer section.
https://www.mageplaza.com/magento-2-module-development/magento-2-add-customer-attribute-programmatically.html
you can fetch custom attribute value from customer object using below code.
$customer->getCustomAttribute('FIELD_NAME')->getValue();
replace FIELD_NAME by your custom attribute name
but in this way I lost the possibility to add thereferenced_by
field as a foreign key
– Mirko Rapisarda
Mar 20 at 9:37
add a comment |
Create new customer custom attribute for referral_code while installing referral module. here is a link to follow how to add custom attribute in customer section.
https://www.mageplaza.com/magento-2-module-development/magento-2-add-customer-attribute-programmatically.html
you can fetch custom attribute value from customer object using below code.
$customer->getCustomAttribute('FIELD_NAME')->getValue();
replace FIELD_NAME by your custom attribute name
but in this way I lost the possibility to add thereferenced_by
field as a foreign key
– Mirko Rapisarda
Mar 20 at 9:37
add a comment |
Create new customer custom attribute for referral_code while installing referral module. here is a link to follow how to add custom attribute in customer section.
https://www.mageplaza.com/magento-2-module-development/magento-2-add-customer-attribute-programmatically.html
you can fetch custom attribute value from customer object using below code.
$customer->getCustomAttribute('FIELD_NAME')->getValue();
replace FIELD_NAME by your custom attribute name
Create new customer custom attribute for referral_code while installing referral module. here is a link to follow how to add custom attribute in customer section.
https://www.mageplaza.com/magento-2-module-development/magento-2-add-customer-attribute-programmatically.html
you can fetch custom attribute value from customer object using below code.
$customer->getCustomAttribute('FIELD_NAME')->getValue();
replace FIELD_NAME by your custom attribute name
answered Mar 20 at 9:33
Kruti AparnathiKruti Aparnathi
463
463
but in this way I lost the possibility to add thereferenced_by
field as a foreign key
– Mirko Rapisarda
Mar 20 at 9:37
add a comment |
but in this way I lost the possibility to add thereferenced_by
field as a foreign key
– Mirko Rapisarda
Mar 20 at 9:37
but in this way I lost the possibility to add the
referenced_by
field as a foreign key– Mirko Rapisarda
Mar 20 at 9:37
but in this way I lost the possibility to add the
referenced_by
field as a foreign key– Mirko Rapisarda
Mar 20 at 9:37
add a comment |
Mirko Rapisarda is a new contributor. Be nice, and check out our Code of Conduct.
Mirko Rapisarda is a new contributor. Be nice, and check out our Code of Conduct.
Mirko Rapisarda is a new contributor. Be nice, and check out our Code of Conduct.
Mirko Rapisarda is a new contributor. Be nice, and check out our Code of Conduct.
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%2f266635%2fmagento-2-3-how-to-add-custom-column-to-customer-entity-table%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