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 d5027d5526
commit 98a34d05f3
10 changed files with 209 additions and 88 deletions

View File

@ -18,57 +18,89 @@
namespace D3\PdfDocuments\Application\Model\AbstractClasses;
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 Smarty;
use Spipu\Html2Pdf\Html2Pdf;
abstract class pdfDocuments_generic implements genericInterface
{
/**
* @param $sFilename
* @param int $iSelLang
* @param string $target
*/
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
{
$oSmarty = Registry::getUtilsView()->getSmarty();
$sFilename = $this->getFilename( $sFilename);
$oSmarty = $this->setSmartyVars($oSmarty);
$this->setInvoiceNumber();
$this->setInvoiceDate();
$this->saveOrderOnChanges();
$sContent = $oSmarty->fetch($this->getTemplate());
$this->setFilename($sContent, $target, $sFilename);
$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);
}
/**
* @param Smarty $smarty
*
* @return Smarty
*/
public function setSmartyVars($smarty)
{
$smarty->assign('oConfig', Registry::getSession()->getConfig());
$smarty->assign('oViewConf', Registry::getSession()->getConfig()->getActiveView()->getViewConfig());
$smarty->assign('order', $this->getOrder());
$smarty->assign('shop', Registry::getSession()->getConfig()->getActiveShop());
$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;
}
public function setFilename($sContent, $target, $sFilename)
/**
* @param string $sFilename
*
* @return string
*/
public function getFilename($sFilename)
{
$ordernr = $this->getOrder()->getFieldData('oxordernr');
$billnr = $this->getOrder()->getFieldData('oxbillnr');;
return $sFilename;
}
$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');
$oPdf->writeHTML($sContent);
$oPdf->output($sFilename, $target);
/** @var Smarty $oSmarty */
$oSmarty = Registry::getUtilsView()->getSmarty();
$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 \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
{
/** @var Order */
public $oOrder;
/**
@ -39,4 +43,41 @@ abstract class pdfDocuments_order extends pdfDocuments_generic implements orderI
{
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
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(){
return 'deliverynote.tpl';
}

View File

@ -24,6 +24,15 @@ class invoicePdf extends pdfDocuments_order implements pdfdocuments_orderinvoice
{
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()
{
$this->blIsNewOrder = false;

View File

@ -19,11 +19,22 @@ namespace D3\PdfDocuments\Application\Model\Interfaces;
interface pdfdocuments_generic
{
public function setFilename($sContent, $target, $sFilename);
public function saveOrderOnChanges();
/**
* @return string
*/
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');
}

View File

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

View File

@ -17,8 +17,9 @@
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\deliverynotePdf;
use OxidEsales\Eshop\Core\Registry;
use Spipu\Html2Pdf\Exception\Html2PdfException;
@ -37,7 +38,9 @@ class d3_Order_PdfDocuments extends d3_Order_PdfDocuments_parent
$Pdf->setOrder($this);
$Pdf->genPdf($sFilename, $iSelLang = 0, $target = 'I');
}
public function getPdfClass(){
public function getPdfClass()
{
switch (Registry::getRequest()->getRequestParameter('pdftype')) {
case ('dnote'):
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 \oxSystemComponentException
*/

View File

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

View File

@ -49,7 +49,7 @@ $aModule = [
],
'controllers' => [],
'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',
'd3tplheader.tpl' => 'd3/pdfdocuments/Application/views/tpl/header.tpl'
],