0

I'm using Magento 2.4.7-p1 and I'm trying to show programmatically a customer block on the success page from my module but without success.

The module seems correctly enabled and registered but the custom block is not shown. No other info in the log files. I also run magento setup:upgrade, magento cache:flush, etc. Products are downloadables.

Here's what I done:

Vendor/Module/registration.php

<?php

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'Vendor_Module',
    __DIR__);

Vendor/Module/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="1.0.0">
    </module>
</config>

Vendor/Module/view/frontend/layout/checkout_onepage_success.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">
    <body>
        <referenceContainer name="order.success.additional.info">
            <block class="Magento\Checkout\Block\Onepage\Success"
                    name="test2.order.success"
                    template="Vendor_Module::order/success.phtml"
                    cacheable="false"
                    after="-">
            </block>
        </referenceContainer>
    </body>
</page>

Vendor/Module/view/frontend/templates/order/success.phtml

<?php
echo "My custom content!";

Edit:

I also tried to set a sequence like this:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Checkout"/>
            <module name="Magento_Sales"/>
            <module name="Magento_Quote"/>
            <module name="Magento_Vault"/>
            <module name="Magento_Paypal"/>
        </sequence>
    </module>
</config>

Solution

I just forgot an s in the actual module name in the registration.php. The actual name was Pettis_LinkOnSuccessPage instead of Pettis_LinksOnSuccessPage.

However, how is it possible the module resulted enabled anyway?

5
  • your code for xml and phtml is correct, must be issue with module or cache
    – Pawan
    Commented Aug 21 at 5:00
  • I also tried to buy a simple product but the result is the same. I think I flushed all the caches: browser, Nginx, Varnish, PHP, Redis...
    – KaMZaTa
    Commented Aug 21 at 7:55
  • The module is shown as enabled running magento module:status. Furthermore, no pertinent output in exception.log, debug.log, and system.log files.
    – KaMZaTa
    Commented Aug 21 at 7:58
  • 1
    previous question you asked related to this, i hope it also work for you, if it is do accept that answer as well
    – Kareem k
    Commented Aug 21 at 8:53
  • @Kareemk sure, I will
    – KaMZaTa
    Commented Aug 21 at 8:58

3 Answers 3

1

@KaMZaTa try changing the block class from

<block class="Magento\Checkout\Block\Onepage\Success">

to <block class="Magento\Framework\View\Element\Template">

Refer the core layout which defines order.success.additional.info as a container within the Magento\Checkout\Block\Onepage\Success block. `

<block class="Magento\Checkout\Block\Onepage\Success" name="checkout.success" template="Magento_Checkout::success.phtml" cacheable="false">
    <container name="order.success.additional.info" label="Order Success Additional Info"/>
</block>

` This container is a child of the checkout.success block, and its purpose is to hold additional content or blocks that should be displayed on the order success page. (\Template class can extend your desired parent class).

3
  • Nothing to do. It doesn't show.
    – KaMZaTa
    Commented Aug 20 at 17:44
  • your code looks fine, try like this <block class="" name=""/> self-closing tag. <referenceContainer name="order.success.additional.info"> <block class="Magento\Checkout\Block\Onepage\Success" name="test2.order.success" template="Vendor_Module::order/success.phtml" cacheable="false" after="-" /> </referenceContainer>
    – Antony
    Commented Aug 21 at 1:08
  • It doesn't work.
    – KaMZaTa
    Commented Aug 21 at 7:50
1

I think that the mistake reside in the name of your layout file.

Instead of that :

Vendor/Module/view/frontend/layout/checkout_onepage_checkout.xml

I think you should have that :

Vendor/Module/view/frontend/layout/checkout_onepage_success.xml
1
  • Sorry, my bad. Actually I reported here the wrong file name. I'm already using Vendor/Module/view/frontend/layout/checkout_onepage_success.xml. I updated the question.
    – KaMZaTa
    Commented Aug 20 at 21:58
1

Everything just look fine to me. I don't have any M2.4.7 instance available right now. But on a 2.4.5, I tested your code, and that run correctly, displaying the "My custom content!" expected.

Then I think the issue is elsewhere. I suggest you run another setup:upgrade, followed by a cache:flush, to be sure to rule that out.

Let's say that does nothing. At first glance, I think that you may don't use order.success.additional.info container anymore, the core layout being override by a module or a theme or the controller is not trigger anymore.

  • First thing first, when an order is placed sucessfully do you land on checkout/onepage/success/ ?

  • If yes then the controller should be triggered and you can check that you go in there (vendor/magento/module-checkout/Controller/Onepage/Success.php).

  • Then, check if you go inside the block (vendor/magento/module-checkout/Block/Onepage/Success.php)

  • The block could be called from elsewhere, from another theme overriding the layout for instance. Try to put your block directly in the core layout (vendor/magento/module-checkout/view/frontend/layout/checkout_onepage_success.xml). If not more success, you can try to duplicate the template success.phtml (vendor/magento/module-checkout/view/frontend/templates/success.phtml) and change it in the layout file. Check if you have any change. Keep in mind to run setup upgrade and cache flush after every change to rule out that kind of problems (even if cacheable is set to false).

If you answered no form anything from above, you may have something overriding the core behaviour. Custom theme, custom module, custom layout or custom templates...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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