douji8549 2015-05-12 06:35
浏览 41
已采纳

从Magento的发票pdf中删除送货方式和付款方式

I wanto completely remove the Shipping Method and Payment Method section from invoice pdf in Magento.

My invoice pdf is look like this:

enter image description here

I look the app/code/core/mage/Sales/Model/Order/Pdf/Abstract.php file, here I can change the labels but I can't change the table(boxes).

Please help me..

  • 写回答

1条回答 默认 最新

  • dsasd12314 2015-05-12 07:12
    关注

    Here I can change the app/code/core/mage/Sales/Model/Order/Pdf/Abstract.php file,Replace the below code,

    protected function insertOrder(&$page, $obj, $putOrderId = true)
        {
            if ($obj instanceof Mage_Sales_Model_Order) {
                $shipment = null;
                $order = $obj;
            } elseif ($obj instanceof Mage_Sales_Model_Order_Shipment) {
                $shipment = $obj;
                $order = $shipment->getOrder();
            }
    
            $this->y = $this->y ? $this->y : 815;
            $top = $this->y;
    
            $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
            $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
            $page->drawRectangle(25, $top, 570, $top - 55);
            $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
            $this->setDocHeaderCoordinates(array(25, $top, 570, $top - 55));
            $this->_setFontRegular($page, 10);
    
            if ($putOrderId) {
                $page->drawText(
                    Mage::helper('sales')->__('Order # ') . $order->getRealOrderId(), 35, ($top -= 30), 'UTF-8'
                );
            }
            $page->drawText(
                Mage::helper('sales')->__('Order Date: ') . Mage::helper('core')->formatDate(
                    $order->getCreatedAtStoreDate(), 'medium', false
                ),
                35,
                ($top -= 15),
                'UTF-8'
            );
    
            $top -= 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, $top, 275, ($top - 25));
            $page->drawRectangle(275, $top, 570, ($top - 25));
    
            /* Calculate blocks info */
    
            /* Billing Address */
            $billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf'));
    
            /* Payment */
            $paymentInfo = Mage::helper('payment')->getInfoBlock($order->getPayment())
                ->setIsSecureMode(true)
                ->toPdf();
            $paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
            $payment = explode('{{pdf_row_separator}}', $paymentInfo);
            foreach ($payment as $key=>$value){
                if (strip_tags(trim($value)) == '') {
                    unset($payment[$key]);
                }
            }
            reset($payment);
    
            /* Shipping Address and Method */
            if (!$order->getIsVirtual()) {
                /* Shipping Address */
                $shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf'));
                $shippingMethod  = $order->getShippingDescription();
            }
    
            $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
            $this->_setFontBold($page, 12);
            $page->drawText(Mage::helper('sales')->__('Sold to:'), 35, ($top - 15), 'UTF-8');
    
            if (!$order->getIsVirtual()) {
                $page->drawText(Mage::helper('sales')->__('Ship to:'), 285, ($top - 15), 'UTF-8');
            } 
    
            $addressesHeight = $this->_calcAddressHeight($billingAddress);
            if (isset($shippingAddress)) {
                $addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
            }
    
            $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
            $page->drawRectangle(25, ($top - 25), 570, $top - 33 - $addressesHeight);
            $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
            $this->_setFontRegular($page, 10);
            $this->y = $top - 40;
            $addressesStartY = $this->y;
    
            foreach ($billingAddress as $value){
                if ($value !== '') {
                    $text = array();
                    foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) {
                        $text[] = $_value;
                    }
                    foreach ($text as $part) {
                        $page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
                        $this->y -= 15;
                    }
                }
            }
    
            $addressesEndY = $this->y;
    
            if (!$order->getIsVirtual()) {
                $this->y = $addressesStartY;
                foreach ($shippingAddress as $value){
                    if ($value!=='') {
                        $text = array();
                        foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) {
                            $text[] = $_value;
                        }
                        foreach ($text as $part) {
                            $page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
                            $this->y -= 15;
                        }
                    }
                }
    
                $addressesEndY = min($addressesEndY, $this->y);
                $this->y = $addressesEndY;
    
                // $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
                // $page->setLineWidth(0.5);
                // $page->drawRectangle(25, $this->y, 275, $this->y-25);
                // $page->drawRectangle(275, $this->y, 570, $this->y-25);
    
                $this->y -= 15;
                $this->_setFontBold($page, 12);
                $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
                // $page->drawText(Mage::helper('sales')->__('Payment Method'), 35, $this->y, 'UTF-8');
                // $page->drawText(Mage::helper('sales')->__('Shipping Method:'), 285, $this->y , 'UTF-8');
    
                $this->y -=10;
                $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
    
                $this->_setFontRegular($page, 10);
                $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
    
                $paymentLeft = 35;
                $yPayments   = $this->y - 15;
            }
            else {
                $yPayments   = $addressesStartY;
                $paymentLeft = 285;
            }
    
            // foreach ($payment as $value){
                // if (trim($value) != '') {
                    // //Printing "Payment Method" lines
                    // $value = preg_replace('/<br[^>]*>/i', "
    ", $value);
                    // foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) {
                        // $page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
                        // $yPayments -= 15;
                    // }
                // }
            // }
    
            if ($order->getIsVirtual()) {
                // replacement of Shipments-Payments rectangle block
                $yPayments = min($addressesEndY, $yPayments);
                $page->drawLine(25,  ($top - 25), 25,  $yPayments);
                $page->drawLine(570, ($top - 25), 570, $yPayments);
                $page->drawLine(25,  $yPayments,  570, $yPayments);
    
                $this->y = $yPayments - 15;
            // } else {
                $topMargin    = 15;
                $methodStartY = $this->y;
                $this->y     -= 15;
    
                // foreach (Mage::helper('core/string')->str_split($shippingMethod, 45, true, true) as $_value) {
                    // $page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
                    // $this->y -= 15;
                // }
    
                $yShipments = $this->y;
                // $totalShippingChargesText = "(" . Mage::helper('sales')->__('Total Shipping Charges') . " "
                    // . $order->formatPriceTxt($order->getShippingAmount()) . ")";
    
                // $page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
                // $yShipments -= $topMargin + 10;
    
                // $tracks = array();
                // if ($shipment) {
                    // $tracks = $shipment->getAllTracks();
                // }
                // if (count($tracks)) {
                    // $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
                    // $page->setLineWidth(0.5);
                    // $page->drawRectangle(285, $yShipments, 510, $yShipments - 10);
                    // $page->drawLine(400, $yShipments, 400, $yShipments - 10);
                    // //$page->drawLine(510, $yShipments, 510, $yShipments - 10);
    
                    // $this->_setFontRegular($page, 9);
                    // $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
                    // //$page->drawText(Mage::helper('sales')->__('Carrier'), 290, $yShipments - 7 , 'UTF-8');
                    // $page->drawText(Mage::helper('sales')->__('Title'), 290, $yShipments - 7, 'UTF-8');
                    // $page->drawText(Mage::helper('sales')->__('Number'), 410, $yShipments - 7, 'UTF-8');
    
                    // $yShipments -= 20;
                    // $this->_setFontRegular($page, 8);
                    // foreach ($tracks as $track) {
    
                        // $CarrierCode = $track->getCarrierCode();
                        // if ($CarrierCode != 'custom') {
                            // $carrier = Mage::getSingleton('shipping/config')->getCarrierInstance($CarrierCode);
                            // $carrierTitle = $carrier->getConfigData('title');
                        // } else {
                            // $carrierTitle = Mage::helper('sales')->__('Custom Value');
                        // }
    
                        // //$truncatedCarrierTitle = substr($carrierTitle, 0, 35) . (strlen($carrierTitle) > 35 ? '...' : '');
                        // $maxTitleLen = 45;
                        // $endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : '';
                        // $truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle;
                        // //$page->drawText($truncatedCarrierTitle, 285, $yShipments , 'UTF-8');
                        // $page->drawText($truncatedTitle, 292, $yShipments , 'UTF-8');
                        // $page->drawText($track->getNumber(), 410, $yShipments , 'UTF-8');
                        // $yShipments -= $topMargin - 5;
                    // }
                // } else {
                    // $yShipments -= $topMargin - 5;
                // }
    
                $currentY = min($yPayments, $yShipments);
    
                // replacement of Shipments-Payments rectangle block
                $page->drawLine(25,  $methodStartY, 25,  $currentY); //left
                $page->drawLine(25,  $currentY,     570, $currentY); //bottom
                $page->drawLine(570, $currentY,     570, $methodStartY); //right
    
                $this->y = $currentY;
                $this->y -= 15;
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误