Index: branches/5.2.x/units/orders/orders_tag_processor.php =================================================================== diff -u -N -r15605 -r16248 --- branches/5.2.x/units/orders/orders_tag_processor.php (.../orders_tag_processor.php) (revision 15605) +++ branches/5.2.x/units/orders/orders_tag_processor.php (.../orders_tag_processor.php) (revision 16248) @@ -1,6 +1,6 @@ Application->getUnitOption('pt', 'TableName'); + $sql = 'SELECT g.RequireCCFields, pt.PaymentTypeId + FROM ' . $pt_table . ' pt + JOIN ' . TABLE_PREFIX . 'Gateways g ON g.GatewayId = pt.GatewayId'; + + $payment_types = $this->Conn->GetCol($sql, 'PaymentTypeId'); + } + + /** @var kDBItem $object */ $object = $this->getObject($params); + $payment_type = $object->GetDBField('PaymentType'); - $pt = $object->GetDBField('PaymentType'); + if ( !$payment_type ) { + $payment_type = $this->getPrimaryPaymentType(); + $object->SetDBField('PaymentType', $payment_type); + } - if (!$pt) { - $pt = $this->Conn->GetOne('SELECT PaymentTypeId FROM '.TABLE_PREFIX.'PaymentTypes WHERE IsPrimary = 1'); - $object->SetDBField('PaymentType', $pt); + if ( !isset($payment_types[$payment_type]) ) { + throw new Exception('Unknown payment type: ' . $payment_type); } - $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 ) ); + return $payment_types[$payment_type]; + } - $sql = 'SELECT RequireCCFields FROM %s WHERE GatewayId = %s'; + /** + * Get primary payment type. + * + * @return string + */ + protected function getPrimaryPaymentType() + { + static $primary_payment_type; - return $this->Conn->GetOne( sprintf($sql, TABLE_PREFIX.'Gateways', $gw_id) ); + if ( !isset($primary_payment_type) ) { + $pt_table = $this->Application->getUnitOption('pt', 'TableName'); + $sql = 'SELECT PaymentTypeId FROM ' . $pt_table . ' WHERE IsPrimary = 1'; + $primary_payment_type = $this->Conn->GetOne($sql); + } + + return $primary_payment_type; } function PaymentTypeDescription($params) @@ -1650,4 +1679,4 @@ return true; } - } \ No newline at end of file + }