0

I am trying to Create my first custom extension. Unfortunately i think that i miss something.

In the magento 2 root directory i have the following files:

/app/code/Clud7/Skroutz/registration.php

    <?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Clud7_Skroutz',
    __DIR__
);

/app/code/Clud7/Skroutz/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="Clud7_Skroutz" setup_version="1.0.0" />
</config>

app/code/Clud7/Skroutz/etc/frontend/routes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="clud7" frontName="skroutz">
            <module name="Clud7_Skroutz" />
        </route>
    </router>
</config>

app/code/Clud7/Skroutz/Block/Success.php

<?php
namespace Clud7\Skroutz\Block;
class Success  extends \Magento\Framework\View\Element\Template
{
    public function getSomething()
    {
        return 'returned something from custom block.';
    }
}

app/code/Clud7/Skroutz/view/frontend/layout/checkout_onepage_success.xml

<?xml version="1.0"?>
<body>
    <referenceContainer name="order.success.additional.info">
        <block class="Clud7\Skroutz\Block\Success"
               name="clud7.order.success"
               template="Clud7_Skroutz::order/success.phtml"
               after="-">
        </block>
    </referenceContainer>
</body>

app/code/Clud7/Skroutz/view/frontend/templates/order/success.phtml

<?php /* @var $block \Clud7\Skroutz\Block\Success */?>
<?php echo __('Custom template file content.'); ?>
<?php echo $block->getSomething(); ?>

My module is activated and also my magento 2 is compiled and cache cleaned. Also static content deployed.

  • What you want to do in success.phtml? – Ravi Soni Jul 2 '19 at 17:52
  • I want to display order id and to add few javascripts for product feed sale. My problem here is that i am unable even to display a single echo text command. – Γκρεβένης Παναγιώτης Jul 2 '19 at 20:50
  • For that you can override success.phtml file in your custom theme you don't need to create extension for that.. – Ravi Soni Jul 3 '19 at 3:17
1

You module code is correct. You have to need run command step by step and after you can place the order to check success page information.

php bin/magento setup:upgrade

php bin/magento setup:di:compile

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

php bin/magento cache:flush

For debug success page:

Temporarily you can debug checkout success page, to stop the checkout success page redirection after refresh page.

File path: magento/vendor/magento/module-checkout/Controller/Onepage/Success.php

Find the code and comment it:

// $session->clearQuote();

See below output of your module.

enter image description here

0

You need to override success.phmtl in to your custom theme. Don't need to create an extension for that

I have override success.phml file on my porto theme as follows

app/design/frontend/Smartwave/Porto/Magento_Checkout/templates/success.phmtl

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.