extract type specific lines from generic to specific clases

This commit is contained in:
Daniel Seifert 2020-05-27 09:46:44 +02:00
parent 738f5ec772
commit ac8498044d
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
10 changed files with 209 additions and 88 deletions

View File

@ -18,57 +18,89 @@
namespace D3\PdfDocuments\Application\Model\AbstractClasses; namespace D3\PdfDocuments\Application\Model\AbstractClasses;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocuments_generic as genericInterface; use D3\PdfDocuments\Application\Model\Interfaces\pdfdocuments_generic as genericInterface;
use \OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Payment;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Base;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use Smarty;
use Spipu\Html2Pdf\Html2Pdf; use Spipu\Html2Pdf\Html2Pdf;
abstract class pdfDocuments_generic implements genericInterface abstract class pdfDocuments_generic implements genericInterface
{ {
public function genPdf($sFilename, $iSelLang = 0, $target = 'I') /**
{ * @param $sFilename
$oSmarty = Registry::getUtilsView()->getSmarty(); * @param int $iSelLang
* @param string $target
*/
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
{
$sFilename = $this->getFilename( $sFilename);
$oSmarty = $this->setSmartyVars($oSmarty); $oPdf = call_user_func_array('oxNew', array_merge([Html2Pdf::class], $this->getPdfProperties()));
//$oPdf = oxNew(Html2Pdf::class, 'P', 'A4', 'de');
$oPdf->writeHTML($this->getHTMLContent($iSelLang));
$oPdf->output($sFilename, $target);
}
$this->setInvoiceNumber(); /**
$this->setInvoiceDate(); * @param Smarty $smarty
$this->saveOrderOnChanges(); *
* @return Smarty
*/
public function setSmartyVars($smarty)
{
$smarty->assign('oConfig', Registry::getSession()->getConfig());
$smarty->assign('oViewConf', Registry::getSession()->getConfig()->getActiveView()->getViewConfig());
$smarty->assign('shop', Registry::getSession()->getConfig()->getActiveShop());
$smarty->assign('lang', Registry::getLang());
$sContent = $oSmarty->fetch($this->getTemplate()); return $smarty;
$this->setFilename($sContent, $target, $sFilename); }
}
public function setSmartyVars($smarty) /**
{ * @param string $sFilename
$smarty->assign('oConfig', Registry::getSession()->getConfig()); *
$smarty->assign('oViewConf', Registry::getSession()->getConfig()->getActiveView()->getViewConfig()); * @return string
$smarty->assign('order', $this->getOrder()); */
$smarty->assign('shop', Registry::getSession()->getConfig()->getActiveShop()); public function getFilename($sFilename)
$smarty->assign('lang', Registry::getLang()); {
return $sFilename;
}
$oUser = oxNew(User::Class); /**
$oUser->load($this->getOrder()->getFieldData('oxuserid')); * @param int $iSelLang
$smarty->assign('user', $oUser); *
* @return mixed
*/
public function getHTMLContent($iSelLang = 0)
{
$lang = Registry::getLang();
$oPayment = oxNew(Payment::class); /** @var Smarty $oSmarty */
$oPayment->load($this->getOrder()->getFieldData('oxpaymenttype')); $oSmarty = Registry::getUtilsView()->getSmarty();
$smarty->assign('payment', $oPayment);
return $smarty; $currTplLang = $lang->getTplLanguage();
} $lang->setTplLanguage($iSelLang);
public function setFilename($sContent, $target, $sFilename) $oSmarty = $this->setSmartyVars($oSmarty);
{
$ordernr = $this->getOrder()->getFieldData('oxordernr');
$billnr = $this->getOrder()->getFieldData('oxbillnr');;
$sFilename = str_replace($ordernr, $billnr, $sFilename); $content = $oSmarty->fetch($this->getTemplate());
$oPdf = oxNew(Html2Pdf::class, 'P', 'A4', 'de'); $lang->setTplLanguage($currTplLang);
$oPdf->writeHTML($sContent);
$oPdf->output($sFilename, $target); return $content;
} }
/**
* arguments for Html2Pdf class constructor
* - $orientation = 'P',
* - $format = 'A4',
* - $lang = 'fr',
* - $unicode = true,
* - $encoding = 'UTF-8',
* - $margins = array(5, 5, 5, 8),
* - $pdfa = false
* @return string[]
*/
public function getPdfProperties()
{
return ['P', 'A4', 'de'];
}
} }

