Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F776472
D81.id214.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Feb 7, 4:18 PM
Size
2 KB
Mime Type
text/x-diff
Expires
Sat, Feb 8, 4:18 PM (10 h, 57 m)
Engine
blob
Format
Raw Data
Handle
558897
Attached To
D81: MINC-127 Optimize "ord_UsingCreditCard" tag
D81.id214.diff
View Options
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,45 @@
}
/**
- * 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
- * @return bool
+ * @param array $params Tag params.
+ *
+ * @return boolean
+ * @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;
- $pt = $object->GetDBField('PaymentType');
+ if ( !isset($payment_types) ) {
+ $pt_table = $this->Application->getUnitOption('pt', 'TableName');
+ $sql = 'SELECT g.RequireCCFields, pt.PaymentTypeId
+ FROM ' . $pt_table . ' pt
+ JOIN ' . TABLE_PREFIX . 'Gateways g ON g.GatewayId = pt.GatewayId';
- if (!$pt) {
- $pt = $this->Conn->GetOne('SELECT PaymentTypeId FROM '.TABLE_PREFIX.'PaymentTypes WHERE IsPrimary = 1');
- $object->SetDBField('PaymentType', $pt);
+ $payment_types = $this->Conn->GetCol($sql, 'PaymentTypeId');
}
- $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 ) );
+ /** @var kDBItem $object */
+ $object = $this->getObject($params);
+ $payment_type = $object->GetDBField('PaymentType');
+
+ if ( !$payment_type ) {
+ if ( !isset($primary_payment_type) ) {
+ $sql = 'SELECT PaymentTypeId FROM ' . $pt_table . ' WHERE IsPrimary = 1';
+ $primary_payment_type = $this->Conn->GetOne($sql);
+ }
- $sql = 'SELECT RequireCCFields FROM %s WHERE GatewayId = %s';
+ $payment_type = $primary_payment_type;
+ $object->SetDBField('PaymentType', $payment_type);
+ }
+
+ if ( !isset($payment_types[$payment_type]) ) {
+ throw new Exception('Unknown payment type: ' . $payment_type);
+ }
- return $this->Conn->GetOne( sprintf($sql, TABLE_PREFIX.'Gateways', $gw_id) );
+ return $payment_types[$payment_type];
}
function PaymentTypeDescription($params)
@@ -1650,4 +1666,4 @@
return true;
}
- }
\ No newline at end of file
+ }
Event Timeline
Log In to Comment