Index: branches/5.3.x/units/orders/orders_tag_processor.php =================================================================== diff -u -N -r15925 -r16398 --- branches/5.3.x/units/orders/orders_tag_processor.php (.../orders_tag_processor.php) (revision 15925) +++ branches/5.3.x/units/orders/orders_tag_processor.php (.../orders_tag_processor.php) (revision 16398) @@ -1,6 +1,6 @@ Application->HREF($this->Application->GetVar('t'), '', Array('pass' => 'm,orditems,ord', 'ord_event' => 'OnRemoveFromCart', 'm_cat_id'=>0)); + $params['m_cat_id'] = 0; + $params['ord_event'] = 'OnRemoveFromCart'; + + if ( !isset($params['pass']) ) { + $params['pass'] = 'm,orditems,ord'; + } + + // Remove parameters, that indicate from where this aggregated tag was called. + unset($params['PrefixSpecial'], $params['original_tag']); + + return $this->Application->ProcessParsedTag('m', 'Link', $params); } function Orderitems_ProductLink($params) @@ -516,29 +526,58 @@ } /** - * 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) { + static $payment_types; + + if ( !isset($payment_types) ) { + $pt_table = $this->Application->getUnitConfig('pt')->getTableName(); + $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->getUnitConfig('pt')->getTableName(); - $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->getUnitConfig('pt')->getTableName(); + $sql = 'SELECT PaymentTypeId FROM ' . $pt_table . ' WHERE IsPrimary = 1'; + $primary_payment_type = $this->Conn->GetOne($sql); + } + + return $primary_payment_type; } function PaymentTypeDescription($params) @@ -1075,10 +1114,9 @@ /* @var $object OrdersItem */ $gw_data = $object->getGatewayData( isset($params['payment_type_id']) ? $params['payment_type_id'] : null ); - $this->Application->registerClass( $gw_data['ClassName'], GW_CLASS_PATH.'/'.$gw_data['ClassFile'] ); - $gateway_object = $this->Application->recallObject( $gw_data['ClassName'] ); - /* @var $gateway_object kGWBase */ + /** @var kGWBase $gateway_object */ + $gateway_object = $this->Application->recallObject($gw_data['ClassName']); return $gateway_object->getFormAction($gw_data['gw_params']); } @@ -1089,10 +1127,9 @@ /* @var $object OrdersItem */ $gw_data = $object->getGatewayData( isset($params['payment_type_id']) ? $params['payment_type_id'] : null ); - $this->Application->registerClass( $gw_data['ClassName'], GW_CLASS_PATH.'/'.$gw_data['ClassFile'] ); - $gateway_object = $this->Application->recallObject( $gw_data['ClassName'] ); - /* @var $gateway_object kGWBase */ + /** @var kGWBase $gateway_object */ + $gateway_object = $this->Application->recallObject($gw_data['ClassName']); $tpl = ''."\n"; $hidden_fields = $gateway_object->getHiddenFields($object->GetFieldValues(), $params, $gw_data['gw_params']); @@ -1116,10 +1153,9 @@ /* @var $object OrdersItem */ $gw_data = $object->getGatewayData( isset($params['payment_type_id']) ? $params['payment_type_id'] : null ); - $this->Application->registerClass( $gw_data['ClassName'], GW_CLASS_PATH.'/'.$gw_data['ClassFile'] ); - $gateway_object = $this->Application->recallObject( $gw_data['ClassName'] ); - /* @var $gateway_object kGWBase */ + /** @var kGWBase $gateway_object */ + $gateway_object = $this->Application->recallObject($gw_data['ClassName']); return $gateway_object->NeedPlaceButton($object->GetFieldValues(), $params, $gw_data['gw_params']); } @@ -1358,10 +1394,9 @@ $object = $this->getObject($params); $gw_data = $object->getGatewayData($params['payment_type_id']); - $this->Application->registerClass( $gw_data['ClassName'], GW_CLASS_PATH.'/'.$gw_data['ClassFile'] ); - $gateway_object = $this->Application->recallObject( $gw_data['ClassName'] ); + /** @var kGWBase $gateway_object */ + $gateway_object = $this->Application->recallObject($gw_data['ClassName']); - $sql = 'SELECT oi.* FROM '.TABLE_PREFIX.'OrderItems oi LEFT JOIN '.TABLE_PREFIX.'Products p ON p.ProductId = oi.ProductId @@ -1436,14 +1471,18 @@ */ function RemoveCouponLink($params) { - $type = strtolower($params['type']); - $url_params = Array ( - 'pass' => 'm,ord', - 'ord_event' => ($type == 'coupon') ? 'OnRemoveCoupon' : 'OnRemoveGiftCertificate', - 'm_cat_id' => 0, - ); + if ( !isset($params['pass']) ) { + $params['pass'] = 'm,ord'; + } - return $this->Application->HREF('', '', $url_params); + $params['m_cat_id'] = 0; + + $link_type = $params['type']; + unset($params['type']); + + $params['ord_event'] = strtolower($link_type) == 'coupon' ? 'OnRemoveCoupon' : 'OnRemoveGiftCertificate'; + + return $this->ItemLink($params); } /** @@ -1656,4 +1695,4 @@ return true; } - } \ No newline at end of file + }