Magento - Custom subject of order email

2019-09-15 00:37发布

问题:

I have a service in PHP which interacts with a Magento website. I can't access the source code of this website. So I can use service to order a product and send a mail. When I call

$order->sendNewOrderEmail();

an email will be send to my email-id with subject Nuovo ordine # XXXXXXXXX.

Now I want add a string to this subject: TEST - Nuovo ordine # XXXXXXXXX.

How I can do it?

回答1:

In app/code/core/Mage/Sales/Model/Order.php find sendNewOrderEmail() method. Then find

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

Here is array of variables from template. Add one new param for test:

            'test'         => $is_test ? $is_test : ''

Change $is_test to your condition. For example:

public function sendNewOrderEmail($is_test = FALSE)

Now open your template file app/locale/en_US/template/email/sales/order_new_guest.html (for example).

Find subject variable on the first line: <!--@subject Nuovo ordine # {{var order.increment_id}} @--> or something like this.

Make changes: <!--@subject {{var is_test}}Nuovo ordine # {{var order.increment_id}} @-->

Call method:

$order->sendNewOrderEmail('TEST - ');