Last active
January 14, 2016 10:56
-
-
Save mmenozzi/de2b7d8a72e2b6e69223 to your computer and use it in GitHub Desktop.
Rendering Magento 1.x email order items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ------------------------------------------------- | |
// Override useful ini values | |
// ------------------------------------------------- | |
set_time_limit(0); // avoid any time limit | |
ini_set('memory_limit', -1); // avoid any memory limit | |
// ------------------------------------------------- | |
// Include Magento Core | |
// ------------------------------------------------- | |
require_once 'app/Mage.php'; | |
// ------------------------------------------------- | |
// Load and Start Magento Application runtime | |
// ------------------------------------------------- | |
// Trick reference: | |
// http://www.magentocommerce.com/boards/viewthread/38379/#t189142 | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
umask(0); | |
// ------------------------------------------------- | |
// Init an admin user session | |
// ------------------------------------------------- | |
Mage::app()->loadArea(Mage_Core_Model_App_Area::AREA_FRONTEND); | |
$order = Mage::getModel('sales/order')->load(1); | |
$layout = Mage::app()->getLayout(); | |
$layout->setArea(Mage_Core_Model_App_Area::AREA_FRONTEND); | |
$layout->getUpdate()->addHandle('sales_email_order_items'); | |
$layout->getUpdate()->load(); | |
$layout->generateXml(); | |
$layout->generateBlocks(); | |
foreach ($layout->getAllBlocks() as $blockName => $block) { | |
/* @var $block Mage_Core_Block_Abstract */ | |
$block->setOrder($order); | |
} | |
$allBlocks = $layout->getAllBlocks(); | |
$firstBlock = reset($allBlocks); | |
if ($firstBlock) { | |
$layout->addOutputBlock($firstBlock->getNameInLayout()); | |
} | |
$layout->setDirectOutput(false); | |
?> | |
<html> | |
<meta charset="UTF-8"> | |
<head></head> | |
<body> | |
<?php echo $layout->getOutput(); ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment