3

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.

  • Are you creating an own payment method or to customize an existing one? Which module is it (if you adapt one?) - and is there more than one payment method that should get this text in the mail? – Alex Jun 5 '13 at 13:14
4

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.

  • Thanks for your reply. I have installed the bankpayment module. I need to make some changes as the css is shocking but It works great. Thanks! – Wessel Jun 6 '13 at 13:37
  • Actually there are others as well. I think github.com/therouv/Magento-DebitPayment is more recent work.*edit* – Alex Jun 6 '13 at 13:54
3

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>
2

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

  • Thanks so much Mufaddal. Very Informative. Going to try this. Will post back! Thanks again! – Wessel Jun 5 '13 at 12:12
1

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 :)

0

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}}
  • Thanks for your reply Fabian. However I'm not quiet with you on this. – Wessel Jun 5 '13 at 12:39
0

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

  • Thanks for your post. I will look into this and post back! – Wessel Jun 5 '13 at 8:22

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.