0

How can I call a .phtml file in Observer?

I want to show popup window when event observer fires after customer login so I can call phtml file that contains html popup?

So After Customer logged-in a popup appear on the screen directly that contain string text.

Observer declaration in config.xml:

<frontend>
        <events>
            <customer_login>
                <observers>
                    <mumodule_model_observer>
                        <type>model</type>
                        <class>mymodule/observer</class>
                        <method>my_custom_event</method>
                    </mymodule_model_observer>
                </observers>
            </customer_login>
        </events>
    </frontend>

My Observer Class:

<?php

class Company_MyModule_Model_Observer
{
    public function my_custom_event($observer)
    {
        $customer = $observer->getCustomer();
    }
}

Base on : https://stackoverflow.com/a/38117362/6041121

  • hmm, why would you need to get a .phtml template in php to show as a popup? If you give me a bit of more context I might be able to help you out. E.g. what is the event for, when is it triggered etc. – André Ferraz Feb 21 '18 at 10:46
  • @AndréFerraz, i've update my question. i want to show popup after the customer logged-in. – mahmoudismail Feb 21 '18 at 10:50
0

This answer might not give you a full explanation but it should help you get started with development.

First you don't really need a observer for this, this should be done on the front-end.

Just add a new block which uses your phtml template to the customer_account_index. So something like this:

<customer_account_index>
        <block type="template/type" as="customname" name="actualname" template="phtml-template">
        </block>
</customer_account_index>

Your phtml template would contain the JS logic for the pop up. (I'm assuming you know the basics of magento so I assume you know what those nodes mean.)

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.