【EC-CUBE3系】納品書にお届け先の情報を出力する

納品書の出力機能はプラグインで追加できます

EC-CUBEの魅力と言えば、Wordpressと同様プラグインで機能拡張できるところにあるかと思います。
(なぜ最初から機能として搭載していないのか、という疑問のある機能も多々ありますが)

ところがこの機能拡張も中には「帯に短し襷に長し」的なものもあり、その中のひとつが「帳票出力プラグイン(OrderPdf)」。
お客さんより「B2で呼び出す時と出荷時の確認の時不便だから、お届け先の情報も納品書に付けて欲しい」と。

ならば自力で修正するしかない、EC-CUBE

PDFの出力内容を制御しているのがOrderPdfService.php。
(EC-CUBEルート)/app/Plugin/OrderPdf/Service/OrderPdfService.php

これを修正するのですが、届出先データを引っ張ってこなければならないらしい・・・
行列?!と思ったのですが、探したらありました(開発コミュニティの皆様ありがとうございます)

https://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=18089&forum=13
https://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=19786&forum=11

この辺を色々見ながら、OrderPdfService.phpの402行目あたりに下記のコードを挿入。

$Shipping = $Order->getShippings()[0];
// お届け先郵便番号
$text = '〒 '.$Shipping->getZip01().' - '.$Shipping->getZip02();
$this->lfText(20, 78.5, $text, 10);
// お届け先都道府県+住所1
$text = $Shipping->getPref().$Shipping->getAddr01();
$this->lfText(20, 82.5, $text, 10);
$this->lfText(20, 86.5, $Shipping->getAddr02(), 10); //お届け先住所2
// お届け先氏名
$text = $Shipping->getName01().' '.$Shipping->getName02().' 様';
$this->lfText(20, 90.5, $text, 10);
// お届け先電話番号
$this->lfText(20, 94.5, $Shipping->getTel01().$Shipping->getTel02().$Shipping->getTel03(), 10);

出ました!が、左上のコメント入力エリアに重なって出力されてしまうので、出力位置変更。
「lfText(20, 78.5, $text, 10);」の「20, 78.5」がどうやら座標軸の模様。

というわけで位置の部分を右下に出るように修正。

$Shipping = $Order->getShippings()[0];
// お届け先郵便番号
$text = '〒 '.$Shipping->getZip01().' - '.$Shipping->getZip02();
$this->lfText(125, 125, $text, 10);
// お届け先都道府県+住所1
$text = $Shipping->getPref().$Shipping->getAddr01();
$this->lfText(125, 129, $text, 10);
$this->lfText(125, 133, $Shipping->getAddr02(), 10); //お届け先住所2
// お届け先氏名
$text = $Shipping->getName01().' '.$Shipping->getName02().' 様';
$this->lfText(125, 137, $text, 10);
// お届け先電話番号
$this->lfText(125, 141, $Shipping->getTel01().$Shipping->getTel02().$Shipping->getTel03(), 10);

出た!のは良いのですが、見出しがないとなんだか唐突感が否めないので、納品書のテンプレートをいじって見出しを付けてみます。
(納品書のテンプレート)
(EC-CUBEルート)/app/template/admin/OrderPdf/nouhinsyo1.pdf

とりあえずこれに「お届け先」の見出しを付けて・・・

よし嵌った!
微調整は必要ですが、当面はこれで運用してみます。このテンプレも置いておきますね。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA