【问题标题】:Add item numbers to items in Magento Invoice PDF将项目编号添加到 Magento Invoice PDF 中的项目
【发布时间】:2013-05-14 11:21:57
【问题描述】:

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

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

关于如何做到这一点的任何线索? 谢谢!

【问题讨论】:

    标签: magento pdf invoice


    【解决方案1】:

    这两个文件负责显示发票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_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'
                );
    }
    

    【讨论】:

    • 嗨,我试过了。但我收到一个错误:'Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or '{' or '$'' on line 'text' => Mage::helper('core/string') ->($i, 35, true, true),
    • 不,这也不起作用。它重复数字“1”并将其添加到新行。所以它是 1、1、1 等等,每个序列号在自己的一行中。
    • invoice.php -> 链接 -> paste.ofcode.org/3gHXE4bMUVdzXLBKtx6uQH default.php -> 链接 -> paste.ofcode.org/bmNig6Lj2Lnb82DrcmD3MF 仍然序列号未添加到我的发票中。我可以知道我的锻炼吗? @Mufaddal
    【解决方案2】:

    按照步骤操作


    第 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 缓存。并查看结果。

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 2021-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多