Magento 2.3 : How to create product attribute via declarative schemamain.CRITICAL: Plugin class doesn't...

Cookies - Should the toggles be on?

Find some digits of factorial 17

How do you funnel food off a cutting board?

Intern applicant asking for compensation equivalent to that of permanent employee

Which one of these password policies is more secure?

Writing a character who is going through a civilizing process without overdoing it?

Why has the mole been redefined for 2019?

How should I handle players who ignore the session zero agreement?

Strange Sign on Lab Door

What is the purpose of easy combat scenarios that don't need resource expenditure?

What's a good word to describe a public place that looks like it wouldn't be rough?

Porting Linux to another platform requirements

Using only 1s, make 29 with the minimum number of digits

How to count the characters of jar files by wc

How can I get my players to come to the game session after agreeing to a date?

what does しにみえてる mean?

Advice for a new journal editor

Why do members of Congress in committee hearings ask witnesses the same question multiple times?

Dilemma of explaining to interviewer that he is the reason for declining second interview

Digits in an algebraic irrational number

In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?

How much mayhem could I cause as a sentient fish?

Finding a mistake using Mayer-Vietoris

Why publish a research paper when a blog post or a lecture slide can have more citation count than a journal paper?



Magento 2.3 : How to create product attribute via declarative schema


main.CRITICAL: Plugin class doesn't existMagento 2.1.5 How to create Module which can use Eav functionalities (addAttribute in my case)Magento 2.1 Create a filter in the product grid by new attributeI have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento 2: Add a product to the cart programmaticallyMagento offline custom Payment method with drop down listMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMagento 2.3 Can't view module's front end page output?Magento 2 How to upgrade existing custom customer address attribute?Magento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?













1















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.










share|improve this question





























    1















    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.










    share|improve this question



























      1












      1








      1


      1






      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 10 mins ago









      Prathap Gunasekaran

      665213




      665213










      asked 35 mins ago









      Adarsh ShuklaAdarsh Shukla

      16313




      16313






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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 :)





          share























            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%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









            0














            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 :)





            share




























              0














              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 :)





              share


























                0












                0








                0







                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 :)





                share













                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 :)






                share











                share


                share










                answered 3 mins ago









                Prathap GunasekaranPrathap Gunasekaran

                665213




                665213






























                    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%2f263958%2fmagento-2-3-how-to-create-product-attribute-via-declarative-schema%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

                    “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                    How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                    變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...