0

I am coming from Wordpress development & now I started Magento module development.

I am following this tutorial.

I am just trying to add social sharing buttons to the product edit page.

According to their article,

Now go to the root directory of your Magento and navigate to vendor/magento/module-catalog/view/frontend/templates/product/view, and find the addtocart.phtml file.

Copy this file to your module in app/code/Cloudways/Mymodule/view/frontend/templates/catalog/product/view

So you can see that we are going to override the addtocart.phtml. So my question is, what happens another module override same file? Loss my changes?

  • 2
    it depends on the modules sequence – Philipp Sander Mar 7 at 12:41
  • @PhilippSander It means, if two modules override the same file, definitely one module doesn't work as expected? – I am the Most Stupid Person Mar 8 at 5:38
  • can't say that per-say. it depends on what the modules do – Philipp Sander Mar 11 at 8:06
0

It depends on sequence of your module.

In module.xml you add all modules on which your module depends. Magento will make sure to load your module after all of these modules.

Example

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_ComponentB" setup_version="0.0.1">
        <sequence>
        <!-- Vendor_ComponentB is dependent on Vendor_ComponentA: -->
            <module name="Vendor_ComponentA" />
        </sequence>
    </module>
</config>

https://devdocs.magento.com/guides/v2.3/extension-dev-guide/build/module-load-order.html

The module which will load in the end will overwrite the files of previous modules.

app/code/etc/config.php is auto generated file which has all modules list and modules loading sequence.

  • and your theme will always overwrite module templates – Philipp Sander Mar 7 at 13:14
  • Question is about when module override same file. It is not about frontend theme. – Ismail Zafar Mar 8 at 5:03
  • @IsmailZafar It means, if two modules override the same file, definitely one module doesn't work as expected? – I am the Most Stupid Person Mar 8 at 5:39
  • @IamtheMostStupidPerson see this file app/code/etc/config.php. The module which comes later can overwrite the module which comes earlier. – Ismail Zafar Mar 8 at 6:20

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.