我正在尝试做一些应该很简单的事情,但我被卡住了。将项目编号添加到Magento发票中的项目PDF
我正在尝试将序列号(1,2,3等)添加到Magento发票pdf中名为序列号的列下的项目中。
任何线索如何做到这一点? 谢谢!
我正在尝试做一些应该很简单的事情,但我被卡住了。将项目编号添加到Magento发票中的项目PDF
我正在尝试将序列号(1,2,3等)添加到Magento发票pdf中名为序列号的列下的项目中。
任何线索如何做到这一点? 谢谢!
这两个文件是负责发票显示PDF内容 应用程序\代码\核心\法师\销售\型号\订单\ PDF阅读器\项目\发票\如default.php 应用程序\代码\核心\法师\销售\型号\ Order \ Pdf \ Invoice.php 覆盖这两个文件或只是放在您的本地文件夹中
现在在此文件中添加序列号标头app \ code \ core \ Mage \ Sales \ Model \ Order \ Pdf \ Invoice .PHP 你可以鳍_drawHeader
函数之前的产品列中添加这样的事情
$lines[0][] = array(
'text' => Mage::helper('sales')->__('Serial number'),
'feed' => 35
);
现在去应用程序\代码\核心\法师\销售\型号\订单\ PDF阅读器\ \项目的发票\如default.php这个文件,你可以找到draw()
功能
从$this->getItem();
你可以找到项目数,并把你的循环这里显示的序列号类似
for($j=1; $j<=count($this->getItem());$j++)
{
$lines[$j][] = array(
'text' => $j,
'font' => 'bold',
'align' => 'right'
);
}
按照以下步骤
第1步:您拥有具有核心法师的两个文件工作,所以,复制与T文件继承人各自的文件夹结构。并粘贴到本地目录。这两个文件如下:
来自: (1)的应用程序\代码\核心\法师\ SALES \模型\订单\全文\ Invoice.php (2)的应用程序\代码\核心\法师\ SALES \型号\订单\ PDF阅读器\项目\发票\如default.php
要: (1)应用程序\代码\本地\法师\销售\型号\订单\ PDF阅读器\ Invoice.php (2)应用程序\代码\本地\法师\销售\模型\订单\ Pdf \物品\发票\ Default.php
(注意:请将上述两个文件复制到本地目录中,并使用相应的文件夹结构,而不是直接更改为核心文件。
第2步:现在,首先使用Invoice.php文件。
在产品名称添加标题代码前粘贴以下代码。
//Serial Number
$lines[0][] = array(
‘text’ => Mage::helper(‘sales’)->__(‘#’),
‘feed’ => 35
);
和更改产品列的饲料价值如下:
$lines[0][] = array(
‘text’ => Mage::helper(‘sales’)->__(‘Products’),
‘feed’ => 70
);
所以它看起来像以下:
/* Add table head */
$this->_setFontRegular($page, 10);
$page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y, 570, $this->y -15);
$this->y -= 10;
$page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
//columns headers
//Serial Number
$lines[0][] = array(
‘text’ => Mage::helper(‘sales’)->__(‘#’),
‘feed’ => 35
);
$lines[0][] = array(
‘text’ => Mage::helper(‘sales’)->__(‘Products’),
‘feed’ => 70
);
3步:现在,剩下的工作,如default.php文件。
在产品名称打印代码之后和$ lines数组声明之后粘贴以下代码。
$var_srno = Mage::registry(‘sr_no’);
if($var_srno!=0)
{
$new_sr = $var_srno + 1;
$sr_no = $new_sr;
Mage::unregister(‘sr_no’);
}
else{
$new_sr = 1;
}
Mage::register(‘sr_no’, $new_sr);
$lines[0][] = array(
‘text’ => $new_sr,
‘feed’ => 35
);
,现在也改变$的代码行[0] []用于获取项目名称如下:
$lines[0][] = array(
‘text’ => Mage::helper(‘core/string’)->str_split($item->getName(), 70, true, true),
‘feed’ => 70,
);
所以,现在,它会看起来如下:
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$lines = array();
// draw Product name
$lines[0] = array(array(
'text' => Mage::helper('core/string')->str_split($item->getName(), 35, true, true),
'feed' => 70
));
$var_srno = Mage::registry('sr_no');
if($var_srno!=0)
{
$new_sr = $var_srno + 1;
$sr_no = $new_sr;
Mage::unregister('sr_no');
}
else{
$new_sr = 1;
}
Mage::register('sr_no', $new_sr);
$lines[0][] = array(
'text' => $new_sr,
'feed' => 35
);
// draw SKU
$lines[0][] = array(
'text' => Mage::helper('core/string')->str_split($this->getSku($item), 17),
'feed' => 190,
'align' => 'right'
);
第4步:保存文件和清除Magento缓存。并查看结果。
嗨,我试过了。但我得到一个错误:'解析错误:语法错误,意外'(',期待T_STRING或T_VARIABLE或'行'文本'=>法师:: helper('核心/字符串')''''或'$'') - >($ i,35,true,true), – GKRP 2013-05-14 13:01:16
已更新我的回答 – Mufaddal 2013-05-15 04:44:13
不,这也行不通,它重复数字'1'并将其添加到一个新的行,所以它是1,1,1等。每个序列号都在自己的一行上。 – GKRP 2013-05-15 08:00:28