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
{ {
/**
* @param $sFilename
* @param int $iSelLang
* @param string $target
*/
public function genPdf($sFilename, $iSelLang = 0, $target = 'I') public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
{ {
$oSmarty = Registry::getUtilsView()->getSmarty(); $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');
$this->setInvoiceNumber(); $oPdf->writeHTML($this->getHTMLContent($iSelLang));
$this->setInvoiceDate(); $oPdf->output($sFilename, $target);
$this->saveOrderOnChanges();
$sContent = $oSmarty->fetch($this->getTemplate());
$this->setFilename($sContent, $target, $sFilename);
} }
/**
* @param Smarty $smarty
*
* @return Smarty
*/
public function setSmartyVars($smarty) public function setSmartyVars($smarty)
{ {
$smarty->assign('oConfig', Registry::getSession()->getConfig()); $smarty->assign('oConfig', Registry::getSession()->getConfig());
$smarty->assign('oViewConf', Registry::getSession()->getConfig()->getActiveView()->getViewConfig()); $smarty->assign('oViewConf', Registry::getSession()->getConfig()->getActiveView()->getViewConfig());
$smarty->assign('order', $this->getOrder());
$smarty->assign('shop', Registry::getSession()->getConfig()->getActiveShop()); $smarty->assign('shop', Registry::getSession()->getConfig()->getActiveShop());
$smarty->assign('lang', Registry::getLang()); $smarty->assign('lang', Registry::getLang());
$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; return $smarty;
} }
public function setFilename($sContent, $target, $sFilename) /**
* @param string $sFilename
*
* @return string
*/
public function getFilename($sFilename)
{ {
$ordernr = $this->getOrder()->getFieldData('oxordernr'); return $sFilename;
$billnr = $this->getOrder()->getFieldData('oxbillnr');; }
$sFilename = str_replace($ordernr, $billnr, $sFilename); /**
* @param int $iSelLang
*
* @return mixed
*/
public function getHTMLContent($iSelLang = 0)
{
$lang = Registry::getLang();
$oPdf = oxNew(Html2Pdf::class, 'P', 'A4', 'de'); /** @var Smarty $oSmarty */
$oPdf->writeHTML($sContent); $oSmarty = Registry::getUtilsView()->getSmarty();
$oPdf->output($sFilename, $target);
$currTplLang = $lang->getTplLanguage();
$lang->setTplLanguage($iSelLang);
$oSmarty = $this->setSmartyVars($oSmarty);
$content = $oSmarty->fetch($this->getTemplate());
$lang->setTplLanguage($currTplLang);
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,9 +19,13 @@ 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
{ {
/** @var Order */
public $oOrder; public $oOrder;
/** /**
@ -39,4 +43,41 @@ abstract class pdfDocuments_order extends pdfDocuments_generic implements orderI
{ {
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,8 +1,26 @@
<?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;
use D3\PdfDocuments\Application\Model\AbstractClasses\pdfDocuments_order;
class deliverynotePdf extends pdfDocuments_order
{
public function getTemplate(){ public function getTemplate(){
return 'deliverynote.tpl'; 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

@ -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;
@ -37,7 +38,9 @@ class d3_Order_PdfDocuments extends d3_Order_PdfDocuments_parent
$Pdf->setOrder($this); $Pdf->setOrder($this);
$Pdf->genPdf($sFilename, $iSelLang = 0, $target = 'I'); $Pdf->genPdf($sFilename, $iSelLang = 0, $target = 'I');
} }
public function getPdfClass(){
public function getPdfClass()
{
switch (Registry::getRequest()->getRequestParameter('pdftype')) { switch (Registry::getRequest()->getRequestParameter('pdftype')) {
case ('dnote'): case ('dnote'):
case ('dnote_without_logo'): case ('dnote_without_logo'):
@ -55,7 +58,7 @@ class d3_Order_PdfDocuments extends d3_Order_PdfDocuments_parent
} }
/** /**
* @return pdfdocuments_generic * @return OrderPdfInterface
* @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException * @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException
* @throws \oxSystemComponentException * @throws \oxSystemComponentException
*/ */

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'
], ],