/** * @param Mage_Sales_Model_Abstract $itemContainer * @return array */ public function extractAdditionalParams(Mage_Sales_Model_Abstract $itemContainer = null) { $invoice = null; if ($itemContainer instanceof Mage_Sales_Model_Order_Invoice && $itemContainer) { $invoice = $itemContainer; } else { if ($itemContainer instanceof Mage_Sales_Block_Order_Creditmemo && $itemContainer) { $invoice = Mage::getModel('sales/order_invoice')->load($itemContainer->getInvoiceId()); } } if ($invoice == null) { // if invoice is not set we load id hard from the request params $invoice = $this->getRefundHelper()->getInvoiceFromCreditMemoRequest(); } $this->creditmemo = $this->getRefundHelper()->getCreditMemoFromRequest(); if ($invoice instanceof Mage_Sales_Model_Order_Invoice) { $this->extractFromCreditMemoItems($invoice); // We dont extract from discount data for the moment, because partial refunds are a problem // $this->extractFromDiscountData($invoice); $this->extractFromInvoicedShippingMethod($invoice); $this->extractFromAdjustments($invoice); // Overwrite amount to fix Magentos rounding problems (eg +1ct) $this->additionalParams['AMOUNT'] = $this->amount; } return $this->additionalParams; }
/** * @param Mage_Sales_Model_Abstract $entity * @param Mage_Sales_Model_Order $order * @param string $context * * @return mixed */ protected function getAllOrderItems($entity, $order, $context) { $this->_order = $order; if ($context == self::TYPE_RS) { return $entity->getAllItems(); } return $order->getAllItems(); }
/** * Before object save * * @return Mage_Sales_Model_Order_Creditmemo_Comment */ protected function _beforeSave() { parent::_beforeSave(); if (!$this->getParentId() && $this->getCreditmemo()) { $this->setParentId($this->getCreditmemo()->getId()); } return $this; }
/** * Return total list * * @param Mage_Sales_Model_Abstract $source * @return array */ protected function _getTotalsList($source) { $nodeName = Mage::helper('zab_billing')->getTotalConfigPath($source->getTipo()); $totals = Mage::getConfig()->getNode($nodeName)->asArray(); usort($totals, array($this, '_sortTotalsList')); $totalModels = array(); foreach ($totals as $index => $totalInfo) { if (!empty($totalInfo['model'])) { $totalModel = Mage::getModel($totalInfo['model']); if ($totalModel instanceof Mage_Sales_Model_Order_Pdf_Total_Default) { $totalInfo['model'] = $totalModel; } else { Mage::throwException(Mage::helper('sales')->__('PDF total model should extend Mage_Sales_Model_Order_Pdf_Total_Default')); } } else { $totalModel = Mage::getModel($this->_defaultTotalModel); } $totalModel->setData($totalInfo); $totalModels[] = $totalModel; } return $totalModels; }
/** * insert customer address and all header like customer number, etc. * * @param Zend_Pdf_Page $page current Zend_Pdf_Page * @param Mage_Sales_Model_Abstract $source source for the address information * @param Mage_Sales_Model_Order $order order to print the document for */ protected function insertAddressesAndHeader(Zend_Pdf_Page $page, Mage_Sales_Model_Abstract $source, Mage_Sales_Model_Order $order) { // Add logo $this->insertLogo($page, $source->getStore()); // Add billing address $this->y = 692 - $this->_marginTop; $this->_insertCustomerAddress($page, $order); // Add sender address $this->y = 705 - $this->_marginTop; $this->_insertSenderAddessBar($page); // Add head $this->y = 592 - $this->_marginTop; $this->insertHeader($page, $order, $source); /* Add table head */ // make sure that item table does not overlap heading if ($this->y > 575 - $this->_marginTop) { $this->y = 575 - $this->_marginTop; } }
/** * Create transaction, * prepare its insertion into hierarchy and add its information to payment and comments * * To add transactions and related information, * the following information should be set to payment before processing: * - transaction_id * - is_transaction_closed (optional) - whether transaction should be closed or open (closed by default) * - parent_transaction_id (optional) * - should_close_parent_transaction (optional) - whether to close parent transaction (closed by default) * * If the sales document is specified, it will be linked to the transaction as related for future usage. * Currently transaction ID is set into the sales object * This method writes the added transaction ID into last_trans_id field of the payment object * * To make sure transaction object won't cause trouble before saving, use $failsafe = true * * @param string $type * @param Mage_Sales_Model_Abstract $salesDocument * @param bool $failsafe * @return null|Mage_Sales_Model_Order_Payment_Transaction */ protected function _addTransaction($type, $salesDocument = null, $failsafe = false) { if ($this->getSkipTransactionCreation()) { $this->unsTransactionId(); return null; } // look for set transaction ids $transactionId = $this->getTransactionId(); if (null !== $transactionId) { // set transaction parameters $transaction = false; if ($this->getOrder()->getId()) { $transaction = $this->_lookupTransaction($transactionId); } if (!$transaction) { $transaction = Mage::getModel('sales/order_payment_transaction')->setTxnId($transactionId); } $transaction->setOrderPaymentObject($this)->setTxnType($type)->isFailsafe($failsafe); if ($this->hasIsTransactionClosed()) { $transaction->setIsClosed((int) $this->getIsTransactionClosed()); } //set transaction addition information if ($this->_transactionAdditionalInfo) { foreach ($this->_transactionAdditionalInfo as $key => $value) { $transaction->setAdditionalInformation($key, $value); } } // link with sales entities $this->setLastTransId($transactionId); $this->setCreatedTransaction($transaction); $this->getOrder()->addRelatedObject($transaction); if ($salesDocument && $salesDocument instanceof Mage_Sales_Model_Abstract) { $salesDocument->setTransactionId($transactionId); // TODO: linking transaction with the sales document } // link with parent transaction $parentTransactionId = $this->getParentTransactionId(); if ($parentTransactionId) { $transaction->setParentTxnId($parentTransactionId); if ($this->getShouldCloseParentTransaction()) { $parentTransaction = $this->_lookupTransaction($parentTransactionId); if ($parentTransaction) { if (!$parentTransaction->getIsClosed()) { $parentTransaction->isFailsafe($failsafe)->close(false); } $this->getOrder()->addRelatedObject($parentTransaction); } } } return $transaction; } }
/** * After object save manipulation * * @return Mage_Sales_Model_Order_Shipment */ protected function _afterSave() { if (null !== $this->_items) { /** * Save invoice items */ foreach ($this->_items as $item) { $item->setOrderItem($item->getOrderItem()); $item->save(); } } if (null !== $this->_comments) { foreach ($this->_comments as $comment) { $comment->save(); } } return parent::_afterSave(); }
/** * Insert totals to pdf page * * @param Zend_Pdf_Page $page * @param Mage_Sales_Model_Abstract $source * @return Zend_Pdf_Page */ protected function insertTotals($page, $source) { $order = $source->getOrder(); $totals = $this->_getTotalsList($source); $lineBlock = array('lines' => array(), 'height' => 15); foreach ($totals as $total) { $total->setOrder($order)->setSource($source); if ($total->canDisplay()) { $total->setFontSize(10); foreach ($total->getTotalsForDisplay() as $totalData) { $lineBlock['lines'][] = array(array('text' => $totalData['label'], 'feed' => 475, 'align' => 'right', 'font_size' => $totalData['font_size'], 'font' => 'bold'), array('text' => $totalData['amount'], 'feed' => 565, 'align' => 'right', 'font_size' => $totalData['font_size'], 'font' => 'bold')); } } } $this->y -= 20; $page = $this->drawLineBlocks($page, array($lineBlock)); return $page; }
/** * Add data to the object. * * Retains previous data in the object. * * @param array $data * @return Mage_Sales_Model_Order_Shipment_Track */ public function addData(array $data) { if (array_key_exists('number', $data)) { $this->setNumber($data['number']); unset($data['number']); } return parent::addData($data); }
/** * Protect order delete from not admin scope * @return Mage_Sales_Model_Order */ protected function _beforeDelete() { $this->_protectFromNonAdmin(); return parent::_beforeDelete(); }
/** * Check whether order entity may be saved * * Invoice, shipment, creditmemo (address & item?) * * @param Mage_Sales_Model_Abstract $model */ public function salesOrderEntitySaveBefore($model) { $this->_salesEntitySaveBefore(Mage::app()->getStore($model->getOrder()->getStoreId())->getWebsiteId()); }
/** * Insert totals to pdf page * * @param Zend_Pdf_Page $page * @param Mage_Sales_Model_Abstract $source * @return Zend_Pdf_Page */ protected function insertTotals($page, $source) { // remvoeme $this->y += 40; if ($this->y - 150 < 15) { $page = $this->newPage($pageSettings); } $order = $source->getOrder(); $totals = $this->_getTotalsList($source); $lineBlock = array('lines' => array(), 'height' => 20); $this->y -= 30; $page->setFillColor(new Zend_Pdf_Color_Html("#58a300")); $page->setLineColor(new Zend_Pdf_Color_GrayScale(1)); $page->setLineWidth(0.5); $page->drawRectangle(275, $this->y, 570, $this->y - 30); $this->_setFontBold($page, 12); $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $page->drawText(Mage::helper('sales')->__('Betrag'), 285, $this->y - 20, 'UTF-8'); $this->sy = $this->y; $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->y -= 30; foreach ($totals as $total) { $total->setOrder($order)->setSource($source); if ($total->canDisplay()) { $total->setFontSize(10); foreach ($total->getTotalsForDisplay() as $totalData) { $fontSize = 7; if ("Gesamt (inkl. Steuern):" === $totalData["label"]) { $fontSize = 10; } if (false !== strpos($totalData["label"], "Produkte zu 19")) { continue; } if ("Steuer:" === $totalData["label"]) { $totalData["label"] = "19% MwSt."; } $totalData["label"] = str_replace("Steuern", "MwSt.", $totalData["label"]); $lineBlock['lines'][] = array(array('text' => $totalData['label'], 'feed' => 475, 'align' => 'right', "font_size" => 7, 'font' => 'bold'), array('text' => $totalData['amount'], 'feed' => 525, 'align' => 'right', "font_size" => $fontSize, 'font' => 'bold')); } } } $this->y -= 20; $page = $this->drawLineBlocks($page, array($lineBlock)); return $page; }
/** * Insert totals to pdf page * * @param Zend_Pdf_Page $page * @param Mage_Sales_Model_Abstract $source * @return Zend_Pdf_Page */ protected function insertTotals($page, $source) { $order = $source->getOrder(); $totals = $this->_getTotalsList($source); $lineBlock = array('lines' => array(), 'height' => 15); foreach ($totals as $total) { $total->setOrder($order)->setSource($source); if ($total->canDisplay()) { $total->setFontSize(10); foreach ($total->getTotalsForDisplay() as $totalData) { if (isset($totalData['title']) && strpos($totalData['title'], '%') !== false) { $origLabel = $totalData['label']; $totalData['label'] = trim(preg_replace('/\\s*\\([^)]*\\)/', '', $origLabel)); #echo "<pre/>";print_r($totalData);die; } Mage::log(print_r($totalData, true), NULL, 'developerTotalAfter.log'); $lineBlock['lines'][] = array(array('text' => $totalData['label'], 'feed' => 475, 'align' => 'right', 'font_size' => $totalData['font_size'], 'font' => 'bold'), array('text' => $totalData['amount'], 'feed' => 565, 'align' => 'right', 'font_size' => $totalData['font_size'], 'font' => 'bold')); } } } $this->y -= 20; $page = $this->drawLineBlocks($page, array($lineBlock)); return $page; }
/** * Create transaction, prepare its insertion into hierarchy and add its information to payment and comments * * To add transactions and related information, the following information should be set to payment before processing: * - transaction_id * - is_transaction_closed (optional) - whether transaction should be closed or open (closed by default) * - parent_transaction_id (optional) * - should_close_parent_transaction (optional) - whether to close parent transaction (closed by default) * * If the sales document is specified, it will be linked to the transaction as related for future usage. * Currently transaction ID is set into the sales object * This method writes the added transaction ID into last_trans_id field of the payment object * * To make sure transaction object won't cause trouble before saving, use $failsafe = true * * @param Mage_Sales_Model_Order_Payment * @param string $type * @param Mage_Sales_Model_Abstract $salesDocument * @param bool $failsafe * @return null|Mage_Sales_Model_Order_Payment_Transaction */ protected function _addTransaction($payment, $type, $salesDocument = null, $failsafe = false) { // look for set transaction ids $transactionId = $payment->getTransactionId(); if (null !== $transactionId) { // set transaction parameters /*$transaction = Mage::getModel('sales/order_payment_transaction') ->setOrderPaymentObject($payment) ->setTxnType($type) ->setTxnId($transactionId) ->isFailsafe($failsafe) ;*/ // set transaction parameters //$transaction = false; $transaction = $this->_lookupTransaction($payment, $transactionId); if (!$transaction) { $transaction = Mage::getModel('sales/order_payment_transaction')->setTxnId($transactionId); } $transaction->setOrderPaymentObject($payment)->setTxnType($type)->isFailsafe($failsafe); if ($payment->hasIsTransactionClosed()) { $transaction->setIsClosed((int) $payment->getIsTransactionClosed()); } // link with sales entities $payment->setLastTransId($transactionId); $payment->setCreatedTransaction($transaction); $payment->getOrder()->addRelatedObject($transaction); if ($salesDocument && $salesDocument instanceof Mage_Sales_Model_Abstract) { $salesDocument->setTransactionId($transactionId); // TODO: linking transaction with the sales document } // link with parent transaction Not used because transaction Id is the same $parentTransactionId = $payment->getParentTransactionId(); if ($parentTransactionId) { $transaction->setParentTxnId($parentTransactionId); if ($payment->getShouldCloseParentTransaction()) { $parentTransaction = $this->_lookupTransaction($payment, $parentTransactionId); // if ($parentTransaction) { $parentTransaction->isFailsafe($failsafe)->close(false); $payment->getOrder()->addRelatedObject($parentTransaction); } } } return $transaction; } }
/** * After object save manipulations * * @return Mage_Sales_Model_Order_Shipment */ protected function _afterSave() { if (null !== $this->_items) { foreach ($this->_items as $item) { $item->save(); } } if (null !== $this->_tracks) { foreach ($this->_tracks as $track) { $track->save(); } } if (null !== $this->_comments) { foreach ($this->_comments as $comment) { $comment->save(); } } return parent::_afterSave(); }
/** * @param Mage_Sales_Model_Abstract $object * @return string */ protected function fetchNewIncrementId(Mage_Sales_Model_Abstract $object) { $entityTypeModel = $this->getFactory()->getModelEavEntityType(); $code = ''; if ($object instanceof Mage_Sales_Model_Order_Invoice) { $code = 'invoice'; } elseif ($object instanceof Mage_Sales_Model_Order_Creditmemo) { $code = 'creditmemo'; } $entityType = $entityTypeModel->loadByCode($code); $newIncrementId = $entityType->fetchNewIncrementId($this->getStoreId()); if ($newIncrementId !== false) { $object->setIncrementId($newIncrementId); } return $newIncrementId; }
/** * @param Mage_Customer_Model_Address_Abstract|Mage_Sales_Model_Abstract $magentoObject * @param ShopgateOrder|ShopgateAddress|ShopgateCustomer $shopgateObject * @return mixed */ public function setCustomFields($magentoObject, $shopgateObject) { foreach ($shopgateObject->getCustomFields() as $field) { $magentoObject->setData($field->getInternalFieldName(), $field->getValue()); } return $magentoObject; }
/** * Before object save manipulations * * @return Mage_Sales_Model_Order_Creditmemo */ protected function _beforeSave() { parent::_beforeSave(); if (!$this->getOrderId() && $this->getOrder()) { $this->setOrderId($this->getOrder()->getId()); $this->setBillingAddressId($this->getOrder()->getBillingAddress()->getId()); } return $this; }
/** * Set order again if required * @return Mage_Sales_Model_Order_Status_History */ protected function _beforeSave() { if ($this->_shouldSetOrderBeforeSave) { $this->setOrder($this->_order); } return parent::_beforeSave(); }