Magento:在发票pdf底部添加自定义文本
我刚到马根托 我想在客户发票的底部添加一些“条款和条件” 我知道这个问题已经发布在门户网站上,但我还没有找到任何解决方案Magento:在发票pdf底部添加自定义文本,magento,pdf,invoice,Magento,Pdf,Invoice,我刚到马根托 我想在客户发票的底部添加一些“条款和条件” 我知道这个问题已经发布在门户网站上,但我还没有找到任何解决方案 谁能告诉我怎么做。打开文件app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php,并在文件末尾添加以下函数 public function insertConditions($page) { $page->drawLine(25, $this->y, 570, $this->y);
谁能告诉我怎么做。打开文件
app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php
,并在文件末尾添加以下函数
public function insertConditions($page)
{
$page->drawLine(25, $this->y, 570, $this->y);
$this->y -= 25;
$page->drawText(Mage::helper('sales')->__('Your custom text here!'), 35, $this->y, 'UTF-8');
}
现在,您需要调用getPdf()
函数中的insertConditions()
函数,如下所示:
public function getPdf($invoices = array())
{
$this->_beforeGetPdf();
$this->_initRenderer('invoice');
$pdf = new Zend_Pdf();
$this->_setPdf($pdf);
$style = new Zend_Pdf_Style();
$this->_setFontBold($style, 10);
foreach ($invoices as $invoice) {
if ($invoice->getStoreId()) {
Mage::app()->getLocale()->emulate($invoice->getStoreId());
Mage::app()->setCurrentStore($invoice->getStoreId());
}
$page = $this->newPage();
$order = $invoice->getOrder();
/* Add image */
$this->insertLogo($page, $invoice->getStore());
/* Add address */
$this->insertAddress($page, $invoice->getStore());
/* Add head */
$this->insertOrder(
$page,
$order,
Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId())
);
/* Add document text and number */
$this->insertDocumentNumber(
$page,
Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId()
);
/* Add table */
$this->_drawHeader($page);
/* Add body */
foreach ($invoice->getAllItems() as $item){
if ($item->getOrderItem()->getParentItem()) {
continue;
}
/* Draw item */
$this->_drawItem($item, $page, $order);
$page = end($pdf->pages);
}
/* Add totals */
$this->insertTotals($page, $invoice);
if ($invoice->getStoreId()) {
Mage::app()->getLocale()->revert();
}
}
$this->insertConditions($page); // the custom text is added here
$this->_afterGetPdf();
return $pdf;
}
PS.我建议覆盖核心文件,而不是直接更改它们 打开文件
app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php
并在文件末尾添加以下函数
public function insertConditions($page)
{
$page->drawLine(25, $this->y, 570, $this->y);
$this->y -= 25;
$page->drawText(Mage::helper('sales')->__('Your custom text here!'), 35, $this->y, 'UTF-8');
}
现在,您需要调用getPdf()
函数中的insertConditions()
函数,如下所示:
public function getPdf($invoices = array())
{
$this->_beforeGetPdf();
$this->_initRenderer('invoice');
$pdf = new Zend_Pdf();
$this->_setPdf($pdf);
$style = new Zend_Pdf_Style();
$this->_setFontBold($style, 10);
foreach ($invoices as $invoice) {
if ($invoice->getStoreId()) {
Mage::app()->getLocale()->emulate($invoice->getStoreId());
Mage::app()->setCurrentStore($invoice->getStoreId());
}
$page = $this->newPage();
$order = $invoice->getOrder();
/* Add image */
$this->insertLogo($page, $invoice->getStore());
/* Add address */
$this->insertAddress($page, $invoice->getStore());
/* Add head */
$this->insertOrder(
$page,
$order,
Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId())
);
/* Add document text and number */
$this->insertDocumentNumber(
$page,
Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId()
);
/* Add table */
$this->_drawHeader($page);
/* Add body */
foreach ($invoice->getAllItems() as $item){
if ($item->getOrderItem()->getParentItem()) {
continue;
}
/* Draw item */
$this->_drawItem($item, $page, $order);
$page = end($pdf->pages);
}
/* Add totals */
$this->insertTotals($page, $invoice);
if ($invoice->getStoreId()) {
Mage::app()->getLocale()->revert();
}
}
$this->insertConditions($page); // the custom text is added here
$this->_afterGetPdf();
return $pdf;
}
PS.我建议覆盖核心文件,而不是直接更改它们 您需要在invoice pdfThanks@saravanavelu中的总计后添加文本,但当我将其添加到invoice.php文件中时,它不会反映在invoice pdf中。您需要在invoice pdfThanks@saravanavelu中的总计后添加文本,但当我将其添加到invoice.php文件中时,在发票pdf中没有反映。Hello@Mansashvi我已将此添加到我的pdf中,但它在页面开始时显示,并与其他内容重叠。请您对此进行指导。另外,我只想在最后一页中显示页脚文本,这是一条关于此的线索?Hello@Mansashvi我已将此添加到我的pdf中,但在页面开始时显示,并且与其他内容重叠。你能在这方面指导我吗。另外,我只想在最后一页的页脚文本和这方面的线索?