2017-07-27 54 views
-1

嗨,我想获得increment idinvoice.phphttp://prntscr.com/g0tyje
已在下面保护http://prntscr.com/g0tyow未来Magento的issuue /法师/销售/模型/顺序/ PDF/invoice.php

我们如何在保护中使用获得增量id请帮助我解决这个问题在此先感谢。

$orderId   = '100000006';  
$order   = Mage::getModel('sales/order')->loadByIncrementId($orderId); 
$shippingAddress = $order->getShippingAddress();  
$vikk   = $shippingAddress['postcode'];  
if($vikk == 110028){ 
    $lines[0][] = array('text' => Mage::helper('sales')->__('Tax(CGST)'), 'feed' => 495, 'align' => 'right'); 
    } else { 
    $lines[0][] = array('text' => Mage::helper('sales')->__('Tax(IGST)'), 'feed' => 495, 'align' => 'right'); 
    } 
+0

请发表您的代码为T在你的问题中通过[编辑]而不是图像分机。这会大大降低您帮助您访问代码的人的机会。并相信我:没有人会输入图像的代码;) – geisterfurz007

+0

我需要更改发票税名更改基于邮政编码,所以我想在这里获得增量id动态而不是静态值http://prntscr.com/g0u1oc –

+0

$ orderId ='100000006'; $ order = Mage :: getModel('sales/order') - > loadByIncrementId($ orderId); $ shippingAddress = $ order-> getShippingAddress(); $ vikk = $ shippingAddress ['postcode']; if($ vikk == 110028){ $ lines [0] [] = array( 'text'=> Mage :: helper('sales') - > __('Tax(CGST)'), ' feed'=> 495, 'align'=>'right' ); } 否则{ $线[0] [] =阵列( '文本'=>法师::助手( '销售') - > __( '税(IGST)'), '进料'=> 495, 'align'=>'right' ); } –

回答

0

我假设你正在编辑的文件app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php

你应该通过创建一个模块覆盖这个文件,我创造了这个给你,你只需要将这些文件复制到你的Magento安装。你也将需要在添加你的代码,我刚才提供的变量$ incrementId给你的函数

应用程序的/ etc /模块/ Vikash_Pdf.xml

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Vikash_Pdf> 
      <active>true</active> 
      <codePool>local</codePool> 
      <depends> 
       <Mage_Sales/> 

      </depends> 
     </Vikash_Pdf> 
    </modules> 
</config> 

应用程序/代码/本地/ Vikash/PDF /等/ config.xml中

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Vikash_Pdf> 
      <version>0.1.0</version> 
     </Vikash_Pdf> 
    </modules> 
    <global> 
     <models> 
      <sales> 
       <rewrite> 
        <order_pdf_invoice>Vikash_Pdf_Model_Order_Pdf_Invoice</order_pdf_invoice> 
       </rewrite> 
      </sales> 
     </models> 
    </global> 
</config> 

应用程序/代码/本地/ Vikash/PDF /型号/订购/ PDF/Invoice.php

<?php 
class Vikash_Pdf_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice 
{ 
    /** 
    * Draw header for item table 
    * 
    * @param Zend_Pdf_Page $page 
    * @return void 
    */ 
    protected function _drawHeader(Zend_Pdf_Page $page, $incrementId = null) 
    { 
     if($incrementId){ 
      var_dump($incrementId);die; 
     } 
     /* 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 
     $lines[0][] = array(
      'text' => Mage::helper('sales')->__('Products'), 
      'feed' => 35 
     ); 

     $lines[0][] = array(
      'text' => Mage::helper('sales')->__('SKU'), 
      'feed' => 290, 
      'align' => 'right' 
     ); 

     $lines[0][] = array(
      'text' => Mage::helper('sales')->__('Qty'), 
      'feed' => 435, 
      'align' => 'right' 
     ); 

     $lines[0][] = array(
      'text' => Mage::helper('sales')->__('Price'), 
      'feed' => 360, 
      'align' => 'right' 
     ); 

     $lines[0][] = array(
      'text' => Mage::helper('sales')->__('Tax'), 
      'feed' => 495, 
      'align' => 'right' 
     ); 

     $lines[0][] = array(
      'text' => Mage::helper('sales')->__('Subtotal'), 
      'feed' => 565, 
      'align' => 'right' 
     ); 

     $lineBlock = array(
      'lines' => $lines, 
      'height' => 5 
     ); 

     $this->drawLineBlocks($page, array($lineBlock), array('table_header' => true)); 
     $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); 
     $this->y -= 20; 
    } 

    /** 
    * Return PDF document 
    * 
    * @param array $invoices 
    * @return Zend_Pdf 
    */ 
    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) { 
      $incrementId = $invoice->getIncrementId(); 
      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 # ') . $incrementId 
      ); 
      /* Add table */ 
      $this->_drawHeader($page, $incrementId); 
      /* 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->_afterGetPdf(); 
     return $pdf; 
    } 

    /** 
    * Create new page and assign to PDF object 
    * 
    * @param array $settings 
    * @return Zend_Pdf_Page 
    */ 
    public function newPage(array $settings = array(), $incrementId = null) 
    { 
     /* Add new table head */ 
     $page = $this->_getPdf()->newPage(Zend_Pdf_Page::SIZE_A4); 
     $this->_getPdf()->pages[] = $page; 
     $this->y = 800; 
     if (!empty($settings['table_header'])) { 
      $this->_drawHeader($page, $incrementId); 
     } 
     return $page; 
    } 
}