Hook: beforeSendingOrderMessage

Bevor das MERCONIS-Nachrichtensystem eine Nachricht versendet

/*
 * -- Registration: --
 * $GLOBALS['MERCONIS_HOOKS']['beforeSendingOrderMessage'][] = array('myMerconisHookClass', 'myBeforeSendingOrderMessage');
 *
 * -- Invocation: --
 * Before sending an order message
 *
 * -- Parameters: --
 *	1. $arrMessageModel - the message model details
 *	2. $arrOrder - the order details
 *  
 * -- Return value: --
 * $arrMessageModel - the possibly manipulated message model details or null, if the message should not be sent
 *
 * -- Objective: --
 * e.g. manipulate the message model details or prevent a message from being sent under certain circumstances
 *
 */

public function myBeforeSendingOrderMessage($arrMessageModel, $arrOrder) {

	/*
	 * In this example we have two message types which would be used as order confirmations.
	 * One message type should only be used on fridays because it contains a text regarding
	 * the coming weekend and the other should be used on every other day.
	 * This hook would be called for both of them and it could decide which one should actually be sent.
	 */
	
	$blnIsFriday = date('D') == 'Fri';
	
	/*
	 * the parent id of the message model is the id of a message type. In this example the
	 * message type with the id 5 is the one to send on friday and the message type with
	 * the id 2 is the one to send on every other day.
	 */
	
	if ($arrMessageModel['pid'] == 5 && !$blnIsFriday) {
		return null;
	}
	
	if ($arrMessageModel['pid'] == 2 && $blnIsFriday) {
		return null;
	}
	
	/*
	 * In the second part of this example, we replace a custom wildcard with a coupon code
	 * if the order amount is bigger than 500. If we modify multilanguage data, we have to make
	 * sure to deal with the contents of the $arrMessageModel['multilanguage'] array.
	 */
	
	$couponCode = $arrOrder['total'] >= 500 ? 'COUPONCODE500' : '';
	$arrMessageModel['multilanguage']['content_html'] = preg_replace('/(##bigBuyerCouponCode##)|(##bigBuyerCouponCode##)/siU', $couponCode, $arrMessageModel['multilanguage']['content_html']);
	$arrMessageModel['multilanguage']['content_rawtext'] = preg_replace('/(##bigBuyerCouponCode##)|(##bigBuyerCouponCode##)/siU', $couponCode, $arrMessageModel['multilanguage']['content_rawtext']);
	
	return $arrMessageModel;
}