Exemplo n.º 1
0
 /**
  * Overriden to add call for _drawCheckoutFields method
  *
  * @param  array $invoices
  * @return Zend_Pdf
  */
 public function getPdf($shipments = array())
 {
     if (!Mage::getStoreConfigFlag('checkoutfields/print/pdf_packingslip')) {
         return parent::getPdf($shipments);
     }
     $this->_beforeGetPdf();
     $this->_initRenderer('shipment');
     $pdf = new Zend_Pdf();
     $this->_setPdf($pdf);
     $style = new Zend_Pdf_Style();
     $this->_setFontBold($style, 10);
     foreach ($shipments as $shipment) {
         if ($shipment->getStoreId()) {
             Mage::app()->getLocale()->emulate($shipment->getStoreId());
             Mage::app()->setCurrentStore($shipment->getStoreId());
         }
         if (method_exists($this, 'insertDocumentNumber')) {
             $page = $this->newPage();
             $order = $shipment->getOrder();
             /* Add image */
             $this->insertLogo($page, $shipment->getStore());
             /* Add address */
             $this->insertAddress($page, $shipment->getStore());
             /* Add head */
             $this->insertOrder($page, $shipment, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID, $order->getStoreId()));
             /* Add document text and number */
             $this->insertDocumentNumber($page, Mage::helper('sales')->__('Packingslip # ') . $shipment->getIncrementId());
             // override start
             $this->_drawCheckoutFields($page, $order);
             // override end
             /* Add table */
             $this->_drawHeader($page);
             /* Add body */
             foreach ($shipment->getAllItems() as $item) {
                 if ($item->getOrderItem()->getParentItem()) {
                     continue;
                 }
                 /* Draw item */
                 $this->_drawItem($item, $page, $order);
                 $page = end($pdf->pages);
             }
         } else {
             $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
             $pdf->pages[] = $page;
             $order = $shipment->getOrder();
             /* Add image */
             $this->insertLogo($page, $shipment->getStore());
             /* Add address */
             $this->insertAddress($page, $shipment->getStore());
             /* Add head */
             $this->insertOrder($page, $shipment, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID, $order->getStoreId()));
             $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
             $this->_setFontRegular($page);
             $page->drawText(Mage::helper('sales')->__('Packingslip # ') . $shipment->getIncrementId(), 35, 780, 'UTF-8');
             // override start
             $this->_drawCheckoutFields($page, $order);
             // override end
             /* Add table */
             $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);
             /* Add table head */
             $page->drawRectangle(25, $this->y, 570, $this->y - 15);
             $this->y -= 10;
             $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
             $page->drawText(Mage::helper('sales')->__('Qty'), 35, $this->y, 'UTF-8');
             $page->drawText(Mage::helper('sales')->__('Products'), 60, $this->y, 'UTF-8');
             $page->drawText(Mage::helper('sales')->__('SKU'), 470, $this->y, 'UTF-8');
             $this->y -= 15;
             $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
             /* Add body */
             foreach ($shipment->getAllItems() as $item) {
                 if ($item->getOrderItem()->getParentItem()) {
                     continue;
                 }
                 if ($this->y < 15) {
                     $page = $this->newPage(array('table_header' => true));
                 }
                 /* Draw item */
                 $page = $this->_drawItem($item, $page, $order);
             }
         }
     }
     $this->_afterGetPdf();
     if ($shipment->getStoreId()) {
         Mage::app()->getLocale()->revert();
     }
     return $pdf;
 }
 public function getPdf($shipments = array())
 {
     $pdf = parent::getPdf($shipments);
     try {
         foreach ($shipments as $shipment) {
             if (!isset($pdf)) {
                 $pdf = new Zend_Pdf();
                 $curl = curl_init();
                 curl_setopt($curl, CURLOPT_URL, $shipment->getCommercialInvoiceUrl());
                 curl_setopt($curl, CURLOPT_TIMEOUT_MS, 1000);
                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
                 curl_setopt($curl, CURLOPT_HEADER, 0);
                 $contents = curl_exec($curl);
                 curl_close($curl);
                 $_pdf = new Zend_Pdf($contents);
                 foreach ($_pdf->pages as $page) {
                     $pdf->pages[] = clone $page;
                 }
                 $curl = curl_init();
                 curl_setopt($curl, CURLOPT_URL, $shipment->getPackingListUrl());
                 curl_setopt($curl, CURLOPT_TIMEOUT_MS, 1000);
                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
                 curl_setopt($curl, CURLOPT_HEADER, 0);
                 $contents = curl_exec($curl);
                 curl_close($curl);
                 $_pdf = new Zend_Pdf($contents);
                 foreach ($_pdf->pages as $page) {
                     $pdf->pages[] = clone $page;
                 }
             } else {
                 $curl = curl_init();
                 curl_setopt($curl, CURLOPT_URL, $shipment->getCommercialInvoiceUrl());
                 curl_setopt($curl, CURLOPT_TIMEOUT_MS, 1000);
                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
                 curl_setopt($curl, CURLOPT_HEADER, 0);
                 $commercialInvoice = curl_exec($curl);
                 curl_close($curl);
                 $curl = curl_init();
                 curl_setopt($curl, CURLOPT_URL, $shipment->getPackingListUrl());
                 curl_setopt($curl, CURLOPT_TIMEOUT_MS, 1000);
                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
                 curl_setopt($curl, CURLOPT_HEADER, 0);
                 $packingList = curl_exec($curl);
                 curl_close($curl);
                 $_pdf = new Zend_Pdf($commercialInvoice);
                 foreach ($_pdf->pages as $page) {
                     $pdf->pages[] = clone $page;
                 }
                 $_pdf = new Zend_Pdf($packingList);
                 foreach ($_pdf->pages as $page) {
                     $pdf->pages[] = clone $page;
                 }
             }
         }
     } catch (Exception $ex) {
         Mage::logException($ex);
     }
     return $pdf;
 }