0

InstallData.php

<?php
namespace Pulsestorm\HelloWorldMVVM\Setup;
use Magento\Framework\Module\Setup\Migration;
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->addAttribute(\Magento\Customer\Model\Customer::ENTITY, "regulation",  array(
        "type"     => "int",
        "backend"  => "",
        "label"    => "Regulation",
        "input"    => "text",
        "source"   => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
        "visible"  => true,
        "required" => true,
        "default" => "",
        "frontend" => "",
        "unique"     => false,
        "note"       => ""

    ));

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

    $regulation = $customerSetup->getEavConfig()->getAttribute(\Magento\Customer\Model\Customer::ENTITY, 'regulation');
    $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";
    $regulation->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", 100);
    $regulation->save();

    $installer->endSetup();
}
}

customer_account_create.xml

<?xml version="1.0"?><page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceContainer name="form.additional.info">
        <block class="Magento\Framework\View\Element\Template" name="my_form_additional_info_customer" template="Pulsestorm_HelloWorldMVVM::customer.phtml"/>
    </referenceContainer>
</body></page>

customer.phtml

<fieldset class="fieldset create account" >
    <legend class="legend"><span><?php /* @escapeNotVerified */
            echo __('Additional Information') ?></span></legend>

<p>
<div class="field regulation required">
    <label for="regulation" class="label"><span><?php /* @escapeNotVerified */
            echo __('Regulation') ?></span></label>
    <div class="control">
        <input type="text" name="regulation" id="photo" title="<?php /* @escapeNotVerified */
        echo __('Regulation') ?>" class="input-text" data-validate="{required:false}">
    </div>
</div>
</p></fieldset>

I need to know how can i insert value of regulation in database ? the field (regulation) is not saving in database. In which table this field will be saved ?

  • U r creating new module or adding 1 customer attribute within Standard Magento Registration Form? – Jackson Sep 20 '16 at 8:53
  • yes, I am creating new module. – Ramkishan Suthar Sep 20 '16 at 8:54
  • i need to know where this attribute has been saved in database @Ankit. After that i have no idea where and how to send this value. plz help – Ramkishan Suthar Sep 20 '16 at 9:04
  • So you are extending Customer Registration form & need to store value in NOT separate table, but default Magento Tables? – Jackson Sep 20 '16 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.