Question

I need to send a specific email if the customer selects a payment method.

I will be using this for clients who wish to pay offline (Bank transfer) The email will inform them of our banking details.

Was it helpful?

Solution

If you can modify that specific payment method / module you use, it should be enough to set the property $_infoBlockType of your payment class and create a block which renders the necessary information.

Basically this block would just make a ->setTemplate() call in the constructor and then reference to your custom .phtml file with the infos.

Remark: Concerning bank transfer there are also ready-made & free extensions (I know about https://github.com/therouv/Magento-DebitPayment and Phoenix_BankPayment - but did not use them so far) which you might want to use directly, get inspiration or adapt them to your specific needs.

OTHER TIPS

As stated before by Fabian Blechschmidt, no need for observers if someone is in need of a simple solution. Insert this block into a desired email template in magento:

{{block type='core/template' area='frontend' template='email/order/sometext.phtml' order=$order}}

And create the file in app/design/frontend/YOURTEMPLATE/email/order/sometext.phtml .

Inside the file, a simple if and away we go:

<?php $_order = $this -> getOrder(); ?>
<?php if ($_order->getPayment()->getMethod() == 'somepayment') ?>
<p>Some text for the specific payment</p>

You can use event/observer method of magento to do something after order is placed.

you can use this event sales_order_place_after

Just create one module to listen magento observer/event.

In your /app/code/local/{namespace}/{yourmodule}/etc/config.xml:

<config>
        ...
        <frontend>
            ...
            <events>
                <sales_order_place_after>
                    <observers>
                        <unique_event_name>
                            <class>{{modulename}}/observer</class>
                            <method>your function name</method>
                        </unique_event_name>
                    </observers>
                </sales_order_place_after>
            </events>
            ...
        </frontend>
        ...
    </config>

And then create an Observer class at /app/code/local/{namespace}/{yourmodule}/Model/Observer.php

    class <namespace>_<modulename>_Model_Observer
   {
      public function your function name(Varien_Event_Observer $observer)
      {
          $observer->getEvent()->getOrder() will give you all order detail.
            retrieve payment methods and customer email from this order object 
      }

   }

For custom email you can refer this link Link

Here is how I solved my problem.

I wanted to display different text depending on different payment methods.

In Transactional Email template where I wanted to display desired HTML I added this line

{{block type='core/template' area='frontend' template='paymentstatus/orderemail.phtml' order=$order}}

Then I created orderemail.phtml file in app/design/frontend/yourtheme/yoursubtheme/template/paymentstatus/

Added php logic I wanted:

<?php

//Get payment method code
$pMethod = $this->getData('order')->getPayment()->getMethodInstance()->getCode();

if ($pMethod == 'banktransfer') {
?>
    <p>Bank Transfer payment method selected during checkout process</p>
<?php
}

if ($pMethod == 'cashondelivery') {
?>
    <p><Cash On Delivery payment method selected during checkout process/p>
<?php
}
?>

And that's it, make your test order and see the changes.

Hope it helps to someone :)

No need for an observer here if you ask me.

You can include a block into the mail, inject the order, check for the payment method and insert an if, then the payment data is only inserted, if the correct payment method is used.

{{block type='core/template' area='frontend' template='email/order/mailtemplate.phtml' order=$order}}

create a new extension for this and use an observer to send the email. From the observer object parsed to the model that is your observer you can retrieve the order and from there the payment method. A simple if/else would then suffice to only send the email on a certain payment method.

Inchoo has a great article on the observer you need: Inchoo Custom Magento Events And sending custom email you can learn from here: Inchoo Magento custom emails

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top