forked from webmaniabr/NFeWooCommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-print.php
65 lines (44 loc) · 1.35 KB
/
class-print.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class WooCommerceNFePrint extends WooCommerceNFe {
function __construct(){}
/**
* Validate Plugin before Load
*
* @return boolean
*/
function print( $order_ids = array(), $is_massa = false ){
$data = [];
foreach ($order_ids as $order_id) {
$order_nfe_data = get_post_meta($order_id, 'nfe', true);
if(!$order_nfe_data){
continue;
} else {
array_push($data, $order_nfe_data[0]["url_danfe"]);
}
}
$result = ($data) ? $this->createPDF($data) : false;
if ($result["result"] == true){
$this->add_success( 'Arquivo de impressão gerado com sucesso.' );
$link = content_url().get_temp_dir().$result["file"].".pdf";
wp_redirect($link);
exit();
} else {
$this->add_error( "Erro ao gerar arquivo de impressão." );
}
return $result;
}
function createPDF($data){
$pdf = new PDFMerger();
foreach ($data as $value) {
$name = explode("/", $value);
file_put_contents( WP_CONTENT_DIR . get_temp_dir() . $name[4] .".pdf", file_get_contents($value));
$pdf->addPDF( WP_CONTENT_DIR . get_temp_dir() . $name[4] .".pdf", 'all');
}
$filename = time()."-".random_int(1, 10000000000);
$result = $pdf->merge('file', WP_CONTENT_DIR . get_temp_dir() . $filename .'.pdf');
return array("result" => $result, "file" => $filename);
}
}