将项目编号添加到Magento发票PDF中的项目

将项目编号添加到Magento发票PDF中的项目,magento,pdf,invoice,Magento,Pdf,Invoice,我正试图做一些非常简单的事情,但我被卡住了 我正在尝试将序列号(1、2、3等)添加到Magento发票pdf中名为序列号的列下的项目中 有没有关于如何做到这一点的线索? 谢谢 这两个文件负责显示发票pdf内容 app\code\core\Mage\Sales\Model\Order\Pdf\Items\Invoice\Default.php app\code\core\Mage\Sales\Model\Order\Pdf\Invoice.php 覆盖这两个文件,或者干脆放在本地文件夹中 现在在这

我正试图做一些非常简单的事情,但我被卡住了

我正在尝试将序列号(1、2、3等)添加到Magento发票pdf中名为序列号的列下的项目中

有没有关于如何做到这一点的线索?
谢谢

这两个文件负责显示发票pdf内容 app\code\core\Mage\Sales\Model\Order\Pdf\Items\Invoice\Default.php app\code\core\Mage\Sales\Model\Order\Pdf\Invoice.php 覆盖这两个文件,或者干脆放在本地文件夹中

现在在这个文件app\code\core\Mage\Sales\Model\Order\Pdf\Invoice.php中添加序列号标题 您可以使用fin
\u drawHeader
函数,只需在“产品”列之前添加类似的内容即可

$lines[0][] = array(
        'text' => Mage::helper('sales')->__('Serial number'),
        'feed' => 35
    );
现在转到app\code\core\Mage\Sales\Model\Order\Pdf\Items\Invoice\Default.php这个文件,您可以找到
draw()
function

$this->getItem()
您可以找到item count并将for循环放在此处,用于显示序列号,如

for($j=1; $j<=count($this->getItem());$j++)
{
 $lines[$j][] = array(
                'text'  => $j,
                'font'  => 'bold',
                'align' => 'right'
            );
}
for($j=1;$jgetItem())$(j++)
{
$lines[$j][]=数组(
“text”=>j美元,
'字体'=>'粗体',
“对齐”=>“右”
);
}

按照步骤进行操作


第一步:你必须处理两个核心法师的文件,所以,用它们各自的文件夹结构复制这些文件。并粘贴到本地目录。这两个文件如下所示:

$lines[0][] = array(
‘text’ => Mage::helper(‘core/string’)->str_split($item->getName(), 70, true, true),
‘feed’ => 70,
);
发件人: (1) app\code\core\Mage\Sales\Model\Order\Pdf\Invoice.php (2) app\code\core\Mage\Sales\Model\Order\Pdf\Items\Invoice\Default.php

致: (1) app\code\local\Mage\Sales\Model\Order\Pdf\Invoice.php (2) app\code\local\Mage\Sales\Model\Order\Pdf\Items\Invoice\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
);
因此,它将如下所示:

$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
);
现在还要更改$lines[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缓存。看看结果。

嗨,我试过这个。但我得到了一个错误:'Parse error:syntax error,unexpected'(',在'text'=>Mage::helper('core/STRING')->行上应为T_字符串或T_变量或'{'或'$')($I,35,true,true),不,这也不起作用。它重复数字“1”并将其添加到新行。因此,它是1,1,1等。每个序列号都在自己的行上。invoice.php->link->paste.ofcode.org/3gHXE4bMUVdzXLBKtx6uQH default.php->link->paste.ofcode.org/bmNig6Lj2Lnb82DrcmD3MF仍然没有添加到我的发票中。我可以知道我的训练计划吗嗯?@Mufaddal