在magento管理控制台中,
客户=> GiftCardAccounts
我想在网格正下方显示Balance的总和。
我尝试在Grid.php中的方法$this->setCountTotals(true);
中设置public function __construct()
,但它没有用。
请让我知道如何做到这一点。任何帮助将不胜感激。
答案 0 :(得分:2)
当我为自己寻找答案时,我遇到了你。我觉得有趣的是,这似乎是一个不存在的在线讨论主题 - 也许每个人都已经弄清楚了吗?
以下是您需要做的事情:
在模块的etc/config.xml
中,像这样重写块:
<blocks>
<enterprise_giftcardaccount>
<rewrite>
<adminhtml_giftcardaccount_grid>Namespace_Giftcardaccount_Adminhtml_Giftcardaccount_Grid</adminhtml_giftcardaccount_grid> <!-- I like to put overrides/rewrites in their same folder under my namespace -->
</rewrite>
</enterprise_giftcardaccount>
</blocks>
现在,在Namespace / Giftcardaccount / Block / Adminhtml / Giftcardaccount / Grid.php中,执行以下操作:
<?php
class Namespace_Giftcardaccount_Adminhtml_Giftcardaccount_Grid extends Enterprise_GiftCardAccount_Block_Adminhtml_Giftcardaccount_Grid {
protected function _prepareGrid()
{
$collection = $this->getCollection();
$balanceTotal = 0;
foreach ($collection as $giftCardAccount) {
$balanceTotal += $giftCardAccount->getBalance();
}
$this->setTotals(new Varien_Object(
array(
'balance' => $balanceTotal
)
);
$this->setCountTotals(true);
return parent::_prepareGrid();
}
}
应该这样做!