So I'll explain this as well as I can, please feel free to ask questions if I need to clarify anything.
- We create credentials from PDF's.
- The background image is already printed onto a piece of paper (A4: Landscape)
- From inputs in our products (Custom Options > Name and Date) and an incrementing credential number which is stored in our database; we overlay these on our A4 papers at specific coordinates to print a final product ourselves.
We typically sell around 400 ~ 900 of these a day, so we would need a combined PDF sheet that generates/adds all these to single printable document. How these are segregated from yesterdays orders or todays orders, or orders after printing todays orders doesn't matter. It could be by LAST credential number, or by date/time cut-off, or whatever. It's negligable as long as there is not duplicates.
Things I would like to see is the ability for the user to preview their credential prior to submission (JQuery would most likely fit the bill, I envisioned updating the preview image from the input fields), the ability to use a filter array or list (could be a flatfile?) so we can remove banned words, and lastly so we can correct mistakes even the the user makes them, a way to edit the PDF's, either direclty through a tool.
I've been looking around for a plugin or module for the last week that I could at least get a starting point on to do this. If not this is something that will need to be created from scratch. I looked at web to print by Zetaprints briefly but there is not only a complicated install process, but also a pay per use of about a $1.70 that would quickly eat into our profit margins.
What we do now This is the old version that we used with OSCommerce that will need to be replaced by a Magento equivalent.
Old Version with Edit Capabilities: http://pastebin.com/pafG0RLZ
New Version without Editing: http://pastebin.com/b4a3kim1
Here is the physical code of the new version that would need some kind of integration. Please stop downvoting me based on "theoretical concepts" since this is already a working product that needs integration.
case "Ordination Credentials":
// hack -jd
include ('class.ezpdf.php');
$pdf =& new Cezpdf('LETTER','landscape');
$pdf->selectFont('./fonts/mtcorsva.afm');
$pdf->ezSetMargins(30,1,30,1);
extract($_GET);
$query = "
SELECT o.date_purchased,
fd.template_fn,
o.customers_name,
op.orders_id,
opa.orders_products_id,
products_name,
op.products_quantity,
field_name,
products_options_values
FROM orders_products AS op
JOIN orders AS o ON o.orders_id = op.orders_id
JOIN fulfillment_doc_products AS fdp ON fdp.product_id = op.products_id
JOIN fulfillment_docs AS fd ON fd.doc_id = fdp.doc_id
JOIN orders_products_attributes AS opa ON opa.orders_products_id = op.orders_products_id
RIGHT JOIN fulfillment_doc_fields AS fdf ON fdf.products_options_name = opa.products_options
AND fdf.doc_products_id = fdp.doc_products_id
WHERE op.orders_id
BETWEEN $in
AND $out
AND fd.doc_id = $doc_id
ORDER BY o.orders_id, products_name, opa.orders_products_id, field_name, products_options_values";
$result = mysql_query(trim($query)) or die("Broke the interwebs.");
while ($query_data = mysql_fetch_array($result)) {
//Standard db output filtering and processing into multi-dimensional array as seen above
$creds[$query_data['orders_products_id']][$query_data['field_name']] = sanitize_db_output($query_data['products_options_values']);
$creds[$query_data['orders_products_id']]['order_number'] = $query_data['orders_id'];
$creds[$query_data['orders_products_id']]['products_quantity'] = $query_data['products_quantity'];
}
$started = false;
foreach( $creds as $opt ) {
if($started) { $pdf->ezNewPage(); } //create new page
$started = true;
$name = ucwords(strtolower($opt['name']));
foreach (array('-', '\'',' Mc') as $delimiter) {
if (strpos($name, $delimiter) == true) {
$name = implode($delimiter, array_map('ucfirst', explode($delimiter, $name)));
}
}
//all caps
foreach (array('Ii', 'Iii') as $delimiter) {
if (strpos($name, $delimiter) == true) {
$name = implode($delimiter, array_map('strtoupper', explode($delimiter, $name)));
}
}
if(strpos($name, ',') !== false) {
foreach (array(', Jr', ', Sr') as $delimiter) {
if (strpos($name, $delimiter) == false) {
$name=implode(" ", array_reverse(explode(',', $name)));
}
}
}
$day = $opt["date-day"];
if (0<>$day) {
if (in_array($day% 100, range(11,13))) {
$day .= 'th';
} else {
switch ( $day % 10 ) {
case 1: $day .= 'st'; break;
case 2: $day .= 'nd'; break;
case 3:开发者_如何学C $day .= 'rd'; break;
default: $day .= 'th'; break;
}
}
}
$month = $opt["date-month"];
$year = $opt["date-year"];
$ordid = $opt["order_number"];
//create date
if (!isset($yname)) { $yname = "370"; }
if (!isset($ydate)) { $ydate = "289"; }
$pdf->ezSetY($yname); $pdf->ezText($name,28,array('left'=>-35, 'justification'=>'center'));
$pdf->ezSetY($ydate); $pdf->ezText($day,17,array('left'=>-220, 'justification'=>'center'));
$pdf->ezSetY($ydate); $pdf->ezText($month,17,array('left'=>40, 'justification'=>'center'));
$pdf->ezSetY($ydate); $pdf->ezText($year,17,array('left'=>375, 'justification'=>'center'));
$pdf->ezSetY(96); $pdf->ezText($ordid,12,array('left'=>505, 'justification'=>'center'));
}
$pdfcode = $pdf->output();
$file = './tmp/PDF_ordinations.pdf';
if (file_exists($fname)) { unlink($fname); } //start with new file
if (!file_exists($dir)) { mkdir ($dir,0777); } //dir create if not there
$fname = $file;
$fp = fopen($fname,'w');
fwrite($fp,$pdfcode);
fclose($fp);
header('Location:'.$fname);
break;
精彩评论