Jump to content

How To Disable "in Transit" Emails From Being Sent?


Recommended Posts

I'm on Prestashop 1.6.1.2, and everytime I set a tracking number an emails is automatically sent, I want to stop this email and sent the tracking code on the "shipping" email.

 

I can't find any settings that enable me to deactivate the "in transit" emails.

 

Link to comment
Share on other sites

  • 3 weeks later...

Disabling checkbox for "Processing in progress" status (Preparation template) will NOT help you.

 

To disable this In-Transit-email you should make some code editing (see screen).

Just comment this lines in /controllers/admin/AdminOrdersController.php file.

 

dMwY8IN.png

 

Just don't ask me why developers didn't make this option for backoffice. I wish i knew.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

I was searching solution for this question and I found this topic. And after checking this clues I would like to describe what I had change.

 

I can't open this screenshot put by serdib.

I have Prestashop 1.6.0.14 and in this mentioned file /controllers/admin/AdminOrdersController.php just try to find this string: /* Update shipping number */

Below there are few lines of code responsible for sending email notification after setting tracking number. You shuold comment part of it. This lines starts in my verion from line 480.

Finaly it should look like this:

/*
if (@Mail::Send((int)$order->id_lang, 'in_transit', Mail::l('Package in transit', (int)$order->id_lang), $templateVars,
    $customer->email, $customer->firstname.' '.$customer->lastname, null, null, null, null,
    _PS_MAIL_DIR_, true, (int)$order->id_shop))
{
*/
    Hook::exec('actionAdminOrdersTrackingNumberUpdate', array('order' => $order, 'customer' => $customer, 'carrier' => $carrier), null, false, true, false, $order->id_shop);
    Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
/*
}
else
    $this->errors[] = Tools::displayError('An error occurred while sending an email to the customer.');
*/

Please be careful, because I didn't comment all this part of code. Un the middle there are still twa lines not commented.

 

I checked this and it works :)

 

What else? I prepared new email template and new order status - "prepared to send". In this email message I put info about tracking URL:

You can track your package using the following link: <a href="{followup}" style="color:#337ff1">{followup}</a>
Link to comment
Share on other sites

  • 9 months later...

It is a bit different for PS 1.7.2+ versions.

As mentioned above you should change the file .../controllers/admin/AdminOrdersController.php
Here you should find next string (line 505 in my case):

if ($order_carrier->sendInTransitEmail($order))

as you see - there is new function sendInTransitEmail which btw is in the file .../classes/order/OrderCarrier.php
This function return True if mai (templates in_transit.html and/ or in_transit.txt) was sent successfully. To disable automatic sending of e-mail we should simply replace above mentioned line to described below:

// if ($order_carrier->sendInTransitEmail($order))
   if (True)


By commenting here the call of this function and set always True in the If clause - we simply bypass sending of this duplicated e-mail as using of shipped template is much more adequate and client-friendly.

To finalize - it would be good idea for PS team or somebody who is designing modules to create simple module, where admin would be able to switch off/ on all these a la default PS e-mails (I counted at least 5 of them, which are generating automatically and they sometimes are very irritating).

  • Thanks 4
Link to comment
Share on other sites

  • 3 months later...
On 31/12/2017 at 1:42 AM, Vito said:

It is a bit different for PS 1.7.2+ versions.

As mentioned above you should change the file .../controllers/admin/AdminOrdersController.php
Here you should find next string (line 505 in my case):

if ($order_carrier->sendInTransitEmail($order))

as you see - there is new function sendInTransitEmail which btw is in the file .../classes/order/OrderCarrier.php
This function return True if mai (templates in_transit.html and/ or in_transit.txt) was sent successfully. To disable automatic sending of e-mail we should simply replace above mentioned line to described below:

// if ($order_carrier->sendInTransitEmail($order))
   if (True)


By commenting here the call of this function and set always True in the If clause - we simply bypass sending of this duplicated e-mail as using of shipped template is much more adequate and client-friendly.

To finalize - it would be good idea for PS team or somebody who is designing modules to create simple module, where admin would be able to switch off/ on all these a la default PS e-mails (I counted at least 5 of them, which are generating automatically and they sometimes are very irritating).

 

