Hook: modifyPaymentOrShippingMethodInfo

Wenn Daten einer Zahlungs-/Versandmethode generiert werden

/*
 * -- Registration: --
 * $GLOBALS['MERCONIS_HOOKS']['modifyPaymentOrShippingMethodInfo'][] = array('myMerconisHookClass', 'myModifyPaymentOrShippingMethodInfo');
 *
 * -- Invocation: --
 * After the method info has been processed and before the method info is used by other functions
 *
 * -- Parameters: --
 *	1. $arrMethodInfo - an array holding the method info
 *	2. $type - the method type (shipping or payment)
 *  
 * -- Return value: --
 * $arrMethodInfo - the possibly manipulated method info
 *
 * -- Objective: --
 * e.g. manipulate the method info, most likely in order to implement a custom method fee calculation
 *
 */

public function myModifyPaymentOrShippingMethodInfo($arrMethodInfo, $type) {

	/*
	 * If the logic of this function depends on customer data, e.g. the customers postal code, we can get it like this:
	 *
	 * $this->import('ls_shop_checkoutData');
	 * $customerPostalCode = $this->ls_shop_checkoutData->arrCheckoutData['arrCustomerData']['postal']['value'];
	 */
	
	/*
	 * If the logic of this function depends on the current cart calculation, we can get it like this:
	 *
	 * $this->import('ls_shop_cartX');
	 * $calculation = $this->ls_shop_cartX->calculation;
	 */
	
	/*
	 * If the logic of this function depends on specific details of the products that are currently contained in the cart,
	 * we can get this information like this:
	 *
	 * $this->import('ls_shop_cartX');
	 * $cartItems = $this->ls_shop_cartX->itemsExtended;
	 * foreach ($cartItems as $cartItem) {
	 *                     // $cartItem['objProduct'] holds a product object that can be used just like the product object available e.g. in product details templates.
	 *                     $productTitle = $cartItem['objProduct']->_title;
	 * }
	 *
	 */
	
	/*
	 * This hook function gets called every time a method information for a shipping or
	 * payment method is requested. Since we only want to manipulate the fee calculation
	 * for a specific shipping method we have to abort this function by returning the
	 * unmodified $arrMethodInfo if the currently requested method is not the one we want
	 */
	
	if ($type != 'shipping' || $arrMethodInfo['id'] != 1) {
		return $arrMethodInfo;
	}
	
	/*
	 * If we only want to modify the already calculated fee given in $arrMethodInfo
	 * it is important to know that this fee value is already a "display price" which
	 * means that the price is already calculated as a net or gross price depending
	 * on what the customer should see.
	 *
	 * Example:
	 *           - In the backend/database we define all prices as net prices.
	 *  - The fee for a shipping method is 10 EUR net and it is taxed with 19 % VAT
	 *  - The customer is not a business customer so he should see gross prices, in this case 10 EUR + 1.90 EUR VAT = 11.90 EUR
	 *  - The fee contained in $arrMethodInfo is the display price 11.90 EUR
	 *
	 * When programming this fee calculation we don't know if the prices are stored as net or gross prices in the database
	 * and whether the customer sees net or gross prices but it does not matter because we know that $arrMethodInfo['feePrice']
	 * holds the correct display price.
	 *
	 * So, if we want to double the fee if it is after 6 pm but before 10 pm, we can simply multiply the fee by 2.
	 *
	 */
	
	if (date(G) >= 18 && date(G) < 22) {
		$arrMethodInfo['feePrice'] = $arrMethodInfo['feePrice'] * 2;
		
		return $arrMethodInfo;
	}
	
	/*
	 * If we want to return a special fee if it is after 10 pm and we want to hardcode this value right
	 * here in this function we have to make sure that we use a net or gross price depending on what we
	 * use in the backend/database and that we convert this value into a display price. Because we
	 * don't know whether the customer sees net or gross prices, we use the function "getDisplayPrice()"
	 * which takes care of the correct conversion. The first parameter is the price that we want to convert
	 * and the second parameter is the tax rate for the shipping or payment method. The third parameter has
	 * to be set to false in this case.
	 */
	
	else if (date(G) >= 22) {
		$this->import('ls_shop_controller');
		$arrMethodInfo['feePrice'] = $this->ls_shop_controller->getDisplayPrice(35, $arrMethodInfo['steuersatz'], false);
		
		return $arrMethodInfo;
	}
	
	/*
	 * If it is before 6 pm we do not manipulate the fee and therefore we return
	 * the unmodified $arrMethodInfo.
	 */
	
	else {
	
		return $arrMethodInfo;
	}
}