Index: branches/5.2.x/units/orders/orders_tag_processor.php =================================================================== diff -u -N -r14816 -r14821 --- branches/5.2.x/units/orders/orders_tag_processor.php (.../orders_tag_processor.php) (revision 14816) +++ branches/5.2.x/units/orders/orders_tag_processor.php (.../orders_tag_processor.php) (revision 14821) @@ -1,6 +1,6 @@ $row) { // if shipping types are limited - get the types $types = $row['ShippingLimitation'] != '' ? explode('|', substr($row['ShippingLimitation'], 1, -1)) : Array ('ANY'); @@ -1084,9 +1082,9 @@ $object =& $this->getObject($params); /* @var $object OrdersItem */ - $gw_data = $object->getGatewayData($params['payment_type_id']); - + $gw_data = $object->getGatewayData( isset($params['payment_type_id']) ? $params['payment_type_id'] : null ); $this->Application->registerClass( $gw_data['ClassName'], GW_CLASS_PATH.'/'.$gw_data['ClassFile'] ); + $gateway_object =& $this->Application->recallObject( $gw_data['ClassName'] ); /* @var $gateway_object kGWBase */ @@ -1098,22 +1096,25 @@ $object =& $this->getObject($params); /* @var $object OrdersItem */ - $gw_data = $object->getGatewayData(array_key_exists('payment_type_id', $params) ? $params['payment_type_id'] : null); - + $gw_data = $object->getGatewayData( isset($params['payment_type_id']) ? $params['payment_type_id'] : null ); $this->Application->registerClass( $gw_data['ClassName'], GW_CLASS_PATH.'/'.$gw_data['ClassFile'] ); + $gateway_object =& $this->Application->recallObject( $gw_data['ClassName'] ); + /* @var $gateway_object kGWBase */ - $tpl = ''."\n"; + $tpl = ''."\n"; $hidden_fields = $gateway_object->getHiddenFields($object->GetFieldValues(), $params, $gw_data['gw_params']); - $ret = ''; - if (!is_array($hidden_fields)) { + if ( !is_array($hidden_fields) ) { return $hidden_fields; } - foreach($hidden_fields as $hidden_name => $hidden_value) - { + + $ret = ''; + + foreach ($hidden_fields as $hidden_name => $hidden_value) { $ret .= sprintf($tpl, $hidden_name, $hidden_value); } + return $ret; } @@ -1122,10 +1123,11 @@ $object =& $this->getObject($params); /* @var $object OrdersItem */ - $gw_data = $object->getGatewayData(); - + $gw_data = $object->getGatewayData( isset($params['payment_type_id']) ? $params['payment_type_id'] : null ); $this->Application->registerClass( $gw_data['ClassName'], GW_CLASS_PATH.'/'.$gw_data['ClassFile'] ); + $gateway_object =& $this->Application->recallObject( $gw_data['ClassName'] ); + /* @var $gateway_object kGWBase */ return $gateway_object->NeedPlaceButton($object->GetFieldValues(), $params, $gw_data['gw_params']); } @@ -1277,51 +1279,77 @@ $esender->Deliver(); } - function PrintTotals($params) + /** + * Prints order totals + * + * @param Array $params + * @return string + * @access protected + */ + protected function PrintTotals($params) { - $order =& $this->getObject($params); + $object =& $this->getObject($params); + /* @var $object OrdersItem */ - $totals = array(); - if (ABS($order->GetDBField('SubTotal') - $order->GetDBField('AmountWithoutVAT')) > 0.01) { - $totals[] = 'products'; + if ( isset($params['element_order']) ) { + // TODO: implement } + else { + // default element order + $element_order = Array ( + 'products' => 1, 'return' => 4, 'sub_total' => 5, 'discount' => 6, + 'vat' => 7, 'shipping' => 8, 'processing' => 9, + ); - $has_tangible = $this->OrderHasTangibleItems($params); + // show shipping & processing costs before tax, when they are taxable + if ( $object->GetDBField('ShippingTaxable') ) { + $element_order['shipping'] = 2; + } - if ($has_tangible && $order->GetDBField('ShippingTaxable')) { + if ( $object->GetDBField('ProcessingTaxable') ) { + $element_order['processing'] = 3; + } + } + + $totals = Array (); + + if ( abs($object->GetDBField('SubTotal') - $object->GetDBField('AmountWithoutVAT')) > 0.01 ) { + $totals[] = 'products'; + } + + if ( $this->OrderHasTangibleItems($params) ) { $totals[] = 'shipping'; } - if ($order->GetDBField('ProcessingFee') > 0 && $order->GetDBField('ProcessingTaxable')) { + if ( $object->GetDBField('ProcessingFee') > 0 ) { $totals[] = 'processing'; } - if ($order->GetDBField('ReturnTotal') > 0 && $order->GetDBField('ReturnTotal')) { + if ( $object->GetDBField('ReturnTotal') > 0 ) { $totals[] = 'return'; } + if ( $this->HasDiscount($params) ) { + $totals[] = 'discount'; + } + $totals[] = 'sub_total'; - if ($order->GetDBField('VAT') > 0) { + if ( $object->GetDBField('VAT') > 0 ) { $totals[] = 'vat'; } - if ($has_tangible && !$order->GetDBField('ShippingTaxable')) { - $totals[] = 'shipping'; - } - - if ($order->GetDBField('ProcessingFee') > 0 && !$order->GetDBField('ProcessingTaxable')) { - $totals[] = 'processing'; - } - - $o = ''; - foreach ($totals as $type) { + asort($element_order, SORT_NUMERIC); + + foreach ($element_order as $type => $order) { $element = getArrayValue($params, $type . '_render_as'); - if ( $element ) { - $o .= $this->Application->ParseBlock(array ('name' => $element), 1); + if ( !in_array($type, $totals) || !$element ) { + continue; } + + $o .= $this->Application->ParseBlock(Array ('name' => $element), 1); } return $o;