cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove custom product attributes on module disable?

How to remove custom product attributes on module disable?

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 )
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

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

$setup->endSetup();

}

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?

 

12 REPLIES 12

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

Hello @shabeer_shabeer 

 

when you disable module then it will not run uninstall schema

 

you must need to run

module:uninstall 

command for this

 

more info this:-

https://devdocs.magento.com/guides/v2.3/install-gde/install/cli/install-cli-uninstall-mods.html

Hope it will help you.

 

If works then mark as a solution.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

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

Hello @Sunil Patel 

Thank you for your reply.

We can run the command module:uninstall when we develop in localhost. but if we deliver this module to the client (or we enabled the module in the running live site), the client can only disable this plugin from Admin->System->Web Setup Wizard->Module Manager->Disable/Enable, I think they can't run the module:uninstall command. So, how can we overcome this issue? Do we have any running Observer/event in Magento 2 that run just before uninstall a module?

Thanks in Advance

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

Hello @shabeer_shabeer 

 

what is the issue if product attribute there, it will create an issue if you are using the source model or backend model.

 

Are you using that?

 

 

Also, that is not recommended way to disable the module.

 

If you don't need to the module then remove module using uninstall 

 

Hope it will help you.

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

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

I am creating a custom module, and it will upload in Magento market-place. so anyone can use the plugin. In the current situation, if anyone installed the plugin once in their site 2 additional required fields will be shown in Admin product edit page. And the input fields are showing even the module disabled. So its will make the logical issue because the user won't need the module functionality but the fields should enter when create or edit a product.

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

Hello, a vendor installed a module but it was not working.  I will like to uninstall it.

1.  I tried to remove the module with this process

php bin/magento module:status

php bin/magento module:disable module_name (successfully disabled)

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy -f

php bin/magento cache:clean

php bin/magento cache:flush

delete the folder from app/code/

ran the above again

2. website loads but get the error

Class vendor_name\module_name\Model\Product\Attribute\Backend\MultiShipping does not exist

Same error occurs in all scripts run in ssh.

How do I remove the module?  It seems to be the problem you mention with a custom class model backend

 

Thanks in advance

 

 

 

 

 

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

Magento Setup Uninstall script

The below page in the Magento DevDocs explains the process of module uninstallation. It explains the steps that are taken and one of those steps is running Uninstall scripts of the modules:

 

https://devdocs.magento.com/guides/v2.2/install-gde/install/cli/install-cli-uninstall-mods.html#inst... 

 

 

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

Hello @shabeer_shabeer

To overcome the issue you don't need to create required attribute entry, please create optional attribute for custom module.

Re: Who is the best digital Marketer?

As the world continues to shift towards digital, businesses in Bangladesh are recognizing the need for full-stack digital marketers to help them stay competitive. A full-stack digital marketer is someone who can manage all aspects of a digital marketing campaign, from strategy and planning to execution and analysis.

As a full-stack digital marketer in Bangladesh, I have a wealth of experience in helping businesses establish and grow their online presence. Whether it's through social media, email marketing, search engine optimization (SEO), pay-per-click advertising (PPC), or content marketing, I am able to provide a full suite of digital marketing services to meet the needs of any business.

One of the main advantages of working with a full-stack digital marketer is the ability to have a single point of contact for all digital marketing needs. This not only streamlines the process and improves communication, but it also ensures a consistent and cohesive approach across all marketing channels.

As a digital marketer in Bangladesh, I have a deep understanding of the local market and consumer behavior. This allows me to develop marketing strategies that are tailored to the needs and preferences of the Bangladeshi market.

Whether you're a small business just getting started or an established brand looking to take your digital marketing efforts to the next level, I am here to help. With my experience and expertise as a full-stack digital marketer in Bangladesh, I am confident that I can help you achieve your business goals and drive success in the digital world.

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.