3

I tried this code but it's not working

app\code\Customer\Attribute\Setup\Installdata.php

    $customerSetup->addAttribute(Customer::ENTITY, 'customer_type', [

        'type'          => 'int',
        'label'         => 'Corporation Or Proproetorship',
        'input'         => 'select',
        'source'        => 'Magento\Eav\Model\Entity\Attribute\Source\Table',
        'required'      => false,
        'visible'       => true,
        'system'        => false,
        'position'      => 210,
        'system' => false,
        'option'         => ['values' => ['Corporation', 'Proproetorship']],
    ]);

    $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'customer_type')
    ->addData(['used_in_forms' => [
            'adminhtml_customer',
            'adminhtml_checkout',
            'customer_account_create',
            'customer_account_edit'
]]);

    $attribute->save();

and

app\code\Custommodule\Wholesale\view\frontend\templates\form\wholesale.phtml

<div class="field">
     <label for="customer_type" class="label"><span><?php /* @escapeNotVerified */ echo __('Corporation Or Proprietorship') ?></span></label>
     <div class="control"> 
     <select id="customer_type" name="customer_type" title="<?php echo $block->escapeHtml(__('Corporation or Proproetorship')) ?>" class="validate-select">
            <option disabled selected value> -- select an option -- </option>
              <option value="0">Corporation</option>
              <option value="1">Proprietorship</option>
            </select>
    </div>
</div>

enter image description here

  • You can also add a text field in database and create select option on front PHTML – Pawan Sep 4 '18 at 3:59
  • what issue you are getting, field is created in database ? Or not saving form front ? Please be more descriptive. – Pawan Sep 4 '18 at 4:00
  • 1
    just check with template hint path is your registration form coming from app\code\Custommodule\Wholesale\view\frontend\templates\form\wholesale.phtml ? – Ansar Husain Sep 4 '18 at 4:11
  • Can you explain me now? – gill Sep 4 '18 at 12:51

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.