バージョン選択
フォーラム
メニュー
オンライン状況
|
 |
58 人のユーザが現在オンラインです。 (46 人のユーザが フォーラム を参照しています。) |
|
|
開発について
投稿者 |
スレッド |
hashida |
投稿日時: 2021/11/8 10:27
対応状況: 開発中
|
半人前   登録日: 2021/6/25 居住地: 投稿: 28 |
プラグインから納品書の住所を非表示にしたい お世話になっております。 納品書の購入者住所を非表示にしたいです。 src\Eccube\Service\OrderPdfService.phpを継承しrenderOrderDataメソッドをオーバーライドし、住所設定の部分コメントアウトしたのですが住所が表示されてしまします。 子クラス住所の変数に別の値()を入れてみたのですが、住所の上にそのデータが重なって表示されてしまいます。 納品書PDFのをプラグインから非表示にすることは可能でしょうか。 ご存じでしたらご教授いただければ幸いです。 何卒宜しくお願い致します。 以下のサイトを参考にしました。 https://qiita.com/chihiro-adachi/items/b3bb70e6abbc0f824965プラグインのservices.yamlは以下の通りです。 services:
Plugin\sample\Service\OrderPdfServiceCustomizer:
public: false
autowire: true
decorates: Eccube\Service\OrderPdfService
<?php
namespace Plugin\sample\Service;
use Eccube\Common\EccubeConfig;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\OrderItem;
use Eccube\Entity\Shipping;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\OrderPdfRepository;
use Eccube\Repository\OrderRepository;
use Eccube\Repository\ShippingRepository;
use Eccube\Twig\Extension\EccubeExtension;
use Eccube\Twig\Extension\TaxExtension;
use Eccube\Service\TaxRuleService;
use setasign\Fpdi\TcpdfFpdi;
class OrderPdfServiceCustomizer extends \Eccube\Service\OrderPdfService
{
/** @var OrderRepository */
protected $orderRepository;
/** @var ShippingRepository */
protected $shippingRepository;
/** @var OrderPdfRepository */
protected $orderPdfRepository;
/** @var TaxRuleService */
protected $taxRuleService;
/**
* @var EccubeConfig
*/
private $eccubeConfig;
/**
* @var EccubeExtension
*/
private $eccubeExtension;
/**
* @var TaxExtension
*/
private $taxExtension;
/**
* OrderPdfService constructor.
* @param EccubeConfig $eccubeConfig
* @param OrderRepository $orderRepository
* @param ShippingRepository $shippingRepository
* @param TaxRuleService $taxRuleService
* @param BaseInfoRepository $baseInfoRepository
* @param EccubeExtension $eccubeExtension
* @param TaxExtension $taxExtension
* @throws \Exception
*/
function __construct(EccubeConfig $eccubeConfig, OrderRepository $orderRepository, ShippingRepository $shippingRepository, TaxRuleService $taxRuleService, BaseInfoRepository $baseInfoRepository, EccubeExtension $eccubeExtension, TaxExtension $taxExtension) {
$this->eccubeConfig = $eccubeConfig;
$this->baseInfoRepository = $baseInfoRepository->get();
$this->orderRepository = $orderRepository;
$this->shippingRepository = $shippingRepository;
$this->taxRuleService = $taxRuleService;
$this->eccubeExtension = $eccubeExtension;
$this->taxExtension = $taxExtension;
parent::__construct($eccubeConfig, $orderRepository, $shippingRepository, $taxRuleService, $baseInfoRepository, $eccubeExtension, $taxExtension);
}
/**
* 購入者情報を設定する.
*
* @param Shipping $Shipping
*/
protected function renderOrderData(Shipping $Shipping)
{
// 基準座標を設定する
$this->setBasePosition();
// フォント情報のバックアップ
$this->backupFont();
// =========================================
// 購入者情報部
// =========================================
$Order = $Shipping->getOrder();
// 購入者都道府県+住所1
// $text = $Order->getPref().$Order->getAddr01();
// $text = $Shipping->getPref().$Shipping->getAddr01();
$text = "000000"; <-ダミーデータを入れるも重なって表示
$this->lfText(27, 47, $text, 10);
$this->lfText(27, 51, $Shipping->getAddr02(), 10); //購入者住所2
// 購入者氏名
if (null !== $Shipping->getCompanyName()) {
// 会社名
$text = $Shipping->getCompanyName();
$this->lfText(27, 57, $text, 11);
// 氏名
$text = $Shipping->getName01().' '.$Shipping->getName02().' 様';
$this->lfText(27, 63, $text, 11);
} else {
$text = $Shipping->getName01().' '.$Shipping->getName02().' 様';
$this->lfText(27, 59, $text, 11);
}
// =========================================
// お買い上げ明細部
// =========================================
$this->SetFont(self::FONT_SJIS, '', 10);
//ご注文日
$orderDate = $Order->getCreateDate()->format('Y/m/d H:i');
if ($Order->getOrderDate()) {
$orderDate = $Order->getOrderDate()->format('Y/m/d H:i');
}
$this->lfText(25, 125, $orderDate, 10);
//注文番号
$this->lfText(25, 135, $Order->getOrderNo(), 10);
// 総合計金額
if (!$Order->isMultiple()) {
$this->SetFont(self::FONT_SJIS, 'B', 15);
$paymentTotalText = $this->eccubeExtension->getPriceFilter($Order->getPaymentTotal());
$this->setBasePosition(120, 95.5);
$this->Cell(5, 7, '', 0, 0, '', 0, '');
$this->Cell(67, 8, $paymentTotalText, 0, 2, 'R', 0, '');
$this->Cell(0, 45, '', 0, 2, '', 0, '');
}
// フォント情報の復元
$this->restoreFont();
return parent::renderOrderData($Shipping);
}
}
|
|
|
468 |
投稿日時: 2021/11/8 10:35
対応状況: −−−
|
神   登録日: 2008/10/26 居住地: 投稿: 3217 |
Re: プラグインから納品書の住所を非表示にしたい PDFを出力する処理(OrderControllerのfunction exportPdfDownload()メソッド)のオーバーライドは行われていないのでしょうか? デフォルトのOrderPdfServiceが実行されていませんか? ---------------- 株式会社シロハチ ■ECCUBE2系、3系構築カスタマイズご相談ください。 ■EC-CUBE3マニュアル ■blog
|
|
|
hashida |
投稿日時: 2021/11/8 14:43
対応状況: 開発中
|
半人前   登録日: 2021/6/25 居住地: 投稿: 28 |
Re: プラグインから納品書の住所を非表示にしたい 早々のご返事誠にありがとうございます。 早速OrderControllerをOrderControllerExtendで継承し、exportPdfDownload()をオーバーライドをしてみたのですが、現状は変わらず、ダミーの住所が上に重なって表示されております。 オーバーライドの方法がおかしいのでしょうか。 よろしければアドバイスをいただけますと幸いです。 何卒宜しくお願い致します。 以下OrderControllerExtend.php
<?php
namespace Plugin\sample\Controller\Admin;
.
.
.
use Eccube\Controller\Admin\Order\OrderController;
use Plugin\sample\Service\OrderPdfServiceCustomizer;
.
.
.
class OrderControllerExtend extends OrderController
{
.
.
.
/**
* @Route("/%eccube_admin_route%/order/export/pdf/download", name="admin_order_pdf_download")
* @Template("@admin/Order/order_pdf.twig")
*
* @param Request $request
*
* @return Response
*/
public function exportPdfDownload(Request $request, OrderPdfService $orderPdfService)
{
/**
* @var FormBuilder
*/
$builder = $this->formFactory->createBuilder(OrderPdfType::class);
/* @var \Symfony\Component\Form\Form $form */
$form = $builder->getForm();
$form->handleRequest($request);
// Validation
if (!$form->isValid()) {
log_info('The parameter is invalid!');
return $this->render('@admin/Order/order_pdf.twig', [
'form' => $form->createView(),
]);
}
$arrData = $form->getData();
// 購入情報からPDFを作成する
$orderPdfService = new OrderPdfServiceCustomizer(); <- 継承したインスタンスを生成
$status = $orderPdfService->makePdf($arrData);
// 異常終了した場合の処理
if (!$status) {
$this->addError('admin.order.export.pdf.download.failure', 'admin');
log_info('Unable to create pdf files! Process have problems!');
return $this->render('@admin/Order/order_pdf.twig', [
'form' => $form->createView(),
]);
}
// ダウンロードする
$response = new Response(
$OrderPdfService->outputPdf(),
200,
['content-type' => 'application/pdf']
);
$downloadKind = $form->get('download_kind')->getData();
// レスポンスヘッダーにContent-Dispositionをセットし、ファイル名を指定
if ($downloadKind == 1) {
$response->headers->set('Content-Disposition', 'attachment; filename="'.$OrderPdfService->getPdfFileName().'"');
} else {
$response->headers->set('Content-Disposition', 'inline; filename="'.$OrderPdfService->getPdfFileName().'"');
}
log_info('OrderPdf download success!', ['Order ID' => implode(',', $request->get('ids', []))]);
$isDefault = isset($arrData['default']) ? $arrData['default'] : false;
if ($isDefault) {
// Save input to DB
$arrData['admin'] = $this->getUser();
$this->orderPdfRepository->save($arrData);
}
return $response;
}
}
|
|
|
|
統計情報
総メンバー数は102,593名です
総投稿数は112,369件です
|