Skip to content

Instantly share code, notes, and snippets.

@metaxy
Created February 22, 2018 09:29
Show Gist options
  • Save metaxy/52d2f874a8a68eb066f0f17effbc23e5 to your computer and use it in GitHub Desktop.
Save metaxy/52d2f874a8a68eb066f0f17effbc23e5 to your computer and use it in GitHub Desktop.
Export all Magento Invoices as PDF
<?php
// this file should be copied to root
require_once('app/Mage.php');
Mage::app();
$maxOrderId = 24346;
for($orderId = 1; $orderId < $maxOrderId; $orderId++) {
$orderObject = Mage::getModel('sales/order')->load($orderId);
echo "$orderId of $maxOrderId\n";
$invoiceCollection = $orderObject->getInvoiceCollection();
try {
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoiceCollection);
$time = new DateTime($orderObject->updated_at);
$id = $orderObject->getIncrementId();
$name = 'i_'.$orderId.'_'.$id.'_'.$time->format('Y-m-d_H-i-s'). '.pdf';
mkdir(Mage::getBaseDir('var'). DS . 'tmp' . DS. $time->format('Y'), 0777);
mkdir(Mage::getBaseDir('var'). DS . 'tmp' . DS. $time->format('Y') . DS . $time->format('m'), 0777);
$pdf->save(Mage::getBaseDir('var'). DS . 'tmp' . DS. $time->format('Y') . DS . $time->format('m') . DS. $name);
} catch (Exception $e) {
echo 'Not possible:', $e->getMessage(), "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment