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 | * @param array $params Tag params. | ||||
* @return bool | * | ||||
* @return boolean | |||||
* @throws Exception When payment type not found. | |||||
alex: It should be `boolean`, not `bool`. | |||||
*/ | */ | ||||
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'); | |||||
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. | |||||
$sql = 'SELECT g.RequireCCFields, pt.PaymentTypeId | |||||
FROM ' . $pt_table . ' pt | |||||
JOIN ' . TABLE_PREFIX . 'Gateways g ON g.GatewayId = pt.GatewayId'; | |||||
Not Done ReplyThe INNER JOIN is equivalent to just JOIN. alex: The `INNER JOIN` is equivalent to just `JOIN`. | |||||
Not Done ReplyPlease rename to $payment_type. alex: Please rename to `$payment_type`. | |||||
if (!$pt) { | $payment_types = $this->Conn->GetCol($sql, 'PaymentTypeId'); | ||||
$pt = $this->Conn->GetOne('SELECT PaymentTypeId FROM '.TABLE_PREFIX.'PaymentTypes WHERE IsPrimary = 1'); | |||||
$object->SetDBField('PaymentType', $pt); | |||||
} | } | ||||
$pt_table = $this->Application->getUnitOption('pt','TableName'); | /** @var kDBItem $object */ | ||||
$sql = 'SELECT GatewayId FROM %s WHERE PaymentTypeId = %s'; | $object = $this->getObject($params); | ||||
$gw_id = $this->Conn->GetOne( sprintf( $sql, $pt_table, $pt ) ); | $payment_type = $object->GetDBField('PaymentType'); | ||||
$sql = 'SELECT RequireCCFields FROM %s WHERE GatewayId = %s'; | if ( !$payment_type ) { | ||||
if ( !isset($primary_payment_type) ) { | |||||
$sql = 'SELECT PaymentTypeId FROM ' . $pt_table . ' WHERE IsPrimary = 1'; | |||||
$primary_payment_type = $this->Conn->GetOne($sql); | |||||
} | |||||
alexUnsubmitted 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… | |||||
$payment_type = $primary_payment_type; | |||||
$object->SetDBField('PaymentType', $payment_type); | |||||
} | |||||
return $this->Conn->GetOne( sprintf($sql, TABLE_PREFIX.'Gateways', $gw_id) ); | if ( !isset($payment_types[$payment_type]) ) { | ||||
throw new Exception('Unknown payment type: ' . $payment_type); | |||||
} | |||||
return $payment_types[$payment_type]; | |||||
} | } | ||||
function PaymentTypeDescription($params) | function PaymentTypeDescription($params) | ||||
{ | { | ||||
return $this->Application->ProcessParsedTag('pt', 'Field', array_merge($params, Array( | return $this->Application->ProcessParsedTag('pt', 'Field', array_merge($params, Array( | ||||
'field' => 'Description' | 'field' => 'Description' | ||||
)) ); | )) ); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1095 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.