Page MenuHomeIn-Portal Phabricator

D81.id213.diff
No OneTemporary

File Metadata

Created
Sat, Feb 1, 6:44 PM

D81.id213.diff

Index: modules/in-commerce/units/orders/orders_tag_processor.php
===================================================================
--- modules/in-commerce/units/orders/orders_tag_processor.php
+++ modules/in-commerce/units/orders/orders_tag_processor.php
@@ -516,29 +516,43 @@
}
/**
- * Returns true in case if credit card was used as payment type for order
+ * Returns true in case if credit card was used as payment type for order.
+ *
+ * @param array $params Tag params.
*
- * @param Array $params
* @return bool
+ * @throws Exception When payment type not found.
*/
- function UsingCreditCard($params)
+ protected function UsingCreditCard(array $params)
{
- $object = $this->getObject($params);
+ static $payment_types, $primary_payment_type;
+
+ if ( !isset($payment_types) ) {
+ $pt_table = $this->Application->getUnitOption('pt', 'TableName');
+ $sql = 'SELECT g.RequireCCFields, pt.PaymentTypeId
+ FROM ' . $pt_table . ' pt
+ INNER JOIN ' . TABLE_PREFIX . 'Gateways g ON g.GatewayId = pt.GatewayId';
+
+ $payment_types = $this->Conn->GetCol($sql, 'PaymentTypeId');
+ $sql = 'SELECT PaymentTypeId FROM ' . $pt_table . ' WHERE IsPrimary = 1';
+ $primary_payment_type = $this->Conn->GetOne($sql);
+ }
+
+ /** @var kDBItem $object */
+ $object = $this->getObject($params);
$pt = $object->GetDBField('PaymentType');
- if (!$pt) {
- $pt = $this->Conn->GetOne('SELECT PaymentTypeId FROM '.TABLE_PREFIX.'PaymentTypes WHERE IsPrimary = 1');
+ if ( !$pt ) {
+ $pt = $primary_payment_type;
$object->SetDBField('PaymentType', $pt);
}
- $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 ) );
-
- $sql = 'SELECT RequireCCFields FROM %s WHERE GatewayId = %s';
+ if ( !isset($payment_types[$pt]) ) {
+ throw new Exception('Unknown payment type: ' . $pt);
+ }
- return $this->Conn->GetOne( sprintf($sql, TABLE_PREFIX.'Gateways', $gw_id) );
+ return $payment_types[$pt];
}
function PaymentTypeDescription($params)
@@ -1650,4 +1664,4 @@
return true;
}
- }
\ No newline at end of file
+ }

Event Timeline