I have tried all examples found on Magento forums but I can't make it work.
I need to get Order ID and customer email on checkout success page.
Here's my module structure:
TV2M/GoogleSurvey/registration.php
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'TV2M_GoogleSurvey', __DIR__ ); TV2M/GoogleSurvey/etc/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="TV2M_GoogleSurvey" setup_version="1.0.0" schema_version="1.0.0"> </module> </config> TV2M/GoogleSurvey/Block/Onepage/Success.php
<?php namespace TV2M\GoogleSurvey\Block\Onepage; use \Magento\Framework\View\Element\Template; class Success extends \Magento\Checkout\Block\Onepage\Success { public function getGoogleSurvey() { return "[email protected]"; } } Module is activated, setup upgrade, cache clean...
In my theme folder, I have created a phtml file called by layout XML. File is loaded correctly. But when I call my function it returns nothing: echo $block->getEmail();
I have also tried to add di.xml:
TV2M/GoogleSurvey/etc/frontend/di.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Checkout\Block\Onepage\Success" type="TV2M\GoogleSurvey\Block\Onepage\Success" /> </config> Can someone please tell me how to access getGoogleSurvey() function? Which files are necessary in my module? Thanks in advance.