1

I have created customer custom attributes using install data, and I want to display this attributes in the Magento admin customer view/personnel information section, next to customer group, Need to achieve this

In this picture I have edited my core files and shows the customer group again , similarly I need to show the custom customer attributes, Is there any method of doing it with out editing core files.

My install data file shows below and i also required this fields in the API

$eavSetup->addAttribute(
            \Magento\Customer\Model\Customer::ENTITY,
            'customer_amnt',
            [
                'type'                  => 'varchar',
                'label'                 => 'Customer Amount',
                'input'                 => 'text',
                'required'              => false,
                'visible'               => true,
                'user_defined'          => true,
                'position'              => 999,
                'system'                => 0,
                'visible_on_front'      => true,
                'is_used_in_grid'       => true,
                'is_visible_in_grid'    => true,
                'is_filterable_in_grid' => true,
            ]
        );

        $eavSetup->addAttributeToSet(
            CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER,
            CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
            null,
            'customer_amnt');

        $customerCLV = $this->eavConfig->getAttribute(Customer::ENTITY, 'customer_amnt');
        $customerCLV->setData(
            'used_in_forms',
            ['adminhtml_checkout',
                'adminhtml_customer',
                'adminhtml_customer_address',
                'customer_account_edit',
                'customer_address_edit',
                'customer_register_address']
        );
        $customerCLV->save();
2

Note: I have checked the code in Magento version 2.2.4.

The Personal Information section under the Customer View tab comes from the /vendor/magento/module-customer/view/adminhtml/templates/tab/view/personal_info.phtml file, which gets the required information from it's block file /vendor/magento/module-customer/Block/Adminhtml/Edit/Tab/View/PersonalInfo.php.

If you want to show some information in this section, you need to override the block file first and write the custom function to return the required data.

Below is an example:

I wanted to show gender information. So content added to my phtml file:

<tr>
    <th><?= $block->escapeHtml(__('Account Lock Expp:')) ?></th>
    <td><?= $block->escapeHtml($block->getGenderInfo()) ?></td>
</tr>

and the content of my custom function:

public function getGenderInfo() {
    return $this->getCustomer()->getGender();
}

I hope it is clear now.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.