How to programatically send order shipped email

  • Posts: 27
  • Thank you received: 4
9 years 6 months ago #229553

-- HikaShop version -- : 2.6.1
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.3.10
-- Browser(s) name and version -- : Firefox 38.0.5

I'm aware of the backend feature to change an order's status to 'shipped' and it will load a modal, which will ask if you want to send an email.
However, how can I make a PHP call to this same exact function? I want to be able to change the order's status and send an email through a plugin. This plugin is inside the Hikashop plugin group.

I did some more research and found the following options:

  • hikashopPaymentPlugin->modifyOrder. However, my plugin is not a derived class of hikashopPlugin
  • OrderController->savechangestatus. However, this relies on POST data, which I don't have from a plugin call

Last edit: 9 years 6 months ago by fengel.

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

  • Posts: 84233
  • Thank you received: 13674
  • MODERATOR
9 years 6 months ago #229568

Hi,

Copy the function modifyOrder from the file adminsitrator/components/com_hikashop/helpers/helper.php to your plugin class and you'll be able to use the $this->modifyOrder() call in the same maner as the payment plugins.
That's the simplest.

The following user(s) said Thank You: fengel

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

  • Posts: 27
  • Thank you received: 4
9 years 6 months ago #229633

Thank you for replying. I did some tinkering and reached this solution:

// Load order
$orderClass = hikashop_get('class.order');
$order = $orderClass->loadFullOrder($orderid);

// These properties should be removed before attempting to save the order
unset($order->order_subtotal);
unset($order->order_subtotal_no_vat);

// Change order status
$order->order_status = 'shipped';

// Set email to user's language
$langparams = json_decode($order->customer->params);
$lang = isset($langparams->language) ? $langparams->language : null;
$langObj = JFactory::getLanguage($lang);
$langObj->load('com_hikashop', JPATH_SITE);

// Set new history entry
$order->history = new stdClass();
$order->history->history_notified = '1';
$order->history->history_type = 'shipment';

// Save order to DB
$orderClass->save($order);

It seems to work fine.
The function modifyOrder seems to have a lot of payment-flow code which isn't relevant to my plugin. I compared the above code snippet with modifyOrder and the above seems to be a boiled down version of it.

Thank you again for your help!

The following user(s) said Thank You: nicolas

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

Time to create page: 0.047 seconds
Powered by Kunena Forum