Sending customer email when updating order status

  • Posts: 7
  • Thank you received: 0
7 months 2 weeks ago #293455

-- HikaShop version -- : 3.4
-- Joomla version -- : 3.8.8
-- PHP version -- : 5.6
-- Error-message(debug-mod must be tuned on) -- : No errors

$orderId = 20421;
$orderClass = hikashop_get('class.order');
$fullOrder = $orderClass->loadFullOrder((int)$orderId, true, false);

$orderObj = new stdClass();
$orderObj->order_status = "shipped";
$orderObj->order_id = $fullOrder->order_id;
$orderObj->history = new stdClass();
$orderObj->history->history_notified = 1;
$orderClass->save($orderObj);

I would expect this to send an email to the customer? But no emails are being sent (they do not appear in the customer emails history).
If I change it manually through the shop then it works when I tick (notify customer).

Any advice?

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

  • Posts: 11898
  • Thank you received: 1642
  • MODERATOR
7 months 2 weeks ago #293460

Hello,

Can you check that the "Order status notification" email is published via "Hikashop->System->Emails" ?

Thank you.

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

  • Posts: 7
  • Thank you received: 0
7 months 2 weeks ago #293485

Hello

Yeap it is published. Emails work fine when setting the status manually but not through the php script.

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

  • Posts: 1995
  • Thank you received: 268
  • MODERATOR
7 months 1 week ago #293514

Hello,

Can you check that your order have switch to a confirmed status ?
If not, maybe the issue isn't starting with Email processing but with Payment method or Order status configuration or the way you process your test (like a payment method isn't able to switch status on localhost or else...)

The logical chain is like this :
Payment servers send notifications => 2° Payment method switch the order status (if configuration fit this and order had succeed) => 3° HikaShop switch the Order statuts => Email is sent.

Hope this will help you to move forward.
Regards

Last Edit: 7 months 1 week ago by Philip.

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

  • Posts: 7
  • Thank you received: 0
7 months 1 week ago #293529

Hello,

Thank you for the reply
I'll explain a bit more on the process at the moment.

Order gets created and updates to 'Confirmed' when paid for (all works fine, emails are sent etc..)
Plugin is hooked on onAfterOrderUpdate and gets the orderId and cURL posts it to another script (script pulls full order, formats a new object to how I need it with the order details and posts it off site) Does not make any changes or updates to the order

Another script is setup to basically update the orders status:
It loads the full order and makes a change to the status if required.

Everything works perfectly fine, script changes order status to 'Shipped' - adds tracking ID to the history etc all updates and reflects on the system.

The only thing it is not doing is sending the email to say 'You're order is now shipped' etc.

// Edit

Just to add to this, the hikashop_history table is updating correctly, showing new_status = shipped and notified = 1

Thanks

Last Edit: 7 months 1 week ago by turfymurphy.

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

  • Posts: 64453
  • Thank you received: 9307
  • MODERATOR
7 months 1 week ago #293532

Hi,

Ok, so do you get the email that should be sent in the "Customer>Emails history" section of the shop ?
Also, in the trigger onAfterOrderUpdate, the second parameter $send_email can be set to false to prevent the sending of the notification.
So make sure that you're not doing that.
In fact, you could even force that variable to true in order to see if you correctly get the email or not.

Last Edit: 7 months 1 week ago by nicolas.

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

  • Posts: 7
  • Thank you received: 0
7 months 1 week ago #293571

Hello,

There are no entries in the Emails History for that order (for the status modification) the normal create/confirmed are there but not my update.
$send_email is not used at all in the plugin, so I assume default of true?.
I'll try and force it to true.

Is there any manual way I can send the email? I have read some threads about the mail class and loading a notification?

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

  • Posts: 64453
  • Thank you received: 9307
  • MODERATOR
7 months 1 week ago #293587

Hi,

Default is the value of $orderObj->history->history_notified, and any plugin integrating with onAfterOrderUpdate can change it.

You should be able to use something like that:

$orderClass = hikashop_get('class.order');
$order = $orderClass->loadNotification((int)$order_id, 'order_status_notification');
$mailClass = hikashop_get('class.mail');
$mailClass->sendMail($order->mail);

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

  • Posts: 7
  • Thank you received: 0
7 months 1 week ago #293597

Also just to clarify, this can be ran from an external script which is loading the Joomla framework & the Hikashop helpers?.
The actions I am taking on updating the order etc do not happen within a plugin, it is external.

Last Edit: 7 months 1 week ago by turfymurphy.

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

  • Posts: 64453
  • Thank you received: 9307
  • MODERATOR
7 months 1 week ago #293605

Hi,

As long as you load joomla and HikaShop properly before, it should work fine yes.

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

  • Posts: 7
  • Thank you received: 0
7 months 1 week ago #293645

Hello,

I have noticed that when I put the ->sendMail code inside the plugin it works and sends two emails! (Don't really understand why two).

<?php
define('_JEXEC', 1);
define('JPATH_BASE', '../../../');

require_once JPATH_BASE . 'includes/defines.php';
require_once JPATH_BASE . 'includes/framework.php';

$app = JFactory::getApplication('site');

if(!defined('DS'))
    define('DS', DIRECTORY_SEPARATOR);
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;

Is this all I need to work with the hikashop? loadFullOrder etc all works fine but am I missing something that stops the emails/notifications from being sent?
$orderClass = hikashop_get('class.order');
$order = $orderClass->loadNotification((int)$order_id, 'order_status_notification');
$mailClass = hikashop_get('class.mail');
$mailClass->sendMail($order->mail);

Above code works inside plugin but not in my own script

Thanks for your help :)

## EDIT

I have added some logging to my file and it doesn't seem to get past this block:
$orderClass = hikashop_get('class.order');
                $order = $orderClass->loadNotification((int)$result->orderid, 'order_status_notification');
                $mailClass = hikashop_get('class.mail');
                $mailClass->sendMail($order->mail);

Is there anything I am missing to be able to use these functions in an external file? :)

Last Edit: 7 months 1 week ago by turfymurphy.

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

  • Posts: 64453
  • Thank you received: 9307
  • MODERATOR
7 months 1 week ago #293678

Hi,

I did a test on my end with that code:

<?php
define('_JEXEC', 1);
define('JPATH_BASE', dirname(__FILE__) );

require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';

// Instantiate the application.
$app = JFactory::getApplication('site');
// Initialise the application.
$app->initialise();

if(!defined('DS'))
    define('DS', DIRECTORY_SEPARATOR);
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;

$orderClass = hikashop_get('class.order');
$order = $orderClass->loadNotification(159, 'order_status_notification');
$mailClass = hikashop_get('class.mail');
$mailClass->sendMail($order->mail);
And I got the email sent for the order 159 when calling the PHP file with that code. So it works for me.
The Joomla code comes from: www.simbunch.com/blog/141-instantiate-in...n-an-external-script

The following user(s) said Thank You: turfymurphy

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

  • Posts: 7
  • Thank you received: 0
7 months 1 week ago #293679

OK Great, it seems to work outside of the plugin directory, I placed the file in the main root public_html folder and it works fine.

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

Time to create page: 0.114 seconds
Powered by Kunena Forum