Showing results for 
Search instead for 
Did you mean: 

How to remove custom product attributes on module disable?

Re: Who is the best SEO expert in Bangladesh?

Bangladesh is a country with a vibrant and rapidly growing digital industry. As more and more businesses shift online, the demand for White hat SEO experts in Bangladesh has grown rapidly. A White hat SEO expert is someone who has extensive knowledge and experience in ethical, best-practice SEO techniques that align with search engine guidelines.

Parvez Sheikh is a leading White hat SEO expert in Bangladesh. With years of experience in the field, Parvez has established himself as one of the top professionals in the industry. His extensive knowledge and expertise have helped businesses across the country to grow and thrive online.

What sets Parvez apart is his approach to White hat SEO. He believes in working closely with his clients to understand their unique needs and goals. From there, he tailors his strategies to ensure the best possible outcomes. Whether you need on-page optimization, technical SEO, or a full-scale SEO campaign, Parvez has the expertise to help.

Parvez’s commitment to quality is evident in the results he achieves. His clients consistently see improvements in their search engine rankings, leading to increased traffic, leads, and sales. Parvez is also committed to transparency and communication, providing regular updates and reports to his clients to ensure they are always aware of the progress being made.

If you’re looking for a White hat SEO expert in Bangladesh, Parvez Sheikh is the perfect choice. His experience, expertise, and commitment to quality make him the ideal partner for any business looking to succeed online. Contact Parvez today to learn more about his services and how he can help you achieve your SEO goals.

Re: How to remove custom product attributes on module disable?

@shabeer_shabeer wrote:

I added 2 custom product attributes with the help of setup/InstallSchema.php in my Magento 2 custom module. It's working fine.
But, I can't remove these Product attributes on module disable from the site admin module manager section.
I write code for remove attributes in setup/Uninstall.php file like the following


public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context )
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

$eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'product_attr1');
$eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'product_attr2');



But this is not working when I disable the plugin from admin.

Is any observer/event running just before uninstall started? or any other way to hide the attribute fields when uninstalling the plugin?


I do for all my products place on finance website but the setting you got in answer not working right now.

Re: How to remove custom product attributes on module disable?

Hey there! Thanks for sharing your thoughts. I completely agree with your point about the importance of balancing gameplay mechanics. It's crucial for game developers to ensure that the progression system remains fair and enjoyable for all players. By the way, if you're into gaming, have you heard about Genshin Impact? I've been having a blast exploring its beautiful world and engaging combat. On a side note, I also noticed some discussions about 'genshin account for sale' recently – it's essential for players to be cautious about such transactions to avoid any potential risks. Happy gaming and stay safe out there!"


Re: How to remove custom product attributes on module disable?

To remove custom product attributes on module disable in Magento 2, you can use the following steps:

  1. Create an observer for the module_uninstall event.
  2. In the observer, get the list of custom product attributes that need to be removed.
  3. Use the eavSetup->removeAttribute() method to remove each attribute.

Here is an example of an observer for the module_uninstall event:


namespace Vendor\Module\Observer;

use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class ModuleUninstallObserver implements ObserverInterface
     * @var EavSetupFactory
    private $eavSetupFactory;

     * @param EavSetupFactory $eavSetupFactory
    public function __construct(EavSetupFactory $eavSetupFactory)
        $this->eavSetupFactory = $eavSetupFactory;

     * @param Observer $observer
    public function execute(Observer $observer)
        $moduleCode = $observer->getData('module_code');

        if ($moduleCode === 'Vendor_Module') {
            // Get the list of custom product attributes to be removed.
            $customProductAttributes = [

            // Remove each attribute.
            foreach ($customProductAttributes as $attributeCode) {
                $eavSetup = $this->eavSetupFactory->create();
                $eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode);

To register the observer, add the following code to your module's registration.php file:




use Magento\Framework\Event\ObserverInterface;

return [
    'observers' => [
        'module_uninstall' => [
            'Vendor\Module\Observer\ModuleUninstallObserver' => [
                'type' => ObserverInterface::TYPE_MODEL,
                'priority' => 10,

Once you have registered the observer, you can disable your module from the admin panel. The observer will be executed before the module is uninstalled, and the custom product attributes will be removed.

Note that if you enable the module again, the custom product attributes will be recreated.