View File

@ -19,24 +19,65 @@ namespace D3\PdfDocuments\Application\Model\AbstractClasses;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocuments_order as orderInterface; use D3\PdfDocuments\Application\Model\Interfaces\pdfdocuments_order as orderInterface;
use \OxidEsales\Eshop\Application\Model\Order; use \OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Payment;
use OxidEsales\Eshop\Application\Model\User;
use Smarty;
abstract class pdfDocuments_order extends pdfDocuments_generic implements orderInterface abstract class pdfDocuments_order extends pdfDocuments_generic implements orderInterface
{ {
public $oOrder; /** @var Order */
public $oOrder;
/** /**
* @param Order $order * @param Order $order
*/ */
public function setOrder(Order $order) public function setOrder(Order $order)
{ {
$this->oOrder = $order; $this->oOrder = $order;
} }
/** /**
* @return Order * @return Order
*/ */
public function getOrder() public function getOrder()
{ {
return $this->oOrder; return $this->oOrder;
} }
/**
* @param Smarty $smarty
*
* @return Smarty
*/
public function setSmartyVars($smarty)
{
$smarty = parent::setSmartyVars($smarty);
$smarty->assign('order', $this->getOrder());
$oUser = oxNew(User::Class);
$oUser->load($this->getOrder()->getFieldData('oxuserid'));
$smarty->assign('user', $oUser);
$oPayment = oxNew(Payment::class);
$oPayment->load($this->getOrder()->getFieldData('oxpaymenttype'));
$smarty->assign('payment', $oPayment);
return $smarty;
}
/**
* @param string $sFilename
*
* @return string
*/
public function getFilename($sFilename)
{
$sFilename = parent::getFilename( $sFilename);
$ordernr = $this->getOrder()->getFieldData('oxordernr');
$billnr = $this->getOrder()->getFieldData('oxbillnr');;
return str_replace($ordernr, $billnr, $sFilename);
}
} }

View File

@ -1,9 +1,27 @@
<?php <?php
namespace D3\PdfDocuments\Modules\Application\Model; /**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
*
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
*
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Max Buhe <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
class deliverynotePdf extends pdfDocuments{ namespace D3\PdfDocuments\Modules\Application\Model\Documents;
public function getTemplate(){
return 'deliverynote.tpl'; use D3\PdfDocuments\Application\Model\AbstractClasses\pdfDocuments_order;
}
class deliverynotePdf extends pdfDocuments_order
{
public function getTemplate(){
return 'deliverynote.tpl';
}
} }

View File

@ -24,6 +24,15 @@ class invoicePdf extends pdfDocuments_order implements pdfdocuments_orderinvoice
{ {
protected $blIsNewOrder = false; protected $blIsNewOrder = false;
public function genPdf( $sFilename, $iSelLang = 0, $target = 'I' )
{
$this->setInvoiceNumber();
$this->setInvoiceDate();
$this->saveOrderOnChanges();
parent::genPdf( $sFilename, $iSelLang, $target );
}
public function setInvoiceNumber() public function setInvoiceNumber()
{ {
$this->blIsNewOrder = false; $this->blIsNewOrder = false;

View File

@ -19,11 +19,22 @@ namespace D3\PdfDocuments\Application\Model\Interfaces;
interface pdfdocuments_generic interface pdfdocuments_generic
{ {
public function setFilename($sContent, $target, $sFilename); /**
* @return string
public function saveOrderOnChanges(); */
public function getTemplate(); public function getTemplate();
/**
* @return mixed
*/
public function getHTMLContent();
/**
* @param $sFilename
* @param int $iSelLang
* @param string $target
*
* @return mixed
*/
public function genPdf($sFilename, $iSelLang = 0, $target = 'I'); public function genPdf($sFilename, $iSelLang = 0, $target = 'I');
} }

View File

@ -21,7 +21,13 @@ use OxidEsales\Eshop\Application\Model\Order;
interface pdfdocuments_order extends pdfdocuments_generic interface pdfdocuments_order extends pdfdocuments_generic
{ {
/**
* @param Order $order
*/
public function setOrder(Order $order); public function setOrder(Order $order);
/**
* @return Order
*/
public function getOrder(); public function getOrder();
} }

