public function getPdf($invoices = array()) { foreach ($invoices as $invoice) { if ($invoice->getOrder()->getPayment()->getMethod() != 'sofortrechnung') { return parent::getPdf($invoices); } break; } $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) { if ($invoice->getStoreId()) { Mage::app()->getLocale()->emulate($invoice->getStoreId()); Mage::app()->setCurrentStore($invoice->getStoreId()); } $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; $order = $invoice->getOrder(); $tid = $order->getPayment()->getPnSuTransactionId(); if (!empty($tid)) { $sObj = new SofortLib_TransactionData(Mage::getStoreConfig('payment/sofort/configkey')); $sObj->setTransaction($tid)->sendRequest(); if ($sObj->isError()) { Mage::throwException(Mage::helper('sales')->__($sObj->getError())); return; } else { $url = $sObj->getInvoiceUrl(); $pdf = file_get_contents($url); return Zend_Pdf::parse($pdf); } } /* 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())); $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $this->_setFontRegular($page); $page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780, 'UTF-8'); /* 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); $page->drawRectangle(25, $this->y, 570, $this->y - 15); $this->y -= 10; /* Add table head */ $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4)); $page->drawText(Mage::helper('sales')->__('Products'), 35, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('SKU'), 255, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8'); $this->y -= 15; $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); /* Add body */ foreach ($invoice->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); } /* Add totals */ $page = $this->insertTotals($page, $invoice); if ($invoice->getStoreId()) { Mage::app()->getLocale()->revert(); } } $this->_afterGetPdf(); return $pdf; }
/** * Construct the SofortLib_TransactionData object * Collect every order's item and set it accordingly * TransactionData is used encapsulated in this class to retrieve information about the order's details * @return object SofortLib_TransactionData * @private */ private function _setupTransactionData() { $SofortLib_TransactionData = new SofortLib_TransactionData($this->_configKey, $this->_apiUrl); $SofortLib_TransactionData->setTransaction($this->_transactionId); $SofortLib_TransactionData->sendRequest(); if (!$SofortLib_TransactionData->getCount()) { return false; } $this->setStatus($SofortLib_TransactionData->getStatus()); $this->setStatusReason($SofortLib_TransactionData->getStatusReason()); $this->setStatusOfInvoice($SofortLib_TransactionData->getInvoiceStatus()); $this->setInvoiceObjection($SofortLib_TransactionData->getInvoiceObjection()); $this->setLanguageCode($SofortLib_TransactionData->getLanguageCode()); $this->setTransaction($this->getTransactionId()); $this->setTime($SofortLib_TransactionData->getTime()); $this->setPaymentMethod($SofortLib_TransactionData->getPaymentMethod()); $this->setInvoiceUrl($SofortLib_TransactionData->getInvoiceUrl()); $this->setAmount($SofortLib_TransactionData->getAmount()); $this->setAmountRefunded($SofortLib_TransactionData->getAmountRefunded()); $itemArray = $SofortLib_TransactionData->getItems(); // should there be any items, fetch them accordingly $this->_items = array(); if (is_array($itemArray) && !empty($itemArray)) { foreach ($itemArray as $item) { $this->setItem($item['item_id'], $item['product_number'], $item['product_type'], $item['title'], $item['description'], $item['quantity'], $item['unit_price'], $item['tax']); $this->_amount += $item['unit_price'] * $item['quantity']; } } /* * set the state according to the state given by transaction information (status, status_reason, invoice_status) * @see $statusMask */ $this->setState($this->_calcInvoiceStatusCode()); return $SofortLib_TransactionData; }
private function _setupTransactionData() { $SofortLib_TransactionData = new SofortLib_TransactionData($this->_configKey, $this->_apiUrl); $SofortLib_TransactionData->setTransaction($this->_transactionId); $SofortLib_TransactionData->sendRequest(); if (!$SofortLib_TransactionData->getCount()) { return false; } $this->setStatus($SofortLib_TransactionData->getStatus()); $this->setStatusReason($SofortLib_TransactionData->getStatusReason()); $this->setStatusOfInvoice($SofortLib_TransactionData->getInvoiceStatus()); $this->setInvoiceObjection($SofortLib_TransactionData->getInvoiceObjection()); $this->setLanguageCode($SofortLib_TransactionData->getLanguageCode()); $this->setTransaction($this->getTransactionId()); $this->setTime($SofortLib_TransactionData->getTime()); $this->setPaymentMethod($SofortLib_TransactionData->getPaymentMethod()); $this->setInvoiceUrl($SofortLib_TransactionData->getInvoiceUrl()); $this->setAmount($SofortLib_TransactionData->getAmount()); $this->setAmountRefunded($SofortLib_TransactionData->getAmountRefunded()); $itemArray = $SofortLib_TransactionData->getItems(); $this->_items = array(); if (is_array($itemArray) && !empty($itemArray)) { foreach ($itemArray as $item) { $this->setItem($item['item_id'], $item['product_number'], $item['product_type'], $item['title'], $item['description'], $item['quantity'], $item['unit_price'], $item['tax']); $this->_amount += $item['unit_price'] * $item['quantity']; } } $this->setState($this->_calcInvoiceStatusCode()); return $SofortLib_TransactionData; }