0

I wish to add custom field (boolean value select) to customer group form in backend.

I have created below plugin for that, Field is added to form, but its not reflecting value in edit form, neither saving value for new group.

<?php

namespace Vendor\Modulename\Plugin\Customer\Adminhtml\Block\Customer\Group\Edit;

use \Magento\Config\Model\Config\Source\Yesno;

class Form {

    protected $yesno;

    public function __construct (
        Yesno $yesno
    ){
        $this->yesno = $yesno;
    }

    /**
     * Get form HTML
     *
     * @return string
     */
    public function aroundGetFormHtml (
        \Magento\Customer\Block\Adminhtml\Group\Edit\Form $subject,
        \Closure $proceed
    ) {

        $form = $subject->getForm();
        if (is_object($form)) {
            $fieldset = $form->addFieldset('pricegroup', ['legend' => __('Pricegroup')]);
            $fieldset->addField(
                'is_pricegroup',
                'select',
                [
                    'name' => 'is_pricegroup',
                    'label' => __('Is Pricegroup'),
                    'id' => 'is_pricegroup',
                    'title' => __('Is Pricegroup'),
                    'values' => $this->yesno->toOptionArray(),
                    'required' => false,
                ]
            );

            $subject->setForm($form);
        }

        return $proceed();
    }
}

And di.xml is like below

 <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Customer\Block\Adminhtml\Group\Edit\Form">
        <plugin name="pricegroup_column_add"
                type="Vendor\Modulename\Plugin\Customer\Adminhtml\Block\Customer\Group\Edit\Form" sortOrder="1"/>
    </type>
</config>

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.