View File

@ -19,7 +19,7 @@ namespace D3\PdfDocuments\Application\Model\Interfaces;
interface pdfdocuments_orderinvoice extends pdfdocuments_order interface pdfdocuments_orderinvoice extends pdfdocuments_order
{ {
public function setInvoiceNumber(); public function setInvoiceNumber();
public function setInvoiceDate(); public function setInvoiceDate();
} }

View File

@ -17,8 +17,9 @@
namespace D3\PdfDocuments\Modules\Application\Model; namespace D3\PdfDocuments\Modules\Application\Model;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocuments_generic; use D3\PdfDocuments\Application\Model\Interfaces\pdfdocuments_order as OrderPdfInterface;
use D3\PdfDocuments\Modules\Application\Model\Documents\invoicePdf; use D3\PdfDocuments\Modules\Application\Model\Documents\invoicePdf;
use D3\PdfDocuments\Modules\Application\Model\Documents\deliverynotePdf;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use Spipu\Html2Pdf\Exception\Html2PdfException; use Spipu\Html2Pdf\Exception\Html2PdfException;
@ -32,38 +33,40 @@ class d3_Order_PdfDocuments extends d3_Order_PdfDocuments_parent
*/ */
public function genPdf($sFilename, $iSelLang = 0, $target = 'I') public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
{ {
$Pdf= $this->getPdfClass(); $Pdf= $this->getPdfClass();
$Pdf->setOrder($this); $Pdf->setOrder($this);
$Pdf->genPdf($sFilename, $iSelLang = 0, $target = 'I'); $Pdf->genPdf($sFilename, $iSelLang = 0, $target = 'I');
} }
public function getPdfClass(){
switch (Registry::getRequest()->getRequestParameter('pdftype')) { public function getPdfClass()
case ('dnote'): {
case ('dnote_without_logo'): switch (Registry::getRequest()->getRequestParameter('pdftype')) {
$pdfInstance= oxNew(deliverynotePdf::class); case ('dnote'):
$pdfInstance->setOrder($this); case ('dnote_without_logo'):
return $pdfInstance; $pdfInstance= oxNew(deliverynotePdf::class);
case ('standart'): $pdfInstance->setOrder($this);
case('standart_without_logo'): return $pdfInstance;
$pdfInvoice= oxNew(invoicePdf::class); case ('standart'):
$pdfInvoice->setOrder($this); case('standart_without_logo'):
return $pdfInvoice; $pdfInvoice= oxNew(invoicePdf::class);
default: $pdfInvoice->setOrder($this);
return $this->getCustomPdfClass(); return $pdfInvoice;
} default:
return $this->getCustomPdfClass();
}
} }
/** /**
* @return pdfdocuments_generic * @return OrderPdfInterface
* @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException * @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException
* @throws \oxSystemComponentException * @throws \oxSystemComponentException
*/ */
public function getCustomPdfClass() public function getCustomPdfClass()
{ {
$pdfInvoice= oxNew(invoicePdf::class); $pdfInvoice= oxNew(invoicePdf::class);
$pdfInvoice->setOrder($this); $pdfInvoice->setOrder($this);
return $pdfInvoice; return $pdfInvoice;
} }
} }

View File

@ -30,6 +30,7 @@
} }
}, },
"require": { "require": {
"oxid-esales/oxideshop-ce": "6.0 - 6.3"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@ -49,7 +49,7 @@ $aModule = [
], ],
'controllers' => [], 'controllers' => [],
'templates' => [ 'templates' => [
'd3deliverynote.tpl' => 'd3/pdfdocuments/Application/views/tpl/deliverynote.tpl', 'd3deliverynote.tpl' => 'd3/pdfdocuments/Application/views/tpl/deliverynote/deliverynote.tpl',
'invoice.tpl' => 'd3/pdfdocuments/Application/views/tpl/invoice/invoice.tpl', 'invoice.tpl' => 'd3/pdfdocuments/Application/views/tpl/invoice/invoice.tpl',
'd3tplheader.tpl' => 'd3/pdfdocuments/Application/views/tpl/header.tpl' 'd3tplheader.tpl' => 'd3/pdfdocuments/Application/views/tpl/header.tpl'
], ],