2

我一直无法找到输出的getPaymentHtml()来源。

其定义为:

public function getPaymentHtml() { return $this->getChildHtml('payment_info'); }

我找不到payment_info块的模板。

基本上我希望能够在结帐的进度块中检索信用卡类型和信用卡号。

如何找出方法名称?就像是$this->getCreditCardType()

编辑:好的!我了解 Magento 会首先确定付款方式,该方式具有用于呈现输出的相应模板。但是在progress.phtml结帐时,var_dump( $this instanceof Mage_Payment_Block_Info_Cc );返回false,那么我如何在当前上下文中访问它?

4

2 回答 2

3

The Progress block doen't have it's own template for Payment info. Mage_Checkout_Block_Onepage_Payment_Info block uses the selected Payment Method block to output html. Look at the Mage_Checkout_Block_Onepage_Payment_Info::_toHtml() method:

protected function _toHtml()
{
    $html = '';
    if ($block = $this->getChild($this->_getInfoBlockName())) {
        $html = $block->toHtml();
    }
    return $html;
}

To find the actual template and block for the specific Payment method you use, you need to perform next steps:

  1. First - get model alias for current payment method Mage::getStoreConfig('payment/'.$yourMethod.'/model') and instantiate it using Mage::getModel(alias)
  2. then get block type using $model->getInfoBlockType() - so you'll be able to find the actual Block by it's type

For example for ccSave payment method the info block is Mage_Payment_Block_Info_Ccsave, and template for it is app\design\frontend\base\default\template\payment\info\default.phtml. You'll be able to find all data inside those. Good luck ;)

For the sake of completeness, exact functions to fetch CC type and last 4 digits of CC number are:

echo Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getCcType();
echo Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getCcLast4();
于 2012-09-11T16:47:18.350 回答
1

The block class is declared in layout update XML; see the onepage checkout and multishipping directives from checkout.xml. The actual child block which is used depends on the payment model which is being used, but there is a common template that will be used unless overridden.

Example:

于 2012-09-11T16:47:29.273 回答