How to remove customer attributes which are created during install 3rd party extention in magento 2?
-
You want to remove using code or directly in database.– Kamlesh SolankiCommented Mar 30, 2019 at 10:34
-
Check this linkhttps://magento.stackexchange.com/a/209867/60921 it may be helpful– Arunprabakaran MCommented Mar 30, 2019 at 10:37
-
We add one extension which is we want remove fully; from files & also from database.– AnilCommented Mar 30, 2019 at 11:05
Add a comment
|
2 Answers
Try This :-
namespace Company\Modulename\Setup
class Uninstall implements \Magento\Framework\Setup\UninstallInterface
{
protected $eavSetupFactory;
public function __construct(\Magento\Eav\Setup\EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function uninstall(\Magento\Framework\Setup\SchemaSetupInterface $setup, \Magento\Framework\Setup\ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create();
$entityTypeId = 1; // Attributte Id
$eavSetup->removeAttribute($entityTypeId, 'attribute_code');
$setup->endSetup();
}
}
-
We add 'github.com/amitshree/magento2-account-approval' this extention. in this only public function install; so we create one more function in 'InstallData.php' file ?– AnilCommented Mar 30, 2019 at 10:58
-
Create script in magento2-account-approval/Setup/Uninstall.php after that follow below command: php bin/magento setup:upgrade php bin/magento setup:static-content:deploy en_US -f php bin/magento cache:clear Commented Mar 30, 2019 at 11:12
-
When we add 'Uninstall.php' at that time any necessary to remove 'InstallData.php' from 'magento2-customer-account-approval/Setup' before command run ?– AnilCommented Mar 30, 2019 at 11:49
-
-
Thanks Very much. its working for us. We change some other things. add this Uninstall.php file then delete attribute from database. So my work is done as per our requirement.– AnilCommented Mar 30, 2019 at 12:21
You can create either an upgrade or install script in your custom module. Here an example with an install script:
<?php
namespace vendor\module\Setup;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->removeAttribute(
\Magento\Customer\Model\Customer::ENTITY,
'custom_attribute');
$setup->endSetup();
}
}
-
Thanks for reply. We add 'github.com/amitshree/magento2-account-approval' this extention. Please guide me what to do for it.– AnilCommented Mar 30, 2019 at 10:57
-
We want to remove this extention from our site. but in customer data value of attribute which is generated by this extention. so we remove all data and attribute which is generated by this extention.– AnilCommented Mar 30, 2019 at 11:01
-
We add 'public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); $customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'approve_account'); $setup->endSetup(); }' this code as your answer update but attribute not remove.– AnilCommented Mar 30, 2019 at 11:24
-