Magento 1.8 – Custom Shipping Method Email Notification

emailmagento-1.8ordersshippingshipping-methods

i just created my custom shipping method.

i created custom module.

now what i want to do is if user select custom shipping method and submit the order ,

user and customer both will get one additional email. user will recieve the text written by admin and admin will receive the user's info.

i have created shipping method describe here:

http://inchoo.net/ecommerce/magento/custom-shipping-method-in-magento/

now what i am looking for is if user select the custom shipping methods and place the order, admin and user both will get one additional email which will be handle by admin.

how can i do that?

any hint?

Best Answer

maybe this will help you: https://github.com/thebod/Thebod_Shippingrates/blob/master/app/code/community/Thebod/Shippingrates/Model/Email.php (the code is pretty ugly, I wrote it 2-3 years ago).

Basically you need an observer on an event where you want to send out the mail(s).

To send the mails you can use the code from my extension, basically use a check like this:

if (strncmp($order->getShippingMethod(), 'shippingrates_', 14) != 0) {
    return false;
}

to see if it matches your shipping rate. Then continue with sending the mail, use the store-emulation to avoid issues with the current store (e.g. if the order is placed somehow from the admin panel).

// Retrieve corresponding email template id and customer name, replace this code in case you use your own mail template
if ($order->getCustomerIsGuest()) {
    $templateId = Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
    $customerName = $order->getBillingAddress()->getName();
} else {
    $templateId = Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_TEMPLATE, $storeId);
    $customerName = $order->getCustomerName();
}

// initialize the core mailer model and mail info model
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
// addTo($mailaddress) specifies the receiver(s) of the mail
$emailInfo->addTo($notificationMail);
$mailer->addEmailInfo($emailInfo);

// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_IDENTITY, $storeId));
$mailer->setStoreId($storeId);
$mailer->setTemplateId($templateId);
// the template params are used in the template file via {{var order.customer_name}}
$mailer->setTemplateParams(
    array(
        'order'        => $order,
        'billing'      => $order->getBillingAddress(),
        'payment_html' => $paymentBlockHtml
    )
);
// send out the mail
$mailer->send();

I hope this helps.

Related Topic