2

I would like to have a parameter which if selected Yes, the dealers of the webpage aren't able to modify any customer information. If selected No, nothing happens and they can modify anything they desire about the customer.

I have added the parameter in the backend:

enter image description here

The code behind the parameter in: app/code/<vendor>/<module>/etc/adminhtml/system.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="tabId" translate="label" sortOrder="0">
            <label>TabName</label>
        </tab>
    <section id="section_id">

        <tab>gsp</tab>
        <resource>resource</resource>

        <group id="customer">                

            <field id="permission_info_dealer" translate="label" type="select" sortOrder="105"
                   showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Allow dealer edit customer data </label>
                <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
            </field>                

        </group>
    </section>
</system>

So as I said I would like depending on the user role, be able to remove or hide this Edit from

Admin-> Customers -> All Customers

when the Yes is selected:

enter image description here

The Edit button with the xml code:

 <action name="edit">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="type" xsi:type="string">edit</item>
                    <item name="label" xsi:type="string" translate="true">Edit</item>
                    <item name="callback" xsi:type="array">
                        <item name="provider" xsi:type="string">customer_listing.customer_listing.customer_columns_editor</item>
                        <item name="target" xsi:type="string">editSelected</item>
                    </item>
                </item>
            </argument>
        </action>

And I have this code app/code/<vendor>/<module>/Block/Form/Edit.php:

<?php

namespace <vendor>\<module>\Block\Form;


class Edit extends \Magento\Customer\Block\Form\Edit
{
   const PERMISSION_INFO_DEALER = 'gsp_configuration/customer/permission_info_dealer';

    public function canEditInfoDealer()
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $scopeConfig = $objectManager->create('Magento\Framework\App\Config\ScopeConfigInterface');

        return $scopeConfig->getValue(self::PERMISSION_INFO_DEALER, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
    }

    protected function _prepareForm()
    {
        $role = $this->_getRole();
        $gspRole = $this->gspRoleFactory->create()->load($role->getId(), 'role_id');

        $data['permission_info_dealer'] = $gspRole->getData('permission_info_dealer');

        $form = $this->_formFactory->create(
            ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
        );

        $fieldset = $form->addFieldset(
            'gsp_users_index_fieldset',
            ['legend' => __('GSP: Additional Permissions'), 'collapsable' => true]
        );

        $yesno = $this->yesnoFactory->create()->toOptionArray();

        $fieldset->addField(
        'gsp_permission_info_dealer',
        'select', [
        'name' => 'gsp_permission_info_dealer',
        'label' => __('Allow dealer edit customer data'),
        'title' => __('Allow dealer edit customer data'),
        'values' => $yesno,
        'value' => isset($data['permission_info_dealer']) ? $data['permission_info_dealer'] : 1
        ]
        );

        $this->setForm($form);

        return $this;
    }

    protected function _getRole()
    {
        return $this->_coreRegistry->registry('current_role');
    }
}

0

Your Answer

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