diff --git a/Application/Model/AbstractClasses/pdfDocuments_generic.php b/Application/Model/AbstractClasses/pdfDocuments_generic.php index 3b09a93..fb1ab7e 100644 --- a/Application/Model/AbstractClasses/pdfDocuments_generic.php +++ b/Application/Model/AbstractClasses/pdfDocuments_generic.php @@ -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']; + } } \ No newline at end of file diff --git a/Application/Model/AbstractClasses/pdfDocuments_order.php b/Application/Model/AbstractClasses/pdfDocuments_order.php index 17cf9ab..7e4f89e 100644 --- a/Application/Model/AbstractClasses/pdfDocuments_order.php +++ b/Application/Model/AbstractClasses/pdfDocuments_order.php @@ -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); + } } \ No newline at end of file diff --git a/Application/Model/Documents/deliverynotePdf.php b/Application/Model/Documents/deliverynotePdf.php index bbe15f4..08b2e29 100644 --- a/Application/Model/Documents/deliverynotePdf.php +++ b/Application/Model/Documents/deliverynotePdf.php @@ -1,9 +1,27 @@ + * @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'; + } } \ No newline at end of file diff --git a/Application/Model/Documents/invoicePdf.php b/Application/Model/Documents/invoicePdf.php index 72ba075..d7e019b 100644 --- a/Application/Model/Documents/invoicePdf.php +++ b/Application/Model/Documents/invoicePdf.php @@ -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; diff --git a/Application/Model/Interfaces/pdfdocuments_generic.php b/Application/Model/Interfaces/pdfdocuments_generic.php index d636533..607aa77 100644 --- a/Application/Model/Interfaces/pdfdocuments_generic.php +++ b/Application/Model/Interfaces/pdfdocuments_generic.php @@ -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'); } \ No newline at end of file diff --git a/Application/Model/Interfaces/pdfdocuments_order.php b/Application/Model/Interfaces/pdfdocuments_order.php index 690061d..4a562a2 100644 --- a/Application/Model/Interfaces/pdfdocuments_order.php +++ b/Application/Model/Interfaces/pdfdocuments_order.php @@ -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(); } \ No newline at end of file diff --git a/Application/Model/Interfaces/pdfdocuments_orderinvoice.php b/Application/Model/Interfaces/pdfdocuments_orderinvoice.php index 11564d4..9dcc216 100644 --- a/Application/Model/Interfaces/pdfdocuments_orderinvoice.php +++ b/Application/Model/Interfaces/pdfdocuments_orderinvoice.php @@ -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(); } \ No newline at end of file diff --git a/Modules/Application/Model/d3_Order_PdfDocuments.php b/Modules/Application/Model/d3_Order_PdfDocuments.php index bc8dfa9..9a8de66 100644 --- a/Modules/Application/Model/d3_Order_PdfDocuments.php +++ b/Modules/Application/Model/d3_Order_PdfDocuments.php @@ -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; } } diff --git a/composer.json b/composer.json index 337a22c..9923320 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ } }, "require": { + "oxid-esales/oxideshop-ce": "6.0 - 6.3" }, "autoload": { "psr-4": { diff --git a/metadata.php b/metadata.php index 37f2674..176e4d8 100644 --- a/metadata.php +++ b/metadata.php @@ -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' ],