How do I get a barcode in Magento email template
I found this out while scouring the net on my quest for all my other recent problems.
Zend has a built in barcode generation class, Zend_Barcode. Then googling php image output, I put together this little script I uploaded to var/export/_barcode.php:
<?php require_once '../../app/Mage.php'; umask(0); Mage::app(); Mage::app()->loadArea(Mage_Core_Model_App_Area::AREA_FRONTEND); if( isset($_GET['ord']) && strlen($_GET['ord']) > 5 ) { header('Content-Type: image/jpeg'); $barcodeOptions = array('text' => $_GET['ord']); $rendererOptions = array(); // Draw the barcode in a new image, $imageResource = Zend_Barcode::draw( 'code39', 'image', $barcodeOptions, $rendererOptions ); imagejpeg($imageResource); } else { echo "<pre><b>Error:</b> required input not found\n"; } ?>
If you visit this script’s URL with the standard GET, you’ll be served a scannable barcode. So put this in your Transactional Email template:
<img src="http://yourmagentowebsite.com/var/export/_barcode.php?ord={{var order.increment_id}}" alt="{{var order.increment_id}}" style="margin-bottom:10px;" border="0"/>