Magento2 में पंजीकरण पृष्ठ पर नए फ़ील्ड कैसे जोड़ें?


जवाबों:


6

यदि आप ग्राहक के खाते में नया फ़ील्ड जोड़ना चाहते हैं, तो आपको अपने कस्टम थीम में register.phtml को ओवरराइड करना होगा ।

कस्टम थीम बनाएं, फिर निम्नलिखित पथ में register.phtml बनाएं

एप्लिकेशन / डिजाइन / दृश्यपटल / विक्रेता / विषय / Magento_Customer / टेम्पलेट्स / प्रपत्र / register.phtml

फिर, कोड - कोड, मॉड्यूल-ग्राहक / दृश्य / फ्रंटएंड / टेम्प्लेट / फॉर्म / register.phtml से ऊपर की फ़ाइल में पेस्ट करें।

फिर, अपना कस्टम फ़ील्ड जोड़ें :

<div class="field required">
    <label for="custom_field" class="label"><span><?= __('CustomField') ?></span></label>
    <div class="control">
        <input type="text" name="custom_field" id="custom_field" value="<?= $block->escapeHtml($block->getFormData()->getCustomField()) ?>" title="<?= __('CustomField') ?>" class="input-text" data-validate="{required:true, 'validate-phoneStrict':true}">
    </div>
</div>

इससे पहले कि आप ऐसा करें, आपको डेटाबेस को संग्रहीत करने के लिए अपने custom_field के लिए ग्राहक विशेषता बनाने की आवश्यकता है ।

ग्राहक विशेषता बनाएँ:

कस्टम मॉड्यूल बनाने के लिए आपको एक कस्टम मॉड्यूल बनाने की आवश्यकता है

निम्नलिखित पथ Vendor \ Module \ Setup में InstallData.php बनाएँ

InstallData.php

इस नीचे दिए गए कोड में मैंने custom_field विशेषता जोड़ी है।

  <?php
  /**
   * Copyright © 2016 Magento. All rights reserved.
   * See COPYING.txt for license details.
   */
  namespace Vendor\Module\Setup;

  use Magento\Customer\Setup\CustomerSetupFactory;
  use Magento\Customer\Model\Customer;
  use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
  use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
  use Magento\Framework\Setup\InstallDataInterface;
  use Magento\Framework\Setup\ModuleContextInterface;
  use Magento\Framework\Setup\ModuleDataSetupInterface;

  /**
   * Install data
   * @codeCoverageIgnore
   */
  class InstallData implements InstallDataInterface
  {

      /**
       * CustomerSetupFactory
       * @var CustomerSetupFactory
       */
      protected $customerSetupFactory;

      /**
       * $attributeSetFactory
       * @var AttributeSetFactory
       */
      private $attributeSetFactory;

      /**
       * initiate object
       * @param CustomerSetupFactory $customerSetupFactory
       * @param AttributeSetFactory $attributeSetFactory
       */
      public function __construct(
          CustomerSetupFactory $customerSetupFactory,
          AttributeSetFactory $attributeSetFactory
      )
      {
          $this->customerSetupFactory = $customerSetupFactory;
          $this->attributeSetFactory = $attributeSetFactory;
      }

      /**
       * install data method
       * @param ModuleDataSetupInterface $setup
       * @param ModuleContextInterface $context
       */
      public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
      {

          /** @var CustomerSetup $customerSetup */
          $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

          $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
          $attributeSetId = $customerEntity->getDefaultAttributeSetId();

          /** @var $attributeSet AttributeSet */
          $attributeSet = $this->attributeSetFactory->create();
          $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
          /**
           * customer registration form default field mobile number
           */
          $customerSetup->addAttribute(Customer::ENTITY, 'custom_field', [
              'type' => 'varchar',
              'label' => 'Custom Field',
              'input' => 'text',
              'required' => true,
              'visible' => true,
              'user_defined' => true,
              'sort_order' => 1000,
              'position' => 1000,
              'system' => 0,
          ]);
          //add attribute to attribute set
          $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'mobile_number')
              ->addData([
                  'attribute_set_id' => $attributeSetId,
                  'attribute_group_id' => $attributeGroupId,
                  'used_in_forms' => ['adminhtml_customer', 'customer_account_create'],
              ]);

          $attribute->save();


      }
  }

