Magento 2.3 : How to create product attribute via declarative schema
How to create product attribute in Magento 2.3 via declarative schema. I have tried below code but the input element is not visible on the form.
<?php
namespace RokanthemesUpdatesSetupPatchData;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoFrameworkSetupPatchPatchVersionInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoCustomerModelCustomer;
use MagentoCustomerSetupCustomerSetupFactory;
use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
use MagentoFrameworkDBDdlTable;
class AddAttributes implements DataPatchInterface
{
protected $_moduleDataSetup;
protected $_customerSetupFactory;
protected $_attributeSetFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CustomerSetupFactory $customerSetupFactory,
AttributeSetFactory $attributeSetFactory
)
{
$this->_moduleDataSetup = $moduleDataSetup;
$this->_customerSetupFactory = $customerSetupFactory;
$this->_attributeSetFactory = $attributeSetFactory;
}
public function apply()
{
$customerSetup = $this->_customerSetupFactory->create(['setup' => $this->_moduleDataSetup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY);
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
$attributeSet = $this->_attributeSetFactory->create();
$attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(Customer::ENTITY, 'news_from_date', array(
'type' => Table::TYPE_DATE,
'label' => 'New from date',
'input' => 'date',
'required' => 1,
'type' => 'static',
'visible' => true
));
}
public function getAliases()
{
return ;
}
public static function getDependencies()
{
return [
];
}
}
Thanks for the help.
magento2 declarative-schema
add a comment |
How to create product attribute in Magento 2.3 via declarative schema. I have tried below code but the input element is not visible on the form.
<?php
namespace RokanthemesUpdatesSetupPatchData;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoFrameworkSetupPatchPatchVersionInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoCustomerModelCustomer;
use MagentoCustomerSetupCustomerSetupFactory;
use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
use MagentoFrameworkDBDdlTable;
class AddAttributes implements DataPatchInterface
{
protected $_moduleDataSetup;
protected $_customerSetupFactory;
protected $_attributeSetFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CustomerSetupFactory $customerSetupFactory,
AttributeSetFactory $attributeSetFactory
)
{
$this->_moduleDataSetup = $moduleDataSetup;
$this->_customerSetupFactory = $customerSetupFactory;
$this->_attributeSetFactory = $attributeSetFactory;
}
public function apply()
{
$customerSetup = $this->_customerSetupFactory->create(['setup' => $this->_moduleDataSetup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY);
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
$attributeSet = $this->_attributeSetFactory->create();
$attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(Customer::ENTITY, 'news_from_date', array(
'type' => Table::TYPE_DATE,
'label' => 'New from date',
'input' => 'date',
'required' => 1,
'type' => 'static',
'visible' => true
));
}
public function getAliases()
{
return ;
}
public static function getDependencies()
{
return [
];
}
}
Thanks for the help.
magento2 declarative-schema
add a comment |
How to create product attribute in Magento 2.3 via declarative schema. I have tried below code but the input element is not visible on the form.
<?php
namespace RokanthemesUpdatesSetupPatchData;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoFrameworkSetupPatchPatchVersionInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoCustomerModelCustomer;
use MagentoCustomerSetupCustomerSetupFactory;
use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
use MagentoFrameworkDBDdlTable;
class AddAttributes implements DataPatchInterface
{
protected $_moduleDataSetup;
protected $_customerSetupFactory;
protected $_attributeSetFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CustomerSetupFactory $customerSetupFactory,
AttributeSetFactory $attributeSetFactory
)
{
$this->_moduleDataSetup = $moduleDataSetup;
$this->_customerSetupFactory = $customerSetupFactory;
$this->_attributeSetFactory = $attributeSetFactory;
}
public function apply()
{
$customerSetup = $this->_customerSetupFactory->create(['setup' => $this->_moduleDataSetup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY);
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
$attributeSet = $this->_attributeSetFactory->create();
$attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(Customer::ENTITY, 'news_from_date', array(
'type' => Table::TYPE_DATE,
'label' => 'New from date',
'input' => 'date',
'required' => 1,
'type' => 'static',
'visible' => true
));
}
public function getAliases()
{
return ;
}
public static function getDependencies()
{
return [
];
}
}
Thanks for the help.
magento2 declarative-schema
How to create product attribute in Magento 2.3 via declarative schema. I have tried below code but the input element is not visible on the form.
<?php
namespace RokanthemesUpdatesSetupPatchData;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoFrameworkSetupPatchPatchVersionInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoCustomerModelCustomer;
use MagentoCustomerSetupCustomerSetupFactory;
use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
use MagentoFrameworkDBDdlTable;
class AddAttributes implements DataPatchInterface
{
protected $_moduleDataSetup;
protected $_customerSetupFactory;
protected $_attributeSetFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CustomerSetupFactory $customerSetupFactory,
AttributeSetFactory $attributeSetFactory
)
{
$this->_moduleDataSetup = $moduleDataSetup;
$this->_customerSetupFactory = $customerSetupFactory;
$this->_attributeSetFactory = $attributeSetFactory;
}
public function apply()
{
$customerSetup = $this->_customerSetupFactory->create(['setup' => $this->_moduleDataSetup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY);
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
$attributeSet = $this->_attributeSetFactory->create();
$attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(Customer::ENTITY, 'news_from_date', array(
'type' => Table::TYPE_DATE,
'label' => 'New from date',
'input' => 'date',
'required' => 1,
'type' => 'static',
'visible' => true
));
}
public function getAliases()
{
return ;
}
public static function getDependencies()
{
return [
];
}
}
Thanks for the help.
magento2 declarative-schema
magento2 declarative-schema
edited 24 mins ago
Prathap Gunasekaran
667213
667213
asked 49 mins ago
Adarsh ShuklaAdarsh Shukla
16313
16313
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try this,
<?php
namespace Vendor_nameModuel_nameSetupPatchData;
use MagentoCatalogSetupCategorySetup;
use MagentoCatalogSetupCategorySetupFactory;
use MagentoFrameworkAppResourceConnection;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoFrameworkSetupPatchPatchVersionInterface;
class AddAttributes implements DataPatchInterface, PatchVersionInterface{
private $moduleDataSetup;
private $categorySetupFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CategorySetupFactory $categorySetupFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->categorySetupFactory = $categorySetupFactory;
}
public function apply()
{
/** @var CategorySetup $categorySetup */
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
$categorySetup->addAttribute(
MagentoCatalogModelProduct::ENTITY,
'custom_layout',
[
'type' => 'varchar',
'label' => 'New Layout',
'input' => 'date',
'required' => false,
'sort_order' => 50,
'group' => 'General',
'is_used_in_grid' => true,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false
]
);
}}
NOTE : Not tested this code. Please try it and let me know :)
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%2f263958%2fmagento-2-3-how-to-create-product-attribute-via-declarative-schema%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
Try this,
<?php
namespace Vendor_nameModuel_nameSetupPatchData;
use MagentoCatalogSetupCategorySetup;
use MagentoCatalogSetupCategorySetupFactory;
use MagentoFrameworkAppResourceConnection;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoFrameworkSetupPatchPatchVersionInterface;
class AddAttributes implements DataPatchInterface, PatchVersionInterface{
private $moduleDataSetup;
private $categorySetupFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CategorySetupFactory $categorySetupFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->categorySetupFactory = $categorySetupFactory;
}
public function apply()
{
/** @var CategorySetup $categorySetup */
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
$categorySetup->addAttribute(
MagentoCatalogModelProduct::ENTITY,
'custom_layout',
[
'type' => 'varchar',
'label' => 'New Layout',
'input' => 'date',
'required' => false,
'sort_order' => 50,
'group' => 'General',
'is_used_in_grid' => true,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false
]
);
}}
NOTE : Not tested this code. Please try it and let me know :)
add a comment |
Try this,
<?php
namespace Vendor_nameModuel_nameSetupPatchData;
use MagentoCatalogSetupCategorySetup;
use MagentoCatalogSetupCategorySetupFactory;
use MagentoFrameworkAppResourceConnection;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoFrameworkSetupPatchPatchVersionInterface;
class AddAttributes implements DataPatchInterface, PatchVersionInterface{
private $moduleDataSetup;
private $categorySetupFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CategorySetupFactory $categorySetupFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->categorySetupFactory = $categorySetupFactory;
}
public function apply()
{
/** @var CategorySetup $categorySetup */
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
$categorySetup->addAttribute(
MagentoCatalogModelProduct::ENTITY,
'custom_layout',
[
'type' => 'varchar',
'label' => 'New Layout',
'input' => 'date',
'required' => false,
'sort_order' => 50,
'group' => 'General',
'is_used_in_grid' => true,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false
]
);
}}
NOTE : Not tested this code. Please try it and let me know :)
add a comment |
Try this,
<?php
namespace Vendor_nameModuel_nameSetupPatchData;
use MagentoCatalogSetupCategorySetup;
use MagentoCatalogSetupCategorySetupFactory;
use MagentoFrameworkAppResourceConnection;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoFrameworkSetupPatchPatchVersionInterface;
class AddAttributes implements DataPatchInterface, PatchVersionInterface{
private $moduleDataSetup;
private $categorySetupFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CategorySetupFactory $categorySetupFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->categorySetupFactory = $categorySetupFactory;
}
public function apply()
{
/** @var CategorySetup $categorySetup */
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
$categorySetup->addAttribute(
MagentoCatalogModelProduct::ENTITY,
'custom_layout',
[
'type' => 'varchar',
'label' => 'New Layout',
'input' => 'date',
'required' => false,
'sort_order' => 50,
'group' => 'General',
'is_used_in_grid' => true,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false
]
);
}}
NOTE : Not tested this code. Please try it and let me know :)
Try this,
<?php
namespace Vendor_nameModuel_nameSetupPatchData;
use MagentoCatalogSetupCategorySetup;
use MagentoCatalogSetupCategorySetupFactory;
use MagentoFrameworkAppResourceConnection;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoFrameworkSetupPatchPatchVersionInterface;
class AddAttributes implements DataPatchInterface, PatchVersionInterface{
private $moduleDataSetup;
private $categorySetupFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CategorySetupFactory $categorySetupFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->categorySetupFactory = $categorySetupFactory;
}
public function apply()
{
/** @var CategorySetup $categorySetup */
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
$categorySetup->addAttribute(
MagentoCatalogModelProduct::ENTITY,
'custom_layout',
[
'type' => 'varchar',
'label' => 'New Layout',
'input' => 'date',
'required' => false,
'sort_order' => 50,
'group' => 'General',
'is_used_in_grid' => true,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false
]
);
}}
NOTE : Not tested this code. Please try it and let me know :)
answered 17 mins ago
Prathap GunasekaranPrathap Gunasekaran
667213
667213
add a comment |
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%2f263958%2fmagento-2-3-how-to-create-product-attribute-via-declarative-schema%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