0

I am using Magento Commerce 2.2.6 running in developer mode.

I have multiple modules that are overriding the same template via the setTemplate action in layout xml. I am using sequence in the modules' module.xml files to control processing order with the intent of controlling which module will ultimately have it's template applied.

UPDATE: It seems Magento is not respecting the sequence specified in these modules. If I manually edit config.php and change the load order (B loads before A) then the modules load correctly/as expected. However, if I then disable and re-enable the modules via cli, Magento rewrites config.php and the order of the modules is switched back (A loads before B).

Below I have copied the module.xml and layout files from each of the conflicting modules:

Vendor_A module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Vendor_A" setup_version="1.0.0"/>
    <sequence>
        <module name="Vendor_B" />
        <module name="MageWorx_Downloads" />
    </sequence>
</config>

Vendor_A catalog_product_view_type_grouped.xml:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceBlock name="product.info.grouped.options">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Vendor_A::product/view/type/grouped.phtml</argument>
        </action>
    </referenceBlock>
</page>

Vendor_B module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Vendor_B" setup_version="1.0.0"/>
    <sequence>
        <module name="Aitoc_GroupedProductsOptions" />
    </sequence>
</config>

Vendor_B catalog_product_view_type_grouped.xml:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceBlock name="product.info.grouped.options">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Vendor_B::product/view/type/grouped.phtml</argument>
        </action>
    </referenceBlock>
</page>

It is my expectation that Vendor_A would have it's template applied because the sequencing specifies for it to be loaded after Vendor_B. However, the opposite is true.

If I comment out the setTemplate action in Vendor_B, then Vendor_A has it's template applied so it seems everything works except sequencing.

Does sequencing not work in the way I think it does or am I making some other erroneous error?

  • 1
    Have you confirmed that your sequence changes have been applied to app/etc/config.php? A cache refresh is not enough - you need to enable/disable any module for the sequence to be written into app/etc/config.php. – Kristof at Fooman Dec 5 '18 at 1:48
  • @KristofatFooman derp, I had a typo in my module.xml files – Steve Karwacki Dec 5 '18 at 19:09
2

I had a typo in my module.xml files. The first module node in:

<module name="Vendor_A" setup_version="1.0.0"/>
<sequence>
    <module name="MageWorx_Downloads" />
    <module name="Vendor_B" />
</sequence>

should not be self-closing and instead should be written as

<module name="Vendor_A" setup_version="1.0.0">
    <sequence>
        <module name="MageWorx_Downloads" />
        <module name="Vendor_B" />
    </sequence>
</module>

Sequencing now works as expected.

  • Is this answer for your own question or an edit? It it is an edit plus update the question. – Mr. Lewis Dec 5 '18 at 19:32
  • It is an answer. Once I fixed the typo everything worked as expected. – Steve Karwacki Dec 5 '18 at 20:41
  • You are a life saver! It's been 3 days I'm struggling with modules loaded in the wrong order, checked so many times the module.xml files and completely not seen that damned self-closing node! – Marco Pallante Apr 15 at 17:46
0

Sometimes you want to load a Module at the end of the sort order. In Magento 1 this could be done by changing the Vendor and/or Module name for the alphabetical order.

In Magento 2 you have to do a little more to load you module at the end of the sort order. Create a simple plugin on Magento\Framework\Module\ModuleList\Loader to change the sort order.

Example Module can be found in Mage2Gen

https://mage2gen.com/load/f3b3a7ce-bf5c-4a09-93a4-d3a1fbdfc717

I have written this totally explained in a Codeblog.

https://codeblog.experius.nl/magento-2-module-load-last-order-position/

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.