Magento:如何打印后端发票像前端HTML



我在Magento 1.7.0.2上。如何使用与前端相同的方式从后端打印发票?我希望它是HTML格式,而不是PDF格式。

假设您想从管理订单详细信息页面一次打印一张发票

创建自定义管理模块

使用下面的方法添加控制器

public function printInvoiceAction()
{  
$invoiceId = (int) $this->getRequest()->getParam('invoice_id');
if ($invoiceId) {
$invoice = Mage::getModel('sales/order_invoice')->load($invoiceId);
$order = $invoice->getOrder();
} else {
$order = Mage::registry('current_order');
}

if (isset($invoice)) {
Mage::register('current_invoice', $invoice);
}
$this->loadLayout('print');
$this->renderLayout();
}

app/code/core/Mage/Sales/controllers/GuestController.php 中的参考打印InvoiceAction()

然后在自定义布局.xml中,使用/app/design/frontend/base/default/layout/sales.xml中的<sales_guest_printinvoice>作为模板

然后添加一个链接到以下url的按钮(需要从订单中获取发票id)/customModule/controller/printInvoice/invoice_id/xxx

(未测试,所以如果遇到任何问题,请告诉我)

您应该创建用于打印print.css的自定义css文件。您应该添加"打印按钮",它将调用window.print()

最新更新