Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento variable to display payment method in email subject

I'm trying to display the payment method in the email subject for new order emails in Magento. The reason being is so that our client can easily determine from the subject of emails send from Magento whether the order came via the payment gateway or Paypal Express.

I'm not entirely sure of the best way to achieve this, I would like to think there is already something available I could use for this.

{{var payment_html}}

returns the payment method block for email templates...

{{var paymentMethod}}

returns absolutely nothing in the email subject so unsure whether this is a depreciated variable now.

I suppose there is also the option of creating a custom attribute, calling it in a static block and then displaying this as a custom variable in the email templates but it seems a rather long winded approach just to purely get a text string of "via SagePay" or "via Paypal Express".

Any help would be greatly appreciated.

Thanks in advance.

like image 973
zigojacko Avatar asked Nov 29 '22 01:11

zigojacko


2 Answers

You actually don't need to perform any customization, this variable is already available in the template though the object chain. This chain is supported by Magento template and allows usage of getters of the object.

In this case you need to retrieve order's payment object, then retrieve its method instance and retrieve method title from method instance. It is very simple construction:

{{var order.getPayment().getMethodInstance().getTitle()}}

This should help you!

like image 59
Ivan Chepurnyi Avatar answered Dec 05 '22 22:12

Ivan Chepurnyi


Method Mage_Sales_Model_Order::sendNewOrderEmail() is responsible for sending new ordr emails.

$paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment())
    ->setIsSecureMode(true);
$paymentBlock->getMethod()->setStore($storeId);
$paymentBlockHtml = $paymentBlock->toHtml();

...

$mailer->setTemplateParams(array(
    'order'        => $this,
    'billing'      => $this->getBillingAddress(),
    'payment_html' => $paymentBlockHtml
)

payment_html is rendered html output of the block, so you can not use it.

You can add one more assoc key (using rewite or local/mage trick) with the payment method and add this param to the subject using transactional emails.

like image 39
Pavel Novitsky Avatar answered Dec 05 '22 21:12

Pavel Novitsky