Skip to content

Commit 393bd38

Browse files
committed
code cleanup,
readme update about deployment
1 parent 9139824 commit 393bd38

File tree

3 files changed

+67
-84
lines changed

3 files changed

+67
-84
lines changed

README.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1-
# Invoices to PDF for Opencart 2.x
1+
# Invoices to PDF for [OpenCart 2.x](https://github.com/opencart/opencart)
22

33
note: developed on version 2.3.2, other versions can need some edits - **fell free to contribute!**
44

55
## Installation
66

7-
1. Requiring installed [Vqmod](https://github.com/vqmod/vqmod) because VqMod doesn't support installing via composer itself.
8-
2. `composer require burdapraha/oc_invoice_pdf dev-master`
9-
3. Add this code to your composer.json project file:
7+
1. Requiring installed [vQmod](https://github.com/vqmod/vqmod) because vQmod doesn't support installing via composer itself.
8+
2. `composer require burdapraha/oc_invoice_pdf`
9+
3. `composer require sasedev/composer-plugin-filecopier` for files manipulating
10+
4. Add this code to your composer.json project file, extra section:
1011

1112
```
12-
"scripts": {
13-
"post-install-cmd": [
14-
"php -r \"copy('vendor/burdapraha/oc_invoice_pdf/upload/vqmod/xml/invoice_pdf.xml', 'upload/vqmod/xml/invoice_pdf.xml');\""
15-
],
16-
"post-update-cmd": [
17-
"php -r \"copy('vendor/burdapraha/oc_invoice_pdf/upload/vqmod/xml/invoice_pdf.xml', 'upload/vqmod/xml/invoice_pdf.xml');\""
13+
"extra": {
14+
"filescopier": [
15+
{
16+
"source": "vendor/burdapraha/oc_invoice_pdf/upload",
17+
"destination": "upload",
18+
"debug": "true"
19+
}
1820
]
19-
}
21+
}
2022
```
21-
4. add constant to your config.php & admin/config.php for storage PDF files:
23+
24+
It will move vQmod xml file to correct folder.
25+
26+
5. add constant to your config.php & admin/config.php for storage PDF files:
2227
For example: `define('INVOICES_DIR', DIR_IMAGE . '/invoices');` and fix this folder for reading from web by .htaccess
23-
5. optionally you can add row to your `.gitignore` file with path to tracy.xml (example: upload/vqmod/xml/invoice_pdf.xml)
24-
5. celebrate!
28+
6. optionally you can add row to your `.gitignore` file with path to tracy.xml (example: upload/vqmod/xml/invoice_pdf.xml)
29+
7. celebrate!
2530

2631
## Credits
2732

2833
- using [dompdf](https://github.com/dompdf/dompdf) to printing
29-
- inspired by [Invoice to PDF](https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=26964&filter_search=invoice%20pdf&filter_license=0)
34+
- inspired by [Invoice to PDF](https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=26964&filter_search=invoice%20pdf&filter_license=0)
35+
- [hawkey](http://www.opencartex.com/) for talking about solution
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
<?php
22

3-
43
class ControllerModuleInvoicePdf extends Controller {
54

6-
private $error = array();
7-
protected $lowCaseBinderName;
8-
protected $configInfo;
95
protected $order_id;
106

117
public function __construct($registry)
128
{
13-
global $config;
14-
159
// set order ID
1610
if(isset($_GET['order_id']))
1711
{
@@ -26,26 +20,30 @@ public function __construct($registry)
2620
}
2721

2822

29-
public function index() {
23+
public function index()
24+
{
3025
$this->load->model('sale/order');
3126
$this->load->model('setting/setting');
3227

3328
$invoice_no = $this->model_sale_order->createInvoiceNo($this->order_id);
3429

3530
if($invoice_no) {
36-
// todo
31+
$custom_parameters = [
32+
'return_invoice_path' => true,
33+
'orders' => [
34+
$this->order_id
35+
]
36+
];
37+
38+
$controller_response = $this->load->controller('sale/order/invoice', $custom_parameters);
39+
$json = json_encode(['path' => $controller_response]);
40+
}
41+
else {
42+
$json = ['error' => 'createInvoiceNo error'];
3743
}
3844

39-
$custom_parameters = [
40-
'return_invoice_path' => true,
41-
'orders' => [
42-
$this->order_id
43-
]
44-
];
45-
46-
$controller_response = $this->load->controller('sale/order/invoice', $custom_parameters);
4745

4846
$this->response->addHeader('Content-Type: application/json');
49-
$this->response->setOutput(json_encode(['path' => $controller_response]));
47+
$this->response->setOutput($json);
5048
}
5149
}

upload/vqmod/xml/invoice_pdf.xml

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -62,59 +62,43 @@
6262
</file>
6363

6464
<file name="admin/controller/sale/order.php">
65-
<operation>
66-
<search position="replace"><![CDATA[public function invoice() {]]></search>
67-
<add><![CDATA[public function invoice($custom_array = null) {]]></add>
68-
</operation>
69-
7065
<operation>
7166
<search position="after"><![CDATA[$data['button_invoice_print'] = $this->language->get('button_invoice_print');]]></search>
7267
<add><![CDATA[$data['button_pdf_invoice'] = $this->language->get('button_pdf_invoice');]]></add>
7368
</operation>
74-
7569
<operation>
76-
<search position="replace"><![CDATA[$orders = array();]]></search>
70+
<search position="after"><![CDATA[invoice() {]]></search>
71+
<add><![CDATA[$pdf = false;]]></add>
72+
</operation>
73+
<operation>
74+
<search position="replace" offset="7"><![CDATA[$orders = array();]]></search>
7775
<add><![CDATA[
7876
7977
$orders = array();
8078
81-
// custom orders ID delivered from argument
82-
if(isset($custom_array['orders']))
83-
{
84-
array_merge($orders, $custom_array['orders']);
85-
}
79+
if (isset($this->request->post['selected'])) {
8680
87-
// pdf from administrator request
88-
$pdf = (isset($this->request->get['pdf'])) ? true : false;
89-
$return_invoice_path = false;
81+
$orders = $this->request->post['selected'];
82+
$pdf = (isset($this->request->get['pdf'])) ? true : false;
9083
84+
} elseif (isset($this->request->get['order_id'])) {
85+
86+
$orders[] = $this->request->get['order_id'];
87+
$pdf = (isset($this->request->get['pdf'])) ? true : false;
88+
89+
}
9190
]]>
9291
</add>
9392
</operation>
94-
9593
<operation>
96-
<search position="replace"><![CDATA[$this->response->setOutput($this->load->view('sale/order_invoice', $data));]]></search>
94+
<search position="after"><![CDATA[$this->response->setOutput($this->load->view('sale/order_invoice', $data));]]></search>
9795
<add><![CDATA[
9896
99-
// return just data for request from catalog
100-
if(isset($custom_array['return_invoice_path']))
101-
{
102-
$pdf = true;
103-
$return_invoice_path = true;
104-
}
105-
106-
// print pdf to request from administrator
10797
if ($pdf)
10898
{
10999
$order_view = $this->load->view('sale/order_invoice', $data);
110-
return invoice_pdf($order_view, $data, $return_invoice_path);
111-
}
112-
113-
// default response
114-
if(!isset($custom_array['return_only_data']) && false == $pdf)
115-
{
116-
echo "tady je klasicky vystup";
117-
//$this->response->setOutput($this->load->view('sale/order_invoice', $data));
100+
$pdf_printer = invoice_pdf($order_view, $data);
101+
$this->response->setOutput();
118102
}
119103
120104
]]>
@@ -196,35 +180,30 @@
196180
</add>
197181
</operation>
198182

199-
200-
<operation info="generate invoice if order status id done">
201-
<search position="before"><![CDATA[$mail = new Mail();]]></search>
183+
<operation info="new feature attachment to order history">
184+
<search position="after"><![CDATA[$mail->setText($text);]]></search>
202185
<add>
203186
<![CDATA[
204-
$success_status_array = array_flip($this->config->get('config_complete_status'));
205-
206-
if(array_key_exists($order_status_id, $success_status_array))
207-
{
208-
// request to generate invoice file
209-
$url = "{$order_info['store_url']}admin/index.php?route=module/invoicepdf&order_id={$order_id}";
210-
$request = do_curl_request($url);
211-
$response = json_decode($request);
212187
213-
// add invoice to the mail
214-
$attachment = isset($response->path) ? $response->path : '';
188+
if(!empty($attachment) && file_exist($invoice))) {
189+
$mail->addAttachment($invoice);
215190
}
191+
216192
]]>
217193
</add>
218194
</operation>
219195

220-
221-
<operation info="new feature attachment to order history">
222-
<search position="after"><![CDATA[$mail->setText($text);]]></search>
196+
<operation info="generate invoice number">
197+
<search position="before" offset="3"><![CDATA[// Admin Alert Mail]]></search>
223198
<add>
224199
<![CDATA[
225-
if(!empty($attachment) && file_exists($attachment)) {
226-
$mail->addAttachment($attachment);
227-
}
200+
$url = "{$order_info['store_url']}/admin/index.php?route=module/invoicepdf&order_id={$order_id}";
201+
$json = do_curl_request($url, $fields);
202+
203+
$invoice = json_decode($json)['invoice'];
204+
205+
// add invoice to the mail
206+
$mail->addAttachment($invoice);
228207
]]>
229208
</add>
230209
</operation>

0 commit comments

Comments
 (0)