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

Why zero tolerance on nudity in space?

Word or phrase for showing great skill at something WITHOUT formal training in it

Why would space fleets be aligned?

Can you tell from a blurry photo if focus was too close or too far?

Why is oil called more viscous than water when we slip on oil more than we do on water

Can we use the stored gravitational potential energy of a building to produce power?

My cat mixes up the floors in my building. How can I help him?

Eww, those bytes are gross

Why is working on the same position for more than 15 years not a red flag?

what does しにみえてる mean?

Publishing research using outdated methods

How can I deliver in-universe written lore to players without it being dry exposition?

Caruana vs Carlsen game 10 (WCC) why not 18...Nxb6?

Can I write a book of my D&D game?

Can a person refuse a presidential pardon?

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

Why has the mole been redefined for 2019?

One Half of Ten; A Riddle

How do you funnel food off a cutting board?

Do authors have to be politically correct in article-writing?

How to say "Brexit" in Latin?

Why did the villain in the first Men in Black movie care about Earth's Cockroaches?

How to limit sight distance to 1 km

How would an AI self awareness kill switch work?



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 50 mins ago









      Prathap Gunasekaran

      667213




      667213










      asked 1 hour 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|improve this answer























            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|improve this answer




























              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|improve this answer


























                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|improve this answer













                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|improve this answer












                share|improve this answer



                share|improve this answer










                answered 43 mins ago









                Prathap GunasekaranPrathap Gunasekaran

                667213




                667213






























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

                    夢乃愛華...