Index: branches/5.2.x/units/orders/orders_item.php =================================================================== diff -u -N -r14641 -r14812 --- branches/5.2.x/units/orders/orders_item.php (.../orders_item.php) (revision 14641) +++ branches/5.2.x/units/orders/orders_item.php (.../orders_item.php) (revision 14812) @@ -1,6 +1,6 @@ GetDBField('PaymentType'); + + if ( !$pt_id ) { + // no Payment Type Id found for this order - escape SQL fatal below + return false; + } } - $pt_table = $this->Application->getUnitOption('pt','TableName'); - $sql = 'SELECT GatewayId FROM %s WHERE PaymentTypeId = %s'; - $gw_id = $this->Conn->GetOne( sprintf($sql, $pt_table, $pt_id) ); - $sql = 'SELECT * FROM %s WHERE GatewayId = %s'; - $ret = $this->Conn->GetRow( sprintf($sql, TABLE_PREFIX.'Gateways', $gw_id) ); + $pt_table = $this->Application->getUnitOption('pt', 'TableName'); + $sql = 'SELECT GatewayId + FROM %s + WHERE PaymentTypeId = %s'; + $gw_id = $this->Conn->GetOne(sprintf($sql, $pt_table, $pt_id)); + + $sql = 'SELECT * + FROM %s + WHERE GatewayId = %s'; + $ret = $this->Conn->GetRow(sprintf($sql, TABLE_PREFIX . 'Gateways', $gw_id)); + // get Gateway parameters based on payment type - $gwf_table = $this->Application->getUnitOption('gwf','TableName'); - $gwfv_table = $this->Application->getUnitOption('gwfv','TableName'); + $gwf_table = $this->Application->getUnitOption('gwf', 'TableName'); + $gwfv_table = $this->Application->getUnitOption('gwfv', 'TableName'); + $sql = 'SELECT gwfv.Value, gwf.SystemFieldName FROM %s gwf LEFT JOIN %s gwfv ON gwf.GWConfigFieldId = gwfv.GWConfigFieldId WHERE gwfv.PaymentTypeId = %s AND gwf.GatewayId = %s'; - $ret['gw_params'] = $this->Conn->GetCol( sprintf($sql, $gwf_table, $gwfv_table, $pt_id, $gw_id), 'SystemFieldName' ); + $ret['gw_params'] = $this->Conn->GetCol(sprintf($sql, $gwf_table, $gwfv_table, $pt_id, $gw_id), 'SystemFieldName'); + $ret['gw_params']['gateway_id'] = $gw_id; - if ($this->GetDBField('IsRecurringBilling') && $this->Application->ConfigValue('Comm_AutoProcessRecurringOrders')) { - if (isset($ret['gw_params']['shipping_control'])) { + if ( $this->GetDBField('IsRecurringBilling') && $this->Application->ConfigValue('Comm_AutoProcessRecurringOrders') ) { + if ( isset($ret['gw_params']['shipping_control']) ) { $ret['gw_params']['shipping_control'] = SHIPPING_CONTROL_DIRECT; } }