LC_Page_Admin_Order_Pdf
クラスはデフォルトクラスなので、できるだけ書き換えないようにします。LC_Page_Admin_Order_Pdf_Ex
クラスのaction()
メソッドで分岐するようにします。init()
メソッドで$this->invoice
プロパティに帳票のロード設定をまとめてあります。これにより、元のアクションではPOSTあり、なしで分岐していたのを連想配列の設定でロードできるようにしてあります。
領収書の実際のフォームデータが不明だったのできちんと実装してありません。else if ($type === 2)
のIF分岐内に実装してください。
実際に動かしていないので不具合があるかもしれませんが、とりあえずサンプルです。
php
1require_once(CLASS_PATH . "pages/admin/order/LC_Page_Admin_Order_Pdf.php");
2
3class LC_Page_Admin_Order_Pdf_Ex extends LC_Page_Admin_Order_Pdf
4{
5 public function init()
6 {
7 parent::init();
8
9 //帳票の種類(セレクトボックス)
10 $this->arrType[0] = '納品書';
11 $this->arrType[1] = '納品書(カスタム)';
12 $this->arrType[2] = '領収書';
13
14 //帳票のロード設定(セレクトボックスのPOST値をキーにする)
15 $this->invoice = array(
16 //初期表示(仮想値)
17 -1 => array(
18 'templ' => $this->tpl_mainpage,
19 ),
20 //納品書(デフォルトPDF、$_POST['type'] == 0)
21 0 => array(
22 'pdf' => true,
23 'class' => 'SC_Fpdf_Ex',
24 'path' => null,
25 'templ' => 'nouhinsyo1.pdf',
26 ),
27 //納品書(カスタム)($_POST['type'] == 1)
28 1 => array(
29 'pdf' => true,
30 'class' => 'SC_Fepdf',
31 'path' => CLASS_REALDIR . 'SC_Fepdf.php',
32 'templ' => 'nouhinsyo1.pdf',
33 ),
34 //領収書($_POST['type'] == 2)
35 2 => array(
36 'templ' => 'order/pdf_input_ex.tpl',
37 ),
38 );
39
40 //セレクトボックスPOST値
41 $this->invoiceType = -1;
42 }
43
44 4748
49 public function process()
50 {
51 $this->action();
52 $this->sendResponse();
53 }
54
55 5859
60 public function action()
61 {
62 //--- ここからLC_Page_Admin_Order_Pdf::action()と同じ ---
63 $objDb = new SC_Helper_DB_Ex();
64 $objDate = new SC_Date_Ex(1901);
65 $objDate->setStartYear(RELEASE_YEAR);
66
67 $this->arrYear = $objDate->getYear();
68 $this->arrMonth = $objDate->getMonth();
69 $this->arrDay = $objDate->getDay();
70
71 // パラメーター管理クラス
72 $this->objFormParam = new SC_FormParam_Ex();
73
74 // パラメーター情報の初期化
75 $this->lfInitParam($this->objFormParam);
76 $this->objFormParam->setParam($_POST);
77
78 // 入力値の変換
79 $this->objFormParam->convParam();
80 if (!isset($arrRet)) $arrRet = array();
81 //--- ここまでLC_Page_Admin_Order_Pdf::action()と同じ ---
82
83 $type = $this->_getInvoiceType();
84
85 //PDF作成
86 if ($type === true) {
87 $arrRet = $this->objFormParam->getHashArray();
88 $arrErr = $this->lfCheckError($objFormParam);
89
90 if (count($arrErr) == 0) {
91 $this->_getFpdf($arrRet)->createPdf();
92 SC_Response_Ex::actionExit();
93 }
94 else {
95 $this->arrErr = $arrErr;
96 }
97 }
98 //領収書作成
99 else if ($type === 2) {
100 //カスタムフォームテンプレートをセット
101 $this->tpl_mainpage = $this->invoice[$this->invoiceType]['templ'];
102 //...
103
104 //親クラスメソッドLC_Page_Admin_Order_Pdf::createFromValues()を変更したい場合は本クラスに同じクラスを作成
105 $this->arrForm = $this->createFromValues($_GET['order_id'], $_POST['pdf_order_id']);
106
107 //テンプレートデータ上書
108 //$this->arrForm['title'] = '';
109 //...
110 }
111 //初期表示、帳票作成フォーム
112 else {
113 //@see data/class/pages/admin/order/LC_Page_Admin_Order_Pdf.php LC_Page_Admin_Order_Pdf::createFromValues()
114 $this->arrForm = parent::createFromValues($_GET['order_id'], $_POST['pdf_order_id']);
115 }
116
117 $this->setTemplate($this->tpl_mainpage);
118 }
119
120 123124
125 private function _getInvoiceType()
126 {
127 $type = -1;
128
129 if ($this->getMode() == 'confirm' && isset($_POST['type']) && is_numeric($_POST['type'])) {
130 $type = preg_replace('/[^0-9]+/m', '', $_POST['type']);
131 if (is_numeric($type)) {
132 $this->invoiceType = $type;
133 }
134 }
135
136 return !empty($this->invoice[$type]['pdf']) && true === $this->invoice[$type]['pdf'] ? true : $type;
137 }
138
139 142143144
145 private function _getFpdf($post = array())
146 {
147 try {
148 $this->arrForm = $post;
149
150 //タイトルが入力されていなければ、デフォルトのタイトルを表示
151 if(empty($post['title'])) {
152 $post['title'] = 'お買上げ明細書(納品書)';
153 }
154
155 //クラス設定
156 $config = !empty($this->invoice[$this->invoiceType]) ? $this->invoice[$this->invoiceType] : $this->invoice[0];
157
158 $invoiceClass = !empty($config['class']) ? $config['class'] : 'SC_Fpdf_Ex';
159 $invoiceTempl = !empty($config['templ']) ? $config['templ'] : 'nouhinsyo1.pdf';
160 $classPath = !empty($config['path']) && is_file($config['path']) ? $config['path'] : false;
161
162 if (false !== $classPath) {
163 //カスタムPDFクラスロード
164 require_once $classPath;
165 }
166 if (! class_exists($invoiceClass)) {
167 throw new Exception("PDFクラスを読み込むことができません。クラス名:$invoiceClass");
168 }
169
170 //FPDFインスタンス作成
171 $objFpdf = new $invoiceClass($post['download'], $post['title'], $invoiceTempl);
172
173 foreach ($post['order_id'] as $key => $val) {
174 $arrPdfData = $post;
175 $arrPdfData['order_id'] = $val;
176 $objFpdf->setData($arrPdfData);
177 }
178
179 return $objFpdf;
180 }
181 catch (Exception $e) {
182 echo $e->getMessage();
183 SC_Response_Ex::actionExit();
184 }
185 }
186}
処理の流れは下記のようになっています。すみません、古いレポジトリを見ていたのでリンク先を変更しました。
■呼び元(1)
https://github.com/EC-CUBE/eccube-2_13/blob/eccube-2.13.5/html/admin/order/pdf.php
■LC_Page_Admin_Order_Pdf_Ex(2)
https://github.com/EC-CUBE/eccube-2_13/blob/eccube-2.13.5/data/class_extends/page_extends/admin/order/LC_Page_Admin_Order_Ex.php
■LC_Page_Admin_Order_Pdf(3)
https://github.com/EC-CUBE/eccube-2_13/blob/eccube-2.13.5/data/class/pages/admin/order/LC_Page_Admin_Order_Pdf.php
■LC_Page_Admin::sendResponse()(4)
https://github.com/EC-CUBE/eccube-2_13/blob/eccube-2.13.5/data/class/pages/admin/LC_Page_Admin.php
■帳票作成画面テンプレート(5)
https://github.com/EC-CUBE/eccube-2_13/blob/eccube-2.13.5/data/Smarty/templates/admin/order/pdf_input.tpl