www.sebastian-enzinger.de * * All rights reserved. * **/ class Enzinger_GridActions_GridController extends Mage_Adminhtml_Controller_Action { public function printLotTravelerAction() { $orderIds = $this->getRequest()->getParam('order_ids'); $flag = false; if (!empty($orderIds)) { foreach ($orderIds as $orderId) { $invoices = Mage::getResourceModel('sales/order_invoice_collection') ->setOrderFilter($orderId) ->load(); if ($invoices->getSize() > 0) { $flag = true; if (!isset($pdf)){ $pdf = Mage::getModel('sales/order_pdf_lottraveler')->getPdf($invoices); } else { $pages = Mage::getModel('sales/order_pdf_lottraveler')->getPdf($invoices); $pdf->pages = array_merge ($pdf->pages, $pages->pages); } //echo $orderId; //$order = Mage::getModel('sales/order')->loadByIncrementId($orderId); //echo $order->getStatus(); //$order->setStatus('processing_invoiced'); //$transactionSave = Mage::getModel('core/resource_transaction') // ->addObject($order) // ->save(); } } if ($flag) { return $this->_prepareDownloadResponse('lottraveler'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').'.pdf', $pdf->render(), 'application/pdf'); } else { $this->_getSession()->addError($this->__('There are no printable documents related to selected orders.')); $this->_redirect('adminhtml/sales_order'); } } $this->_redirect('adminhtml/sales_order'); } public function massActionAction() { $orderIds = $this->getRequest()->getParam('order_ids'); if ($this->getRequest()->getParam('email', 0) == 1) { $sendEmails = true; } else { $sendEmails = false; } if ($this->getRequest()->getParam('invoice', 0) == 1) { $doInvoice = true; } else { $doInvoice = false; } if ($this->getRequest()->getParam('build', 0) == 1) { $doBuild = true; } else { $doBuild = false; } if ($this->getRequest()->getParam('ship', 0) == 1) { $doShip = true; } else { $doShip = false; } if ($this->getRequest()->getParam('complete', 0) == 1) { $doComplete = true; } else { $doComplete = false; } if ($this->getRequest()->getParam('delete', 0) == 1) { $doDelete = true; } else { $doDelete = false; } $modifiedCount = 0; if (!is_array($orderIds)) { $this->_getSession()->addError($this->__('Please select Order(s)')); } else { try { foreach ($orderIds as $orderId) { $isModified = false; $order = Mage::getModel('sales/order')->load((int)$orderId); if (!$order || !$order->getId()) { $this->_getSession()->addError('Could not load Order'); $this->getResponse()->setRedirect($this->getUrl('*')); return; } if ($doInvoice && $order->canInvoice()) { $invoice = $order->prepareInvoice(); $invoice->register(); $invoice->setEmailSent($sendEmails); //if ($invoice->canCapture()) { // $invoice->capture(); //} $invoice->pay(); //$invoice->getOrder()->setIsInProcess(true); //$invoice->getOrder()->setStatus('processing_invoiced'); $transactionSave = Mage::getModel('core/resource_transaction') ->addObject($invoice) ->addObject($invoice->getOrder()) ->save(); if ($sendEmails) $invoice->sendEmail($sendEmails, ''); unset($invoice); $isModified = true; } if ($doBuild && $order->getStatus() == 'processing') { //$invoice = $invoice->setOrder($order); //echo $doBuild; //$invoice->getOrder()->setIsInProcess(true); $order->setStatus('processing_invoiced'); $transactionSave = Mage::getModel('core/resource_transaction') ->addObject($order) ->save(); //unset($invoice); $isModified = true; } if ($doShip && $order->canShip()) { $convertor = Mage::getModel('sales/convert_order'); $shipment = $convertor->toShipment($order); foreach ($order->getAllItems() as $orderItem) { if (!$orderItem->getQtyToShip()) { continue; } if ($orderItem->getIsVirtual()) { continue; } $item = $convertor->itemToShipmentItem($orderItem); $qty = $orderItem->getQtyToShip(); $item->setQty($qty); $shipment->addItem($item); } $shipment->register(); $shipment->setEmailSent($sendEmails); //$shipment->getOrder()->setStatus('in_process'); $transactionSave = Mage::getModel('core/resource_transaction') ->addObject($shipment) ->addObject($shipment->getOrder()) ->save(); if ($sendEmails) $shipment->sendEmail($sendEmails, ''); $isModified = true; } if ($doComplete && ($order->getStatus() !== 'complete' && $order->getStatus() !== 'canceled' && $order->getStatus() !== 'closed')) { $order->setStatus(Mage_Sales_Model_Order::STATE_COMPLETE); $order->save(); $isModified = true; } if ($doDelete && ($order->getState() === Mage_Sales_Model_Order::STATE_CANCELED && !$order->hasCreditmemos() && !$order->hasShipments() && !$order->hasInvoices())) { $order->delete(); $isModified = true; } if ($isModified) $modifiedCount++; } $this->_getSession()->addSuccess($this->__('Total of %d order(s) were modified.', $modifiedCount)); } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); } } $this->_redirect('adminhtml/sales_order'); } }