Send order status change email with function

  • Posts: 171
  • Thank you received: 9
10 years 3 months ago #168393

-- HikaShop version -- : 2.3.2
-- HikaMarket version -- : 1.4.3
-- Joomla version -- : 3.3

Hi Jerome,

We need to speed up the vendors' frontend confirmation process a bit.
I created a button and connected a function for it in /components/com_hikamarket/controllers/order.php

function jovahagyott_order(){
		$app = JFactory::getApplication();
		$db = JFactory::getDBO();		
		$order_id = JRequest::getVar('order_id');
		$order_number = JRequest::getVar('order_number');
		$query = 'UPDATE '.hikashop_table('order').' SET order_status="confirmed" WHERE order_number='.$db->Quote($order_number);		
		$db->setQuery($query);
		$result = $db->query();
		$redirect_url = JRequest::getVar('redirect_url');
		$app->redirect($redirect_url);
		return true;
	}
}

The buttons in the listing view template are injected in this way:
<?php if($order->order_status == 'created') {?>
 <form id="adminForm_<?php echo $order->order_id; ?>_jovahagyott" action="<?php echo hikashop_currentURL(); ?>" method="post" name="adminForm_<?php echo $order->order_id; ?>_jovahagyott">
                    <button type="submit" class="btn btn-large right" name="jovahagyott_order" value="OK" onclick="var field=document.getElementById('<?php echo $order->order_id; ?>');document.adminForm_<?php echo $order->order_id; ?>_jovahagyott.submit();return false;">OK</button>             
                                 
			                    <input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>"/>
                                            <input type="hidden" name="option" value="<?php echo HIKAMARKET_COMPONENT; ?>" />
                                            <input type="hidden" name="task" value="jovahagyott_order" />
                                            <input type="hidden" name="order_number" value="<?php echo $order->order_number ?>" />
                                            <input type="hidden" name="email" value="1" />
                                            <input type="hidden" name="order_id" value="<?php echo $order->order_id; ?>" />
                                            <input type="hidden" name="ctrl" value="<?php echo JRequest::getCmd('ctrl'); ?>" />
                                            <input type="hidden" name="redirect_url" value="<?php echo hikashop_currentURL(); ?>" />
                                            <?php echo JHTML::_( 'form.token' ); ?>    
                                 </form>  
<?php }?>

It works as we need, the only missing point is to solve somehow to send the order status change notification emails (both to user and vendor) the same way as it sends if we use the frontend status editing in the default way (click on order details, click on edit order status part, click on dropdown to choose status, then click save).

Could you give me a small code hint how should I solve that?

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

  • Posts: 26156
  • Thank you received: 4028
  • MODERATOR
10 years 3 months ago #168399

Hi,

You have to use the HikaShop API if you want to change the order status and trigger the different events (like HikaMarket and his process to link the main order with the sub orders).

// Security stuff
$config = hikamarket::config();
if(!$config->get('frontend_edition',0))
   return false;
if(!hikamarket::loginVendor())
   return false;
if(!hikamarket::acl('order_edit'))
   return false;
$order_id = hikamarket::getCID('order_id');
if(!hikamarket::isVendorOrder($order_id))
   return false;

// Processing stuff
$shopConfig = hikamarket::config(false);
$orderClass = hikamarket::get('shop.class.order');
$o = new stdClass();
$o->order_id = $order_id;
$o->order_status = $shopConfig->get('confirm_status', 'confirmed');
$o->history = new stdClass();
$o->history->history_notified = true;
$o->history->history_type = 'modification';
$orderClass->save($o);
I also recommend you to put a token verification for security purpose.

Regards,

PS : Don't use order_number as identifier, use the order_id.


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: pepecortez

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

  • Posts: 171
  • Thank you received: 9
10 years 3 months ago #168465

Jerome, thanks for the help, and the tips, works great.

Now vendor gets the oder status notification email correctly.
But user, who made the order do not get it. I think user's status email is a hikashop mail, not hikamarket's, maybe that can cause this, isn't it?

Edit: added code you earlier helped me, now user also gets it:

$o->hikamarket->force_email = true;

Thanks again!

Last edit: 10 years 3 months ago by pepecortez.

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

  • Posts: 26156
  • Thank you received: 4028
  • MODERATOR
10 years 3 months ago #168470

Hi,

Right, if the order is a sub order, you have to "force the email" so HikaMarket will allow the user notification.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

Moderators: Obsidev
Time to create page: 0.060 seconds
Powered by Kunena Forum