禁用模块后,Magento2模块字段在管理员中仍然可见

时间:2019-07-06 09:31:00

标签: module magento2 uninstall

我在尝试禁用Magento2模块时遇到问题,导致自定义值在客户编辑页面中仍然可见

我想知道我该怎么做才能完全摆脱Magento2系统中的模块及其数据。

Magento版本:2.3.2
PHP版本:7.2.19


通过以下方式安装了自定义(自己的)Magento2模块:

  • 复制代码:app / code / VENDOR / MODULE
  • 运行:magento模块:启用VENDOR_MODULE
  • 运行magento设置:升级

此模块创建了两个Customer EAV属性,这些属性正确显示在客户编辑表单中。 我能够成功填充/保存/更新值。


我正在禁用该模块:

  • 运行:magento模块:禁用VENDOR_MODULE
  • 运行magento设置:升级
  • 完全删除app / code / VENDOR / MODULE目录

当我导航回到客户编辑页面时,我仍然可以看到属性,这些属性可见并填充有以前输入的数据

这时我尝试了以下方法:

  • 手动删除setup_module中的条目。
  • 包括一个卸载类。
  • magento cache:clean和&magento setup:di:compile的组合。

附加课程:

InstallData.php

namespace VENDOR\MODULE\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetupFactory;

class InstallData implements InstallDataInterface {

    private $customerSetupFactory;

    /**
     * Constructor
     *
     * @param \Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory
     */
    public function __construct(CustomerSetupFactory $customerSetupFactory) {
        $this->customerSetupFactory = $customerSetupFactory;
    }

    /**
     * {@inheritdoc}
     */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
        $this->installModule1($setup, $context);
        $this->installModule2($setup, $context);
    }

    private function installModule1(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
        $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

        $customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, 'module1', [
            'type' => 'varchar',
            'label' => 'Module1 label',
            'input' => 'text',
            'source' => '',
            'required' => false,
            'visible' => true,
            'position' => 500,
            'system' => false,
            'backend' => ''
        ]);
        
        $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'module1')
        ->addData(['used_in_forms' => [
                'adminhtml_customer',
                'adminhtml_checkout',
                'customer_account_create',
                'customer_account_edit'
            ]
        ]);
        $attribute->save();
    }

    private function installModule1(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
        $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

        $customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, 'module2', [
            'type' => 'varchar',
            'label' => 'Module2 label',
            'input' => 'text',
            'source' => '',
            'required' => false,
            'visible' => true,
            'position' => 500,
            'system' => false,
            'backend' => ''
        ]);
        
        $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'module2')
        ->addData(['used_in_forms' => [
                'adminhtml_customer',
                'adminhtml_checkout',
                'customer_account_create',
                'customer_account_edit'
            ]
        ]);
        $attribute->save();
    }
}

Uninstall.php

namespace VENDOR\MODULE\Setup;

use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\Db\Select;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\UninstallInterface;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class Uninstall implements UninstallInterface {
    private $_eavSetupFactory;
    private $_mDSetup;

    public function __construct(EavSetupFactory $eavSetupFactory, ModuleDataSetupInterface $mDSetup) {
        $this->_eavSetupFactory = $eavSetupFactory;
        $this->_mDSetup = $mDSetup;
    }

    public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context) {
        $installer = $setup;
        $eavSetup = $this->_eavSetupFactory->create(['setup' => $this->_mDSetup]);
        $eavSetup->removeAttribute(\Magento\Catalog\Model\Customer::ENTITY, 'module1');
        $eavSetup->removeAttribute(\Magento\Catalog\Model\Customer::ENTITY, 'module2');
    }
}

1 个答案:

答案 0 :(得分:0)

对于客户属性,您需要从表“ eav_attribute”中删除特定的属性条目,可以通过“ attribute_code”进行搜索并删除该行,您必须从数据库中删除属性,因为admin中没有删除属性的功能

相关问题