Whats new?
This is an old revision of the document!
A quick fix to add a pop up print label print window in the orders page. Thought it might be useful for someone. This uses the default admin template, so you would need to refresh on Magento upgrade. Have left red border so you can use to position the label.
Edit view.phtml |
Download the file /app/design/adminhtml/default/default/template/sales/order/view/info.phtml
Around line 171 of this file, just after Shipping Address Title <h4 class=”icon-head head-shipping-address”><?php echo Mage::helper(’sales’)→__(’Shipping Address’) ?></h4>
add this
<span style="float:right"><a href='#' style="color:#FFCC22" onclick="labelPrint()" >Print Shipping Label</a></span>
at the bottom of info.phtml add this:
<script type="text/javascript">
/* <![CDATA[ */
<?php
$shipaddr= $_order->getShippingAddress()->getFormated(true);
$splitx=explode("\\n",$shipaddr);
$inx=array('<br />','<br/>',' ');
$outx=array('','','');
$shipx='';
foreach($splitx as $sx):
if(!empty($sx) && substr($sx,0,3)!='T: '):
$shipx.=str_replace($inx,$outx,$sx).'@@';
endif;
endforeach;
echo "n".'var shipx="'.$shipx.'"; '."n" ;
?>
var popUpWin=0;
function labelPrint() {
var url='/label.html?addr='+shipx;
//
popUpWin = open(url,'popUpWin','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,copyhistory=yes, width=500,height=250,left=100,top=100,screenX=100,screenY=100');
}
/* ]]> */
</script>
Create label.html |
then create file label html and upload to Magento web root folder.
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Print Shipping Label</title>
<style type="text/css" media="all">
* { margin:0; padding:0; }
#address {
/**********ADJUST THE CSS VALUES BELOW FOR THE PRINT LABEL PAGE ***********/
font-size:17pt;
top:30px;
left:20px;
width:400px;
height:210px;
line-height:120%;
/**************************************************************/
border:1px solid red;
font-weight:bold;
position:absolute;
}
#printBTN { float:right;margin:2px 5px 0 0 !important; }
</style>
<style type="text/css" media="print">
#printBTN {visibility:hidden;}
</style>
</head>
<body>
<div id="printBTN"><input type="button" value="Print" onClick="window.print()" /></div>
<div id='address'>
<script type="text/javascript">
/* <![CDATA[ */
var str=location.href; var output='';
str=str.substr(str.indexOf("addr=")+5);
str=str.replace(/%20/g,' ');
output=str.replace(/@@/g, "<br />");
document.write(output);
/* ]]> */
</script>
</div></body></html>
You can then just adjust the popup label.html to size and position on printing.
use CMS |
If you prefer you could also use the CMS/Manage Pages - first create a page with no layout and with the URL identifier print_label
then change the URL var in info.phtml var url=’/print_label?addr=’+shipx;
then edit the CMS page adding this code
<style type="text/css" media="all">
* { margin:0; padding:0; }
#address {
/**********ADJUST THE CSS VALUES BELOW FOR THE PRINT LABEL PAGE ***********/
font-size:17pt;
top:30px;
left:20px;
width:400px;
height:210px;
line-height:120%;
/**************************************************************/
border:1px solid red;
font-weight:bold;
position:absolute;
}
#printBTN { float:right;margin:2px 5px 0 0 !important;}</style><style type="text/css" media="print">
#printBTN {visibility:hidden;}</style></p><div id="printBTN"><input type="button" onClick="window.print()" value="Print" /></div><div id="address"><script type="text/javascript">
var str=location.href; var output='';
str=str.substr(str.indexOf("addr=")+5);
str=str.replace(/%20/g,' ');
output=str.replace(/@@/g, "<br />");
document.write(output);
</script>


