Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
magento在app/code/core/mage/sales/model/order/pdf/invoice.php中获取订单id时发出_Php_Magento - Fatal编程技术网

magento在app/code/core/mage/sales/model/order/pdf/invoice.php中获取订单id时发出

magento在app/code/core/mage/sales/model/order/pdf/invoice.php中获取订单id时发出,php,magento,Php,Magento,您好,我正在invoice.php页面 那已经在下面了 我们如何在受保护中获得增量id请帮助我解决此问题,谢谢提前 $orderId = '100000006'; $order = Mage::getModel('sales/order')->loadByIncrementId($orderId); $shippingAddress = $order->getShippingAddress(); $vikk

您好,我正在
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' );
  }

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

你应该通过创建一个模块来覆盖这个文件,我已经为你创建了这个模块,你只需要将这些文件复制到你的magento安装中。您还需要添加代码,我刚刚为您的函数提供了变量$incrementId

app/etc/modules/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>

真的
地方的
app/code/local/Vikash/Pdf/etc/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>

0.1.0
Vikash\u Pdf\u型号\u订单\u Pdf\u发票
app/code/local/Vikash/Pdf/Model/Order/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;
    }
}
getStoreId())
);
/*添加文档文本和编号*/
$this->insertDocumentNumber(
$page,
Mage::helper('sales')->_____________#')。$incrementId
);
/*添加表*/
$this->\u drawHeader($page,$incrementId);
/*添加正文*/
foreach($invoice->getAllItems()作为$item){
如果($item->getOrderItem()->getParentItem()){
继续;
}
/*抽签项目*/
$this->\u drawItem($item,$page,$order);
$page=end($pdf->pages);
}
/*加总*/
$this->insertTotals($page,$invoice);
如果($invoice->getStoreId()){
Mage::app()->getLocale()->revert();
}
}
$this->_afterGetPdf();
返回$pdf;
}
/**
*创建新页面并指定给PDF对象
*
*@param数组$settings
*@return Zend\u Pdf\u页面
*/
公共函数newPage(数组$settings=array(),$incrementId=null)
{
/*添加新的表格标题*/
$page=$this->\u getPdf()->newPage(Zend\u Pdf\u page::SIZE\u A4);
$this->_getPdf()->pages[]=$page;
$this->y=800;
如果(!empty($settings['table_header'])){
$this->\u drawHeader($page,$incrementId);
}
返回$page;
}
}

请在问题中以文本形式发布代码,不要以图像形式发布。这大大减少了有人帮助您的机会,因为这有助于访问代码。相信我:没有人会键入图像的代码;)我需要根据邮政编码更改发票税名称,因此我希望在此处动态获取增量id,而不是静态值$orderId='10000006'$order=Mage::getModel('sales/order')->loadByIncrementId($orderId)$shippingAddress=$order->getShippingAddress()$vikk=$shippingAddress['postcode'];如果($vikk==110028){$lines[0][]=array('text'=>Mage::helper('sales')->uuuu('Tax(CGST)),'feed'=>495,'align'=>'right');}否则{$lines[0][]=array('text'=>Mage::helper('sales')->uuu('Tax(IGST)')),'feed'=>495,'align'=>right');}请把这和你的问题联系起来。正如你在评论中看到的,这会变得混乱。粘贴问题后,您可以突出显示它,然后按编辑区域顶部的Ctrl+K或
{}
符号将其格式化为代码。我不知道是否有人可以帮助我解决此问题,我将非常感谢他。