3

Bonjour !

I try to edit some custom customer group fields in my Magento 2.3 but I don't know how to start.

I already have added some columns and displayed it in admin back-office with a module.

view/adminhtml/ui_component/customer_group_listing.xml

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="customer_group_columns">
        <column name="siret">
            <settings>
                <filter>text</filter>
                <label translate="true">SIRET</label>
            </settings>
        </column>
        <column name="code_client">
            <settings>
                <filter>text</filter>
                <label translate="true">Code client</label>
            </settings>
        </column>
        <column name="zipcode">
            <settings>
                <filter>text</filter>
                <label translate="true">Code postal</label>
            </settings>
        </column>
    </columns>
</listing>

But now I want on the update form to have the capability to modify this fields (siret, code_client, zipcode)

Screenshot of the BO

For exemple, here I only have 2 fields but I want to add for example the zipcode in the form.

Screenshot of the update form

Thanks ;)


Thanks for the help.

I extend my module and now I try to display the field SIRET, and I modify the file Form.php.

The field is display but the field is not filled.

enter image description here

I try to modify the Save.php, Group.php

//Save.php

 $siret = $this->getRequest()->getParam('SIRET');
 $customerGroup->setSiret(!empty($siret) ? $siret : null);

//Group.php

public function getSiret()
{
    return $this->_get(self::SIRET);
}

public function setSiret($siret)
{
    return $this->setData(self::SIRET, $siret);
}

// GroupRepository.php

    public function getById($id)
{
    $groupModel = $this->groupRegistry->retrieve($id);
    $groupDataObject = $this->groupDataFactory->create()
        ->setId($groupModel->getId())
        ->setCode($groupModel->getCode())
        ->setTaxClassId($groupModel->getTaxClassId())
        ->setSiret($groupModel->getSiret());
    return $groupDataObject;
}

I add setSiret() everywhere in the file where we had setTaxClassId().

But it doesn't work, can someone help me ?

Thank you.

2
  • Have you solved the loading of customer fields in edit page?
    – steve lou
    Commented Jan 15, 2020 at 20:49
  • I am facing issue on adding custom filter in Customer Group . Could you please help me out on adding custom filter in Customer Group. Thanks
    – Joseph
    Commented Sep 3, 2020 at 17:23

2 Answers 2

0

I'm also, working on a similar solution. We have to extend the magento/module-customer.

Check this two files: Block/Adminhtml/Group/Edit/Form.php Controller/Adminhtml/Group/Save.php

In the form you add:

$fieldset->addField(
            'CustomField',
            'text',
            [
                'name' => 'fieldname',
                'label' => __('CustomField'),
                'title' => __('CustomField'),
                'class' => 'validate-number'


            ]
        );

And in the Save.php after these two lines:

$customerGroup->setCode(!empty($customerGroupCode) ? $customerGroupCode : null);
$customerGroup->setTaxClassId($taxClass);

Your save your custom field.

$CustomField= $this->getRequest()->getParam('CustomField');
$customerGroup->setCustomField($CustomField?:0);

Not sure if you have to also override these:

Model/Data/Group.php

Model/ResourceModel/GroupRepository.php To create the method "setCustomField"

Of course, you need to extend it in your own module.

(This is my first answer in this forum, so forgive-me if is something missing)

0

You have to extend Magento\Customer\Block\Adminhtml\Group\Edit\Form class to your custom module.

Try like below :

app\code\Namespace\Modulename\Block\Adminhtml\Group\Edit\Form

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Namespace\Modulename\Block\Adminhtml\Group\Edit;

use Magento\Customer\Controller\RegistryConstants;

/**
 * Adminhtml customer groups edit form
 */
class Form extends \Magento\Customer\Block\Adminhtml\Group\Edit\Form
{
    //Add new field using $fieldset->addField()

}

I hope it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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