1

I try to change some "view" files from a module called Amasty_MegaMenu.

I installed the module via composer. It is located in vendor\amasty\mega-menu.

So I created app/code/Amasty/MegaMenu with these files:

app/code/Amasty/MegaMenu/registration.php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Amasty_MegaMenu',
    __DIR__
);

and app\code\Amasty\MegaMenu\etc\module.xml

<?xml version="1.0"?>
<!--
/**
 * @author Amasty Team
 * @copyright Copyright (c) 2020 Amasty (https://www.amasty.com)
 * @package Amasty_MegaMenu
 */
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Amasty_MegaMenu" setup_version="1.5.0">
        <sequence>
            <module name="Amasty_Base"/>
            <module name="Magento_Cms"/>
            <module name="Magento_Theme"/>
            <module name="Magento_CatalogWidget"/>
        </sequence>
    </module>
</config>

which I have copied from the original vendor module.

Then I added the files which I want to replace

app\code\Amasty\MegaMenu\view\base\web\css\source\module\_variables.less

app\code\Amasty\MegaMenu\view\base\web\css\source\module\_helpers.less

app\code\Amasty\MegaMenu\view\base\web\css\source\mkcss\ammenu.css

Then I executed php bin/magento setup:upgrade but I get:

Autoload error: Module 'Amasty_MegaMenu' from '/home/company/redesign.company.com/app/code/Amasty/MegaMenu' has been already defined in '/home/company/redesign.company.de/vendor/amasty/mega-menu'.

  • You don't need to create a module for that, just place it in your current theme like this : app/design/frontend/Your-theme/theme-name/Amasty_MegaMenu/web/css/source/mkcss/ammenu.css – PЯINCƏ Feb 24 at 22:52
2

If you are just trying to change view files, then you don't need to create a new module at all. Instead you can just create them under the app/design folder to override them with your theme. For example if I wanted to override the following vendor files

vendor\amasty\mega-menu\src\view\base\web\css\source\module_variables.less
vendor\amasty\mega-menu\src\view\base\web\css\source\module_helpers.less
vendor\amasty\mega-menu\src\view\base\web\css\source\mkcss\ammenu.css

We can use the following template to override web files in a module.

app/design/frontend/[ThemeVendor]/[Theme]/[ModuleVendor_ModuleName]

An example extending the amasty files onto the Magento Luma theme would be.

app/design/frontend/Magento/Luma/Amasty_MegaMenu/web/css/source/module_variables.less
app/design/frontend/Magento/Luma/Amasty_MegaMenu/web/css/source/module_helpers.less
app/design/frontend/Magento/Luma/Amasty_MegaMenu/web/css/source/mkcss/ammenu.css

But to answer why are are getting the error message, Magento treats all modules in app/code and vendor as a big pool. So since you name your new module Amasty_MegaMenu it clashes with the Amasty one in vendor. So the options you would have would be.

1. Rename your module

This would be the ideal solution, generally when overriding modules I would advise to use your own Vendor prefix to show who created the override. So for example you could name the module Sam_AmastyMegaMenu.

In your etc\module.xml file you would add a dependency for the original module.

Then because we want to override stylesheets, we would need to find where they are included (layout xml / templates etc). Then override the relevant layout xml / template to use the asset from our new module.

2. Move module to app/code

This is the less ideal solution as you would have to manage the module updates manually, and editing vendor files would cause you to lose modifications during updates. But you would uninstall the module from composer composer remove amasty/mega-menu. Then download their file archive (a zip file i think) and extract that into your app/code folder

| improve this answer | |
0

I think you remove the module name database

Please going the database and open the setup_module and remove the your module name

And after add the your files like Your app/code file path:-

app\code\Amasty\MegaMenu\view\base\web\css\source\module_variables.less

app\code\Amasty\MegaMenu\view\base\web\css\source\module_helpers.less

app\code\Amasty\MegaMenu\view\base\web\css\source\mkcss\ammenu.css

And after run the php bin/magento s:up

Hope help you

Thanks.

| improve this answer | |
  • I removed the module from setup_module but it does still not work. Same error. – Black Feb 25 at 9:40
0
  1. Remove entry fromsetup_module table.
  2. Also if you find it's entry in app/etc/config.php , you should delete it from there as well.
  3. Now run following commands

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy

chmod 777 -R var pub generate

If you sill getting error then run below command in magento root directory and check.

composer dump-autoload

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.