Orders Status CSV Import and email trigger

Hi,

We’re evaluating cs-cart for customers and so far so good. Excellent system.

The import/export options are very flexible but can someone answer the following question please.



If we import a csv with the “order status” field updated it uploads to the server and correctly updates the cs-cart orders status which is fine.



Is there a built in way for the import “order status” routine to also fire the “send email confirmation” options as an order status is changed ?



If not, can someone point me in the rights direction within the php file as to where this functionality if found.



Thanks in advance,

Derek

Not clear why you’d be importing orders (other than once to establish a history). Please describe your objective/strategy in more detail.



But to see all order status changes…



Look in core/fn.common.php.

The function fn_change_order_status() has a hook in it of:

set_hook(‘change_order_status’, $old_status, $new_status, $order_info);



You need to setup a handler for this hook in your addons/my_changes/init.php file of fn_register_hooks(‘change_order_status’);



You then need to add a function to addons/my_changes/func.php of:


function fn_my_changes_change_order_status($statusTo, $statusFrom, &$orderInfo) {
// your code here
}

We are trying to import orders to change the status to show that the orders has been shipped from a 3rd party system and would like the email to be generated on update of the status.



The file core/fn.common.php does not have the function fn_change_order_status().



Regards,

Mark



Version: 2.1.0

[quote name=‘MarkPountney’]We are trying to import orders to change the status to show that the orders has been shipped from a 3rd party system and would like the email to be generated on update of the status.



The file core/fn.common.php does not have the function fn_change_order_status().



Regards,

Mark



Version: 2.1.0[/QUOTE]



If I hear you correctly, this is what you want to do:


  1. Import orders.
  2. If the status is changed, the same event should be triggered as if you changed the status by hand in the “Orders” tab.



    What this involves, as was pointed out earlier, is a line of code to check the “status” field as the orders are imported. If the status field is set to a certain status then the same function used on the “View orders” page is called.



    I’m not sure how complicated this is, however. Although, on the surface, it doesn’t seem too hard, it could be alot more complicated than it looks.



    Perhaps someone would volunteer to check the function called when an order status is changed and what it needs when called.

In your addons/my_changes/init.php add this line:


fn_register_hooks( 'change_order_status');




Then in your addons/my_changes/func.php add:


define('myImportStatus', '?'); // replace ? with the status char you want
function fn_my_changes_change_order_status($new, $old, $o_info, &$notification) {
if( $new == myImportStatus && $new != $old)
$notification['C'] = true;
}




That should do it. This is off the top of my head and has not been checked for syntax errors or the like.

Hi,



Thanks for the help, I have tried the code and I want the email to be changed when the status is completed - Status ‘C’ and cancelled - Status ‘I’



I implemented the code and I still don’t get any email.



Can you advise how to debug function?



Thanks,

Mark

Check to see if the status you’re changing the order to is set to send emails to the “orders deparement”. Then make sure the orders email is set right.

Hmm… This should force the “Customer” notification to be sent based on the condition that is captured in the change_order_status hook. If you change the line of:

$notification[‘C’] = true;

to

$notification[‘A’] = true;



then you should get an email sent to the “orders department” email setting in your store.



Unfortunately, cs-cart provides no logging of emails sent from the cart so there’s no real way to track this other than to add debugging code. We do have a cheap ($20) email tracking addon that will make log entries for outbound emails sent from the cart. You can take a look at the documentation in the Attachments tab of the product detail page (http://www.ez-ms.com/addonproducts/email-logging.html).



But making the above change to the code should make a suitable test. You can also change it to read:


if( $new == myImportStatus && $new != $old)
$notification['C'] = true;
file_put_contents("./debug.log", __FUNCTION__.": ".date("r").", notification:".print_r($notification,true), FILE_APPEND);
}




Thsi will output lines to the file debug.log in the root of your store. You can then review that file to see what the values are for $notification for the status you’ve captured.

Hi,



I implemented the debug code. The results where


fn_my_changes_change_order_status: Tue, 31 Aug 2010 12:49:01 +0100, notification:Array
(
[C] => 1
[A] => 1
)
New: I Old: C




The log was written to ONLY when the order status was changed using the front end and not via the import/export routine.



I moved the debug code out of the if condition just to see if it was getting triggered and I don’t think it is.



Is the Change Order Status hook still available in v2.1.0???



Thanks,

Mark

As far as I know, no hooks have been eliminated in 2.1 (that would be a very bad choice on cs-cart’s part). However, many hooks have had parameters added over the release history. But these have always been “additive” as far as I know.



The debug output looks correct (the ‘A’ is true and the ‘C’ is true).



ANY change to order_status goes through fn_change_order_status() and therefore this hook will always be called regardless if done manually or via an import or other API. That’s why I suggested using the order status hook and then forcing the notification…



If you change the debugging output to show what the value is of $notifications when the function is called, what does it show? It should either show “array()” or [‘C’]=>

[‘A’]=>

(indicating false if you do not have notify customer and notify orders department set for that particular status change)…

define('myImportStatus', 'C'); // replace ? with the status char you want
function fn_my_changes_change_order_status($new, $old, $o_info, &$notification) {
file_put_contents("./log/debug.log", __FUNCTION__.": ".date("r").", pre notification:".print_r($notification,true)." New: ".print_r($new, true)." Old: ".print_r($old, true)."\n", FILE_APPEND);
if($new == myImportStatus && $new != $old) {
$notification['C'] = true;
file_put_contents("./log/debug.log", __FUNCTION__.": ".date("r").", post notification:".print_r($notification,true)." New: ".print_r($new, true)." Old: ".print_r($old, true)."\n", FILE_APPEND);
}
}
?>




Produces the following log file. The log file is only created when a manual change is done through the web user interface and not the Import/Export procedures.


fn_my_changes_change_order_status: Wed, 01 Sep 2010 14:31:07 +0100, pre notification:Array
(
[C] => 1
[A] => 1
)
New: I Old: C




This log is when I reset the status to cancelled using the administration panel. Nothing else gets written to log when the Import Orders procedure is run.



Do you have any other ideas?



Thanks,



Mark

Hi Mark,



I’m sorry, but I’m fresh out of ideas… I can only assume that the order import is setting the “status” value directly in the DB rather than using the fn_change_order_status() (provide an API but then don’t use it). You can file it as a bug, but good luck getting it fixed.



The exim code is very complicated to follow. But you might be able to dig something out of schemas/exim to tell it to use the fn_change_order_status() function rather than updating the DB directly.

Hi,



Thanks for much for all your help and guidance. I will get a bug/support call log.

I will post an update when I get one.



Many Thanks,

Mark

I have had a response back for csc support and they say the hook has not been included in the import/export procedures.



Mark:(