Answers:
不知道是否可以在不扩展magento基本功能的情况下实现所需的功能。我必须做类似的事情,这就是我所做的: 首先,我将sales_order_creditmemo_totals改写为自动的贷项通知单(也许您不需要,所以可以转到第二部分):
在我的模块config.xml中:
<blocks>
<adminhtml>
<rewrite>
...
<sales_order_creditmemo_totals>Bla_Customercredit_Block_Adminhtml_Sales_Creditmemo</sales_order_creditmemo_totals>
</rewrite>
</adminhtml>
<sales>
<rewrite>
...
<order_creditmemo_totals>Bla_Customercredit_Block_Sales_Creditmemo</order_creditmemo_totals>
</rewrite>
</sales>
</blocks>
然后在Block / Adminhtml / Sales / Creditmemo.php中
class Bla_Customercredit_Block_Adminhtml_Sales_Creditmemo extends Mage_Sales_Block_Order_Creditmemo_Totals
{
protected $_code = 'credit';
protected function _initTotals()
{
$helper = $this->getCreditsHelper();
parent::_initTotals();
$baseAmount = $this->getOrder()->getBaseCustomerCredit();
$this->addTotal(
new Varien_Object(
array(
'code' => $this->_code,
'value' => -$creditAmount,
'base_value' => -$baseAmount,
'label' => $helper->__('Bla Credit'),
)
),
'discount'
);
return $this;
}
}
如您所见,我这样做是为了为具有客户信用的订单创建贷项通知单,因此我也重写了sales_order_totals和sales_order_invoice_totals,但我认为您不需要这样做。
第二: 我还添加了自己的模板,以在手动creditmemo创建期间添加一些功能,因此管理员可以决定如何生成它。为此,我在app / design / adminhtml / default / default / template / MODULE_NAME / order / creditmemo / create / items.phtml下创建了items.phtml,在此phtml中,我添加了一些输入字段以更改默认值。我还在Company_CustomerCredit_Adminhtml_CustomerController下的管理控制器中的模块中添加了我
require_once 'Mage/Adminhtml/controllers/CustomerController.php';
class Bla_Customercredit_Adminhtml_CustomerController extends Mage_Adminhtml_CustomerController
{
/**
* Overload to save customer credits, then call
* parent::saveAction()
*/
public function saveAction()
{
$data = $this->getRequest()->getPost();
if($data && $data['bla_credits'])
{
if(!empty($data['bla_credits']['id']))
{
$model = Mage::getModel('credits/credits')->load($data['bla_credits']['id']);
}
else
{
unset($data['bla_credits']['id']);
$model = Mage::getModel('credits/credits');
}
try
{
$model->setData($data['bla_credits']);
$model->save();
}
catch(Exception $e)
{
}
}
parent::saveAction();
}
}