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

时间:2013-05-14 11:21:57

标签: magento pdf invoice

我正在尝试做一些非常简单的事情,但我被困住了。

我正在尝试在序列号列下的Magento发票pdf中添加序列号(1,2,3等)。

有关如何执行此操作的任何线索? 谢谢!

2 个答案:

答案 0 :(得分:0)

这两个文件负责显示发票pdf内容 应用程序\代码\核心\法师\销售\型号\订单\ PDF阅读器\项目\发票\如default.php 应用程序\代码\核心\法师\销售\型号\订单\ 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
    );

现在转到app \ code \ core \ Mage \ Sales \ Model \ Order \ Pdf \ Items \ Invoice \ Default.php这个文件你可以找draw()函数

$this->getItem();您可以找到项目计数,并在此处显示您的for循环以显示类似

的序列号
for($j=1; $j<=count($this->getItem());$j++)
{
 $lines[$j][] = array(
                'text'  => $j,
                'font'  => 'bold',
                'align' => 'right'
            );
}

答案 1 :(得分:0)

按照步骤

步骤1:您必须使用两个核心图像文件,因此,使用各自的文件夹结构复制这些文件。并粘贴到本地目录。这两个文件如下:

来自: (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
);

并将Product列的Feed值更改为:

$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 Cache。并查看结果。