Hello!

When I do what you say, the "Orders" page throws me a 505.

 

EDIT: Now it's working so thx u so much :)

Thank you
Best regards

Edited by Raiderpoer (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Yes, you just have to deactivate above mentioned condition rule (by commenting "//") , and put instead of it new statement "If (true)" which means it will perform always - no magic. It has to work ;)

best regards, Vito

Link to comment
Share on other sites

  • 8 months later...

Hello,

Unfortunately, this does not work from 1.6.1.20:

/*
if (@Mail::Send((int)$order->id_lang, 'in_transit', Mail::l('Package in transit', (int)$order->id_lang), $templateVars,
    $customer->email, $customer->firstname.' '.$customer->lastname, null, null, null, null,
    _PS_MAIL_DIR_, true, (int)$order->id_shop))
{
*/
    Hook::exec('actionAdminOrdersTrackingNumberUpdate', array('order' => $order, 'customer' => $customer, 'carrier' => $carrier), null, false, true, false, $order->id_shop);
    Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
/*
}
else
    $this->errors[] = Tools::displayError('An error occurred while sending an email to the customer.');
*/

It's blank page in orders:
Parse error: syntax error, unexpected 'else' (T_ELSE) in controllers/admin/AdminOrdersController.php on line 505

 

Problem solved:

