2

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?

  • you can use sales_order_place_after event and check shipping method in order object if it your custom shipping method then send custom email to admin and customer – Keyur Shah Feb 14 '14 at 11:41
  • i don't know how to do that. do i need to create in same module or i have to create one more module? – Jack Torris Feb 14 '14 at 11:45
  • you can use your module and create one event sales_order_place_after plz chk magento.stackexchange.com/questions/10222/getting-payment-info-on-sales-order-place-after-help – Keyur Shah Feb 14 '14 at 11:52
  • hi keyur, thanks for reply. i am trying to create pickup module. it mean if user select mycustom shipping method and place the order user will get notification set by the admin. so custom shipping method done. if user don't select my custom shipping method then , user won't receive the email set bu admin. user will receive only default emails. – Jack Torris Feb 14 '14 at 11:59
2

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.

  • hi, thanks for this code. i am gonna try it. – Jack Torris Feb 14 '14 at 12:00
  • send email to customer and admin if shipping method is free? how to do that? need help with it – Jack Torris Feb 17 '14 at 10:47
  • @thebod, can you explain this a little further? In case of a specific shipping method, I need to sent a custom shipping email instead of the default one. This is some kind of override, right? If I send this email using an observer, the default sipping email will be sent too. How can I prevent that? – zekia Oct 3 '18 at 13:54

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.