[SOLVED] Conditional admin notification recipients

  • Posts: 194
  • Thank you received: 13
  • Hikashop Business
9 years 2 months ago #188463

-- HikaShop version -- : 2.3.5
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.4
-- Error-message(debug-mod must be tuned on) -- : None.

Is it currently possible to have a conditional "to address" for the Order creation admin notifications emails? I thought this may be possible if the email addresses were values in a custom field, and then I could place the custom field 'tag' or 'placeholder' in the Configuration for "Order creation admin notifications email address"?

This is the scenario:
Products are purchased online and picked up in a local store of the customer's choice. There are 5 local stores and each has an assigned email address. The local store that is selected by the customer during checkout needs to receive an email notification of the order.


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters
Last edit: 7 years 11 months ago by 3by400.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 2 months ago #188499

Hi,

You can try with that code at the end of the preload of your emails that you can edit via the menu System>Emails :

// Do some checks on the shipping address which should be the store address
if($data->cart->shipping_address == 'address 1'){
    $this->mailer->addBCC('store1@address.com');
}elseif($data->cart->shipping_address == 'address 2'){
    $this->mailer->addBCC('store2@address.com');
}
// etc.

The following user(s) said Thank You: 3by400

Please Log in or Create an account to join the conversation.

  • Posts: 194
  • Thank you received: 13
  • Hikashop Business
9 years 1 month ago #189456

Thanks, Xavier!


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

Please Log in or Create an account to join the conversation.

  • Posts: 194
  • Thank you received: 13
  • Hikashop Business
7 years 11 months ago #235375

Hi Xavier -

We've tried to implement this, but the bcc emails are not being generated. We have a custom field single selection drop down with the name 'store'. The values of the drop down options are 1 through 5 and the titles are the name of the stores (eg. Highland Park).

Then we've added this code to the very bottom of the "Preload Version" in the Order Status Notification email:

if($data->cart->store == '1'){
    $this->mailer->addBCC('email@email.com,email2@email.com');
}elseif($data->cart->store == '2'){
    $this->mailer->addBCC('email3@email.com,email4@email.com');
}


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters
Last edit: 7 years 11 months ago by 3by400.

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
7 years 11 months ago #235398

Hi,

This would only work if the custom field is of the table "order" and has its column name set to "store".
Could you provide a screenshot of the settings of your custom field ?

Please Log in or Create an account to join the conversation.

  • Posts: 194
  • Thank you received: 13
  • Hikashop Business
7 years 11 months ago #235468

Here you go ..


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters
Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
7 years 11 months ago #235796

Hi,

That should be working, what if you add that code at the end of hte preload part:

var_dump($data->cart->store);

Then in order management in backend, try to change an order status from the listing and in the popup enable the "notify customer" option, that will display the content of the email and you will see the value of $data->cart->store.

Please Log in or Create an account to join the conversation.

  • Posts: 194
  • Thank you received: 13
  • Hikashop Business
7 years 11 months ago #236020

Xavier -

This was the output - string(1) "1"

Initially, I received an error on the backend status change popup saying the email was invalid. It apparently would not accept the comma separated emails. Is there a way around that? I need to specify two email addresses, as in my example in the previous post.

I removed the second email, and then received the 'string(1) "1"' output on the backend order status change email, however, on the frontend when I try to submit an order I'm redirected to an error page that says "0 invalid address customer_name".


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
7 years 11 months ago #236066

The error "0 invalid address" comes from Joomla 3.5.1.
You would need to update your HikaShop to fix it:
www.hikashop.com/forum/checkout/883603-4...-process.html#235445

Please Log in or Create an account to join the conversation.

  • Posts: 194
  • Thank you received: 13
  • Hikashop Business
7 years 11 months ago #236069

Ok, Hikashop is upgraded so the "0 invalid address" issue is resolved. Thanks!

However, we are still not getting the bcc email. I've even added a 'catch all' else at the end in the event the value isn't matching any of the elseif's and we're still not getting the email.

Will the code being in the Preload version execute on the frontend when an order is confirmed automatically by the payment method? We have tested using the frotend as well as changing the order status from the backend. Neither result in a bcc email.


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

Please Log in or Create an account to join the conversation.

  • Posts: 194
  • Thank you received: 13
  • Hikashop Business
7 years 11 months ago #236115

I found this - www.hikashop.com/forum/4-how-to/872622-a...on-email.html#179068

So I tried this:

if($data->cart->store == '1') {
    $mail->bcc_email = array('email@email.com','email2@email.com');
} elseif($data->cart->store == '2') {
    $mail->bcc_email = array('email3@email.com','email4@email.com');

This worked.


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters
The following user(s) said Thank You: Mohamed Thelji

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
7 years 11 months ago #236081

Hi,

From what I understand BCC and CC won't work on windows with the "mail" sending method of Joomla:
phpmailer.worxware.com/?pg=methods
So would it come from that ?

Please Log in or Create an account to join the conversation.

  • Posts: 194
  • Thank you received: 13
  • Hikashop Business
7 years 11 months ago #236196

We use a Linux server, however, our email is routed through Mandrill so using $this->$mailer->Bcc wouldn't work.


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters
Last edit: 7 years 11 months ago by 3by400.

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
7 years 11 months ago #236203

Mmm. Why using $this->mailer->Bcc wouldn't work because of Mandrill ?

Please Log in or Create an account to join the conversation.

  • Posts: 194
  • Thank you received: 13
  • Hikashop Business
7 years 11 months ago #236395

Doesn't $this->mailer->Bcc utilize PHPMailer? We have PHPMailer disabled on our server, and route all Joomla site traffic through SMTP (Mandrill).


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
7 years 11 months ago #236397

$this->mailer->Bcc indeed uses PHPMailer as does $mail->bcc_email.
You can't disable PHPMailer. It's a library included by Joomla and it's used for sending all the emails sent by Joomla. There is no option to disable it in Joomla.
Joomla will then use PHPMailer to either use the "mail" system of your server, or connect to a SMTP server.

Please Log in or Create an account to join the conversation.

Time to create page: 0.097 seconds
Powered by Kunena Forum