Hello,
I'm creating a plugin that hooks onto plgVmOnUpdateOrderShipment and generates a tracking code when the order status changes to "Shipped".
I'm looking for a way to add that tracking code to the email that is sent in that step.
Ideally I would like to add it to the "Comments" section but I can't find how to access that.
I noticed that the variable $data is passed by reference to plgVmOnUpdateOrderShipment so I looked into that thinking there might be a way to add a comment through that but it doesn't seem to contain something that would help.
Any ideas? I'm on Virtuemart 3.4.2
Thanks
you produce your own tracking code?
how is the status set to shipped? manually? then just add the tracking code to the comment box .. sends with the email
if programatically I do something like below with a plugin triggered from e.g. function plgVmOnUpdateOrderPayment ($data,$old_order_status){
although really depends on how your workflow is
$modelOrder = VmModel::getModel ('orders');
$order2 = array();
$order2['customer_notified'] = 1;
$order2['order_status'] = $status2;
$order2['comments'] = 'Your Tracking Link: '.$sale_result['warehouse_tracking_link'];
$modelOrder->updateStatusForOneOrder ($data->virtuemart_order_id, $order2, FALSE);
Thanks for your response.
The order status is manually changed to "Shipped", plgVmOnUpdateOrderShipment is fired and then in that function I generate the tracking code.
At this point I'm looking for a way to add that code to the comment box programmatically. Basically what you're doing in your code but without having to re-update it with updateStatusForOneOrder.
Quotewithout having to re-update it with updateStatusForOneOrder.
if u don't how do u fill the field, fir the email etc etc
just live with doing it twice -- manually set to "G" -> generate - then the rest of the code to set it to shipped programatically
Hi, thanks for your help. I ended up using your code.
Quick followup, the email is sent and it contains the tracking code info, however it seems it uses the raw email template rather than the normal html. Any idea what could be causing this?
Edit: This only happens if I try to update the order status from a third page, if I use the same code plgVmOnUpdateOrderShipment it displays the html template.
To explain better, I have an admin component installed which I access through
https://DOMAIN/administrator/index.php?option=com_PLUGIN&action=issue&orderNo=155
When this url is accessed, I generate the tracking code, change the order status to shipped and send the email (the last two parts using your code). When this happens the email sent is in plaintext.
If I copy the code to plgVmOnUpdateOrderShipment of my other plugin, when the order status changes the email sent uses the normal html template.
Any thoughts?
Edit2: managed to fix it. First off, I included the virtuemart config helper and order model files and initialize VmConfig
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR .'/components/com_virtuemart/helpers/config.php');
if (!class_exists ('VirtueMartModelOrders')) require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php');
$config = VmConfig::loadConfig();
This however stopped the emails from being sent, after some digging it seems useDefaultEmailOrderStatus in the orders model was not set to False via updateStatusForOneOrder, I'm not sure why this happens though so if anyone knows, please let me know.
To work around that, I changed updateStatusForOneOrder to updateOrderStatus
$order2 = array();
$order2['customer_notified'] = 1;
$order2['order_status'] = "S";
$order2['comments'] = 'Your tracking code is XXXXXXX';
$order_model->updateOrderStatus(array(0=>$order2),$myorder['details']['BT']->virtuemart_order_id);
the "array(0=>$order2)" is another workaround because updateOrderStatus expects the first parameter to be an array of type array('orderNo'=>OrderInstance), you could set 'orderNo' to the actual order number but updateOrderStatus takes care of it internally as well.
Again, if anyone has any idea why using updateStatusForOneOrder does not set useDefaultEmailOrderStatus to false please let me know.