extract type specific lines from generic to specific clases
This commit is contained in:
parent
738f5ec772
commit
ac8498044d
@ -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
|
||||
{
|
||||
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
|
||||
{
|
||||
$oSmarty = Registry::getUtilsView()->getSmarty();
|
||||
/**
|
||||
* @param $sFilename
|
||||
* @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();
|
||||
$this->saveOrderOnChanges();
|
||||
/**
|
||||
* @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('shop', Registry::getSession()->getConfig()->getActiveShop());
|
||||
$smarty->assign('lang', Registry::getLang());
|
||||
|
||||
$sContent = $oSmarty->fetch($this->getTemplate());
|
||||
$this->setFilename($sContent, $target, $sFilename);
|
||||
}
|
||||
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());
|
||||
/**
|
||||
* @param string $sFilename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFilename($sFilename)
|
||||
{
|
||||
return $sFilename;
|
||||
}
|
||||
|
||||
$oUser = oxNew(User::Class);
|
||||
$oUser->load($this->getOrder()->getFieldData('oxuserid'));
|
||||
$smarty->assign('user', $oUser);
|
||||
/**
|
||||
* @param int $iSelLang
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getHTMLContent($iSelLang = 0)
|
||||
{
|
||||
$lang = Registry::getLang();
|
||||
|
||||
$oPayment = oxNew(Payment::class);
|
||||
$oPayment->load($this->getOrder()->getFieldData('oxpaymenttype'));
|
||||
$smarty->assign('payment', $oPayment);
|
||||
/** @var Smarty $oSmarty */
|
||||
$oSmarty = Registry::getUtilsView()->getSmarty();
|
||||
|
||||
return $smarty;
|
||||
}
|
||||
$currTplLang = $lang->getTplLanguage();
|
||||
$lang->setTplLanguage($iSelLang);
|
||||
|
||||
public function setFilename($sContent, $target, $sFilename)
|
||||
{
|
||||
$ordernr = $this->getOrder()->getFieldData('oxordernr');
|
||||
$billnr = $this->getOrder()->getFieldData('oxbillnr');;
|
||||
$oSmarty = $this->setSmartyVars($oSmarty);
|
||||
|
||||
$sFilename = str_replace($ordernr, $billnr, $sFilename);
|
||||
$content = $oSmarty->fetch($this->getTemplate());
|
||||
|
||||
$oPdf = oxNew(Html2Pdf::class, 'P', 'A4', 'de');
|
||||
$oPdf->writeHTML($sContent);
|
||||
$oPdf->output($sFilename, $target);
|
||||
}
|
||||
$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'];
|
||||
}
|
||||
}
|
@ -19,24 +19,65 @@ 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
|
||||
{
|
||||
public $oOrder;
|
||||
/** @var Order */
|
||||
public $oOrder;
|
||||
|
||||
/**
|
||||
* @param Order $order
|
||||
*/
|
||||
public function setOrder(Order $order)
|
||||
{
|
||||
$this->oOrder = $order;
|
||||
}
|
||||
/**
|
||||
* @param Order $order
|
||||
*/
|
||||
public function setOrder(Order $order)
|
||||
{
|
||||
$this->oOrder = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Order
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->oOrder;
|
||||
}
|
||||
/**
|
||||
* @return Order
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,9 +1,27 @@
|
||||
<?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{
|
||||
public function getTemplate(){
|
||||
return 'deliverynote.tpl';
|
||||
}
|
||||
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';
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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');
|
||||
}
|
@ -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();
|
||||
}
|
@ -19,7 +19,7 @@ namespace D3\PdfDocuments\Application\Model\Interfaces;
|
||||
|
||||
interface pdfdocuments_orderinvoice extends pdfdocuments_order
|
||||
{
|
||||
public function setInvoiceNumber();
|
||||
public function setInvoiceNumber();
|
||||
|
||||
public function setInvoiceDate();
|
||||
public function setInvoiceDate();
|
||||
}
|
@ -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;
|
||||
|
||||
@ -32,38 +33,40 @@ class d3_Order_PdfDocuments extends d3_Order_PdfDocuments_parent
|
||||
*/
|
||||
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
|
||||
{
|
||||
$Pdf= $this->getPdfClass();
|
||||
$Pdf= $this->getPdfClass();
|
||||
|
||||
$Pdf->setOrder($this);
|
||||
$Pdf->genPdf($sFilename, $iSelLang = 0, $target = 'I');
|
||||
$Pdf->setOrder($this);
|
||||
$Pdf->genPdf($sFilename, $iSelLang = 0, $target = 'I');
|
||||
}
|
||||
public function getPdfClass(){
|
||||
switch (Registry::getRequest()->getRequestParameter('pdftype')) {
|
||||
case ('dnote'):
|
||||
case ('dnote_without_logo'):
|
||||
$pdfInstance= oxNew(deliverynotePdf::class);
|
||||
$pdfInstance->setOrder($this);
|
||||
return $pdfInstance;
|
||||
case ('standart'):
|
||||
case('standart_without_logo'):
|
||||
$pdfInvoice= oxNew(invoicePdf::class);
|
||||
$pdfInvoice->setOrder($this);
|
||||
return $pdfInvoice;
|
||||
default:
|
||||
return $this->getCustomPdfClass();
|
||||
}
|
||||
|
||||
public function getPdfClass()
|
||||
{
|
||||
switch (Registry::getRequest()->getRequestParameter('pdftype')) {
|
||||
case ('dnote'):
|
||||
case ('dnote_without_logo'):
|
||||
$pdfInstance= oxNew(deliverynotePdf::class);
|
||||
$pdfInstance->setOrder($this);
|
||||
return $pdfInstance;
|
||||
case ('standart'):
|
||||
case('standart_without_logo'):
|
||||
$pdfInvoice= oxNew(invoicePdf::class);
|
||||
$pdfInvoice->setOrder($this);
|
||||
return $pdfInvoice;
|
||||
default:
|
||||
return $this->getCustomPdfClass();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return pdfdocuments_generic
|
||||
* @return OrderPdfInterface
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException
|
||||
* @throws \oxSystemComponentException
|
||||
*/
|
||||
public function getCustomPdfClass()
|
||||
{
|
||||
$pdfInvoice= oxNew(invoicePdf::class);
|
||||
$pdfInvoice->setOrder($this);
|
||||
$pdfInvoice= oxNew(invoicePdf::class);
|
||||
$pdfInvoice->setOrder($this);
|
||||
|
||||
return $pdfInvoice;
|
||||
return $pdfInvoice;
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"oxid-esales/oxideshop-ce": "6.0 - 6.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@ -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'
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user