Changeset View
Changeset View
Standalone View
Standalone View
modules/in-commerce/units/orders/orders_tag_processor.php
Show First 20 Lines • Show All 510 Lines • ▼ Show 20 Line(s) | |||||
$this->Application->SetVar('pt_id', $payment_type_id); | $this->Application->SetVar('pt_id', $payment_type_id); | ||||
$block_params['name'] = $this->SelectParam($params, $this->UsingCreditCard($params) ? 'cc_render_as,block_cc' : 'default_render_as,block_default' ); | $block_params['name'] = $this->SelectParam($params, $this->UsingCreditCard($params) ? 'cc_render_as,block_cc' : 'default_render_as,block_default' ); | ||||
return $this->Application->ParseBlock($block_params); | return $this->Application->ParseBlock($block_params); | ||||
} | } | ||||
return ''; | return ''; | ||||
} | } | ||||
/** | /** | ||||
* 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 | * @return bool | ||||
alex: It should be `boolean`, not `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'; | |||||
alexUnsubmitted Not Done ReplyThe INNER JOIN is equivalent to just JOIN. alex: The `INNER JOIN` is equivalent to just `JOIN`. | |||||
$payment_types = $this->Conn->GetCol($sql, 'PaymentTypeId'); | |||||
$sql = 'SELECT PaymentTypeId FROM ' . $pt_table . ' WHERE IsPrimary = 1'; | |||||
$primary_payment_type = $this->Conn->GetOne($sql); | |||||
alexUnsubmitted Not Done ReplyThis should be done only when needed, not all the time. alex: This should be done only when needed, not all the time. | |||||
} | |||||
/** @var kDBItem $object */ | |||||
$object = $this->getObject($params); | |||||
$pt = $object->GetDBField('PaymentType'); | $pt = $object->GetDBField('PaymentType'); | ||||
alexUnsubmitted Not Done ReplyPlease rename to $payment_type. alex: Please rename to `$payment_type`. | |||||
if (!$pt) { | if ( !$pt ) { | ||||
$pt = $this->Conn->GetOne('SELECT PaymentTypeId FROM '.TABLE_PREFIX.'PaymentTypes WHERE IsPrimary = 1'); | $pt = $primary_payment_type; | ||||
$object->SetDBField('PaymentType', $pt); | $object->SetDBField('PaymentType', $pt); | ||||
} | } | ||||
$pt_table = $this->Application->getUnitOption('pt','TableName'); | if ( !isset($payment_types[$pt]) ) { | ||||
$sql = 'SELECT GatewayId FROM %s WHERE PaymentTypeId = %s'; | throw new Exception('Unknown payment type: ' . $pt); | ||||
$gw_id = $this->Conn->GetOne( sprintf( $sql, $pt_table, $pt ) ); | } | ||||
$sql = 'SELECT RequireCCFields FROM %s WHERE GatewayId = %s'; | |||||
return $this->Conn->GetOne( sprintf($sql, TABLE_PREFIX.'Gateways', $gw_id) ); | return $payment_types[$pt]; | ||||
} | } | ||||
function PaymentTypeDescription($params) | function PaymentTypeDescription($params) | ||||
Not Done ReplyWe can actually extract this to separate getPrimaryPaymentType that will have $primary_payment_type variable in it. alex: We can actually extract this to separate `getPrimaryPaymentType` that will have… | |||||
{ | { | ||||
return $this->Application->ProcessParsedTag('pt', 'Field', array_merge($params, Array( | return $this->Application->ProcessParsedTag('pt', 'Field', array_merge($params, Array( | ||||
'field' => 'Description' | 'field' => 'Description' | ||||
)) ); | )) ); | ||||
} | } | ||||
function PaymentTypeInstructions($params) | function PaymentTypeInstructions($params) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1092 Lines • ▼ Show 20 Line(s) | |||||
foreach ($address_fields as $address_field) { | foreach ($address_fields as $address_field) { | ||||
if ( $object->GetDBField('Shipping' . $address_field) != $object->GetDBField('Billing' . $address_field) ) { | if ( $object->GetDBField('Shipping' . $address_field) != $object->GetDBField('Billing' . $address_field) ) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
No newline at end of file |
It should be boolean, not bool.