Set statut programmatically & notify the customer

  • Posts: 14
  • Thank you received: 0
5 years 10 months ago #250797

Hello everybody,
I need help to change statut of an order programmatically, I've search the forum and found a solution here:
www.hikashop.com/forum/development/88577...to-order.html#246491

But my problem is that my customer would like a mail notification for the final customer.

For your information Here in Belgium your bank can give you a text file with all the transactions occurred on your account.
My customer would like to import these files and have a screen to validate the matching with the orders. So he can mark the orders as "confirmed".

Everything is ok, but I can't figure how to also send a mail with that modification.
Thanks in advance.

Last edit: 5 years 10 months ago by sebastienh@alkaonline.be. Reason: Solved

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

  • Posts: 76147
  • Thank you received: 11918
  • MODERATOR
5 years 10 months ago #250801

Hi,

I see what yo'ure trying to do.
It's called bank reconciliation:
en.wikipedia.org/wiki/Bank_reconciliation
It's something you usually do in an accounting software.
So you would import both the HikaShop orders and the bank account exports to the accounting software, and then reconciliate both together in there.

If you want to send a notification email to the customer you'll want to change the code from the other thread to:

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 = new stdClass();
$order->order_id = XXX;
$order->order_status = 'YYY';
$order->history = new stdClass();
$order->history->history_notified = 1;
$orderClass->save($order);

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

  • Posts: 14
  • Thank you received: 0
5 years 10 months ago #250866

Thank a lot for your mail, you're right for the bank reconciliation
I put some screenshot of my dev for information on attachment

Yesterday I found a similar solution by searching in the Helper.
Unfortunatly my mail still not send :(

Here is my code :

if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return false;
	$ids 	= JFactory::getApplication()->input->get('ids',null,null);
	$config = hikashop_config();
	if(sizeof($ids)){
		foreach($ids as $id){
			$orderObj = new stdClass();
			$orderObj->order_id = (int)$id;
			$orderObj->order_status = $config->get('order_confirmed_status', 'confirmed');
			$orderObj->history 	= new stdClass();
			$orderObj->history->history_notified = 1;
			$orderObj->history->history_reason = "CODA Matching";
			$orderObj->history->history_type 	= "modification";
			$orderClass = hikashop_get('class.order');

			$orderClass->save($orderObj);
		}
	}

Last edit: 5 years 10 months ago by sebastienh@alkaonline.be.

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

  • Posts: 76147
  • Thank you received: 11918
  • MODERATOR
5 years 10 months ago #250871

Hi,

I don't see why that wouldn't work.
Do you see the emails in the menu Customers>Emails history ? If you do, then the problem is not with your code or HikaShop but with your email server and you should look in its log.

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

  • Posts: 14
  • Thank you received: 0
5 years 10 months ago #250932

Thanks for your answer.
I do not see the mail in the history.
I wonder if it could be because my script is call by Ajax (via Joomla! com_ajax) an not in an plugin event.

I created a system plugin to add the button that open the modal box, everything is in Javascript and ajax/php (via Joomla! com_ajax).
As the script perfectly change the order status and add the order history using Hikashop API I supposed Ajax is not the problem, but I'm not sure.

Thanks.

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

  • Posts: 76147
  • Thank you received: 11918
  • MODERATOR
5 years 10 months ago #250948

Hi,

Then make sure that you didn't disable the "order status notification" email in the menu System>Emails, and that you have a valid email address for the customer of the order.
Other than that, it could also be a plugin implementing the trigger onAfterOrderUpdate( &$order, &$send_email) and which would set the $send_mail variable to false on your website.

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

  • Posts: 14
  • Thank you received: 0
5 years 10 months ago #251040

Hi thanks for your answer.

The Order status notification mail is active and when I use the dropdown in column orders status on the orders > orders page i receive the mail.
But when I try my code on the same order the status is changed but I don't receive any mail.

:S

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

  • Posts: 76147
  • Thank you received: 11918
  • MODERATOR
5 years 10 months ago #251061

Hi,

I don't see why that would happen then.

You'll have to add debug code in the file administrator/components/com_hikashop/classes/order.php after the call to the onAfterOrderUpdate trigger before the email sending block to understand why it does that in your case.

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

  • Posts: 14
  • Thank you received: 0
5 years 10 months ago #251154

Ok I got some more information.

when I execute the code with an ajax call I got this as answer : JLIB_APPLICATION_ERROR_VIEW_NOT_FOUND

If I comment the line

$orderClass->save($orderObj);
the error disappears and I got my answer... but obviously the order isn't updated.

Is there any restriction of use $orderClass->save($orderObj); in an com_ajax call?

Last edit: 5 years 10 months ago by sebastienh@alkaonline.be.

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

  • Posts: 76147
  • Thank you received: 11918
  • MODERATOR
5 years 10 months ago #251156

Hi,

I don't see why that error would happen. The save doesn't use any view as far as I know. Maybe there is a plugin which implement a trigger like onAfterOrderUpdate and which would create the problem ?
I've actually never used com_ajax. I usually use a system plugin to do ajax requests for a plugin.

The following user(s) said Thank You: sebastienh@alkaonline.be

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

  • Posts: 14
  • Thank you received: 0
5 years 10 months ago #251347

Hi,
Ok thanks for your answer, I'll try to make the call without com_ajax to getting around the problem.

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

  • Posts: 14
  • Thank you received: 0
5 years 10 months ago #252052

Hello,
You're right the problem came by the call of

$orderClass->save($orderObj);
with com_ajax.
I made a simple ajax call and it works fine. Thanks for your help

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

Time to create page: 0.081 seconds
Powered by Kunena Forum