Author Topic: Adding content in shipping confirmation email  (Read 231 times)

kloukas

  • Beginner
  • *
  • Posts: 3
  • A beginner
Adding content in shipping confirmation email
« on: December 21, 2018, 10:03:14 am »
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


GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8678
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.14
Re: Adding content in shipping confirmation email
« Reply #1 on: December 21, 2018, 12:34:19 pm »
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

Code: [Select]


$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);
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

kloukas

  • Beginner
  • *
  • Posts: 3
  • A beginner
Re: Adding content in shipping confirmation email
« Reply #2 on: December 21, 2018, 12:49:45 pm »
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.



GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8678
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.14
Re: Adding content in shipping confirmation email
« Reply #3 on: December 21, 2018, 13:49:52 pm »
Quote
without 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
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

kloukas

  • Beginner
  • *
  • Posts: 3
  • A beginner
Re: Adding content in shipping confirmation email
« Reply #4 on: December 24, 2018, 11:08:52 am »
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

Code: [Select]
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

Code: [Select]
$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.