/*  
	if (@Mail::Send((int)$order->id_lang, 'in_transit', Mail::l('Package in transit', (int)$order->id_lang),$templateVars,
        $customer->email, $customer->firstname.' '.$customer->lastname, null, null, null, null,
        _PS_MAIL_DIR_, true, (int)$order->id_shop))
*/
{
 	Hook::exec('actionAdminOrdersTrackingNumberUpdate', array('order' => $order, 'customer' => $customer, 'carrier' => $carrier), null, 		false, true, false, $order->id_shop);
	Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
/*	
	} else {
       $this->errors[] = Tools::displayError('An error occurred while sending an email to the customer.');
*/ 

This is correct code, attention to the brackets!

Edited by roman.b (see edit history)
Link to comment
Share on other sites

  • 2 months later...
  • 6 months later...
  • 5 months later...
Am 12.4.2018 um 6:20 PM schrieb Raiderpoer:

 

Hello!

When I do what you say, the "Orders" page throws me a 505.

 

EDIT: Now it's working so thx u so much :)

Thank you
Best regards

Hi,

on Prestashop doesn't work this way, I'm getting an error .. Can someone help me?

 

Link to comment
Share on other sites

  • 10 months later...

Somehow on PS 1.7.7.2 did not work

On 12/31/2017 at 2:42 AM, Vito said:

It is a bit different for PS 1.7.2+ versions.

As mentioned above you should change the file .../controllers/admin/AdminOrdersController.php
Here you should find next string (line 505 in my case):

if ($order_carrier->sendInTransitEmail($order))

as you see - there is new function sendInTransitEmail which btw is in the file .../classes/order/OrderCarrier.php
This function return True if mai (templates in_transit.html and/ or in_transit.txt) was sent successfully. To disable automatic sending of e-mail we should simply replace above mentioned line to described below:

// if ($order_carrier->sendInTransitEmail($order))
   if (True)


By commenting here the call of this function and set always True in the If clause - we simply bypass sending of this duplicated e-mail as using of shipped template is much more adequate and client-friendly.

To finalize - it would be good idea for PS team or somebody who is designing modules to create simple module, where admin would be able to switch off/ on all these a la default PS e-mails (I counted at least 5 of them, which are generating automatically and they sometimes are very irritating).

So instead I configured different process:

1. I added to copy of /override/classes/order/OrderCarrier.php , line 138    
'{delivery_time}' => $carrier->delay,

So I can use all the same variables as I have defined for my shipping template.

2. I copied all shipping.html and .txt template content to in_transit.html and .txt in all languages

3. I disabled e-mail sending for delivered status in Shop Parameters, Order Settings

4. I Changed e-mail subject translations in all languages so that In transit and Shipped are the same: Shipped

Now I can just send shipping conformation by adding tracking number. After that I set the order as Delivered, where I disabled the e-mail sending. If I still need to send e-mail I can always set status to shipped. Just in case to avoid customer confusion about status you may also rename Delivered as shipped_1 or something...

So, it is resolution, not on code, but on process.

Link to comment
Share on other sites

  • 1 month later...
Am 31.12.2017 um 1:42 AM schrieb Vito:

It is a bit different for PS 1.7.2+ versions.

As mentioned above you should change the file .../controllers/admin/AdminOrdersController.php
Here you should find next string (line 505 in my case):

if ($order_carrier->sendInTransitEmail($order))

as you see - there is new function sendInTransitEmail which btw is in the file .../classes/order/OrderCarrier.php
This function return True if mai (templates in_transit.html and/ or in_transit.txt) was sent successfully. To disable automatic sending of e-mail we should simply replace above mentioned line to described below:

// if ($order_carrier->sendInTransitEmail($order))
   if (True)


By commenting here the call of this function and set always True in the If clause - we simply bypass sending of this duplicated e-mail as using of shipped template is much more adequate and client-friendly.

To finalize - it would be good idea for PS team or somebody who is designing modules to create simple module, where admin would be able to switch off/ on all these a la default PS e-mails (I counted at least 5 of them, which are generating automatically and they sometimes are very irritating).

 

Does not work with PS 1.7.7.3 anymore 😭! Has somebody found a simple solution to disable that stupid in_transit mail? 

 

 

Link to comment
Share on other sites

  • 1 month later...
13 hours ago, Sexto Placer said:

Hello, you managed to find the solution. I have version 1.7.7.3 and the above solutions are not working.

Thanks

Seeing as you are the second person on that PS version where it doesn't work It seems there has been changes to the core files.

Link to comment
Share on other sites

  • 3 weeks later...
On 5/19/2021 at 7:38 PM, Sexto Placer said:

Hello, you managed to find the solution. I have version 1.7.7.3 and the above solutions are not working.

Thanks

Hi guys,

For Prestashop 1.7.7.0-1.7.7.4 you need to modify a different file since the order page was migrated to Symfony:
[please note that you will lose this modification if you upgrade Prestashop in future]

File path:
/src/Adapter/Order/CommandHandler/UpdateOrderShippingDetailsHandler.php

You need to comment out the following part - in my case line 111 to 124:

Before:

//send mail only if tracking number is different AND not empty
        if (!empty($trackingNumber) && $oldTrackingNumber != $trackingNumber) {
            if (!$orderCarrier->sendInTransitEmail($order)) {
                throw new TransistEmailSendingException('An error occurred while sending an email to the customer.');
            }

            $customer = new Customer((int) $order->id_customer);
            $carrier = new Carrier((int) $order->id_carrier, $order->id_lang);

            Hook::exec('actionAdminOrdersTrackingNumberUpdate', [
                'order' => $order,
                'customer' => $customer,
                'carrier' => $carrier,
            ], null, false, true, false, $order->id_shop);
        }

After:
 

     //send mail only if tracking number is different AND not empty
        // if (!empty($trackingNumber) && $oldTrackingNumber != $trackingNumber) {
        //     if (!$orderCarrier->sendInTransitEmail($order)) {
        //         throw new TransistEmailSendingException('An error occurred while sending an email to the customer.');
        //     }

        //     $customer = new Customer((int) $order->id_customer);
        //     $carrier = new Carrier((int) $order->id_carrier, $order->id_lang);

        //     Hook::exec('actionAdminOrdersTrackingNumberUpdate', [
        //         'order' => $order,
        //         'customer' => $customer,
        //         'carrier' => $carrier,
        //     ], null, false, true, false, $order->id_shop);
        // }

 

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

On 6/7/2021 at 4:44 PM, matik4 said:

Hi guys,

For Prestashop 1.7.7.0-1.7.7.4 you need to modify a different file since the order page was migrated to Symfony:
[please note that you will lose this modification if you upgrade Prestashop in future]

File path:
/src/Adapter/Order/CommandHandler/UpdateOrderShippingDetailsHandler.php

You need to comment out the following part - in my case line 111 to 124:

Before:


//send mail only if tracking number is different AND not empty
        if (!empty($trackingNumber) && $oldTrackingNumber != $trackingNumber) {
            if (!$orderCarrier->sendInTransitEmail($order)) {
                throw new TransistEmailSendingException('An error occurred while sending an email to the customer.');
            }

            $customer = new Customer((int) $order->id_customer);
            $carrier = new Carrier((int) $order->id_carrier, $order->id_lang);

            Hook::exec('actionAdminOrdersTrackingNumberUpdate', [
                'order' => $order,
                'customer' => $customer,
                'carrier' => $carrier,
            ], null, false, true, false, $order->id_shop);
        }

After:
 


     //send mail only if tracking number is different AND not empty
        // if (!empty($trackingNumber) && $oldTrackingNumber != $trackingNumber) {
        //     if (!$orderCarrier->sendInTransitEmail($order)) {
        //         throw new TransistEmailSendingException('An error occurred while sending an email to the customer.');
        //     }

        //     $customer = new Customer((int) $order->id_customer);
        //     $carrier = new Carrier((int) $order->id_carrier, $order->id_lang);

        //     Hook::exec('actionAdminOrdersTrackingNumberUpdate', [
        //         'order' => $order,
        //         'customer' => $customer,
        //         'carrier' => $carrier,
        //     ], null, false, true, false, $order->id_shop);
        // }

 

Many thanks. All right. All the best!

Link to comment
Share on other sites

  • 1 month later...

 

Hi all,

If you don't want to send this e-mail each time you add/update a tracking number for a specific order, you can override sendInTransitEmail() function by creating the following file in /override/classes/order/OrderCarrier.php

<?php
/**
 * OrderCarrier override : disable in_transit emails
 *
 */
defined('_PS_VERSION_') or die;
class OrderCarrier extends OrderCarrierCore
{
    /**
     * @param Order $order Required
     *
     * @return bool
     */
    public function sendInTransitEmail($order)
    {
        return true;
    }
}

This function is only called from /src/Adapter/Order/CommandHandler/UpdateOrderShippingDetailsHandler.php

If you clear your Prestashop cache, then it won't send at all the in_transit email when you add/update tracking number.

It works in Prestashop 1.7.7.2 and as it is an override, you won't loose your modification when you update Prestashop.

Hope it helps.

  • Like 5
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...
On 7/15/2021 at 11:38 PM, tomasz_be said:

 

Hi all,

If you don't want to send this e-mail each time you add/update a tracking number for a specific order, you can override sendInTransitEmail() function by creating the following file in /override/classes/order/OrderCarrier.php

<?php
/**
 * OrderCarrier override : disable in_transit emails
 *
 */
defined('_PS_VERSION_') or die;
class OrderCarrier extends OrderCarrierCore
{
    /**
     * @param Order $order Required
     *
     * @return bool
     */
    public function sendInTransitEmail($order)
    {
        return true;
    }
}

This function is only called from /src/Adapter/Order/CommandHandler/UpdateOrderShippingDetailsHandler.php

If you clear your Prestashop cache, then it won't send at all the in_transit email when you add/update tracking number.

It works in Prestashop 1.7.7.2 and as it is an override, you won't loose your modification when you update Prestashop.

Hope it helps.

Great, thanks for this.

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...
On 4/19/2021 at 12:13 PM, Nickovitshj said:

For PS 1.7.6.5 

I edited the following:
//if ($order_carrier->sendInTransitEmail($order)) {
if(true) {

Seems to have worked for me.

Thank you, this worked for me (on same version)! 

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 6 months later...

+1 Merci

Ok sur 1.7.8.2

<?php
/**
 * OrderCarrier override : disable in_transit emails
 *
 */
defined('_PS_VERSION_') or die;
class OrderCarrier extends OrderCarrierCore
{
    /**
     * @param Order $order Required
     *
     * @return bool
     */
    public function sendInTransitEmail($order)
    {
        return true;
    }
}

 

Link to comment
Share on other sites

  • 11 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...