उसके बाद कमांड के नीचे चलाएँ:

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento cache:clean

आपको पंजीकरण फॉर्म में अपना कस्टम दर्ज करना होगा।

अगर आपके पास समस्या है तो मुझे बताएं।


4
किस तालिका में डेटा सहेजें?
देवीदास

7

आपको एक मॉड्यूल बनाने की आवश्यकता है और यहां है installData.php:

namespace Barcode\Unique\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface
{
    /**
     * Customer setup factory
     *
     * @var \Magento\Customer\Setup\CustomerSetupFactory
     */
    private $customerSetupFactory;
    /**
     * Init
     *
     * @param \Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory
     */
    public function __construct(\Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory)
    {
        $this->customerSetupFactory = $customerSetupFactory;
    }
    /**
     * Installs DB schema for a module
     *
     * @param ModuleDataSetupInterface $setup
     * @param ModuleContextInterface $context
     * @return void
     */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {

        $installer = $setup;
        $installer->startSetup();

        $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
        $entityTypeId = $customerSetup->getEntityTypeId(\Magento\Customer\Model\Customer::ENTITY);

        $customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, "barcode_unique");

        $customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, "barcode_unique",  array(
            "type"     => "varchar",
            "backend"  => "",
            "label"    => "Barcode",
            "input"    => "text",
            "source"   => "",
            "visible"  => true,
            "required" => false,
            "default" => "",
            "frontend" => "",
            "unique"     => false,
            "note"       => ""

        ));

        $barcode_unique   = $customerSetup->getAttribute(\Magento\Customer\Model\Customer::ENTITY, "barcode_unique");

        $barcode_unique = $customerSetup->getEavConfig()->getAttribute(\Magento\Customer\Model\Customer::ENTITY, 'barcode_unique');

      $used_in_forms[]="adminhtml_customer";
        $used_in_forms[]="checkout_register";
        $used_in_forms[]="customer_account_create";
        $used_in_forms[]="customer_account_edit";
        $used_in_forms[]="adminhtml_checkout";

        $barcode_unique->setData("used_in_forms", $used_in_forms)
            ->setData("is_used_for_customer_segment", true)
            ->setData("is_system", 0)
            ->setData("is_user_defined", 1)
            ->setData("is_visible", 1)
            ->setData("sort_order", 1002);

        $barcode_unique->save();

        $installer->endSetup();
    }
}

यह फ़ील्ड बनाएगा और आप phtml (यानी: extrainfocustomer.phtml) फ़ाइल में कॉल कर सकते हैं।

आप इन 2 URL: IBNAB और SASHAS से मदद कर सकते हैं

मुझे आशा है कि यह आपकी मदद करेगा।


0

आप Magento2 में पंजीकरण पृष्ठ पर कस्टम फ़ील्ड बनाने के लिए नीचे दिए गए लिंक का उल्लेख कर सकते हैं-

https://github.com/jainmegha5395/custom-fields

यह कस्टम मॉड्यूल कस्टम फॉर्म और पंजीकरण फॉर्म पर विशेषता जोड़ देगा। यह विशेषता Magento 2 व्यवस्थापक में ग्राहक प्रपत्र को जोड़ने या संपादित करने में भी दिखाई देगी।


0

आप वास्तव में Magento 2 खाता पीढ़ी पर पूरा पता पूछ सकते हैं रजिस्टर ब्लॉक में show_address_fields को सही पर सेट करें - फिर यह कंपनी के लिए (अन्य के अलावा) भी पूछता है।

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.