From e1a2f8ec48ab27ec00d1d61d37b44f2db82c7d7b Mon Sep 17 00:00:00 2001 From: MaxBuhe01 Date: Sun, 27 Oct 2024 12:03:15 +0100 Subject: [PATCH] [Update] ManufacturerTab-Controller [Added] savability and display in tab --- .../Admin/ManufacturerInfoLongdesc.php | 70 +++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/Application/Controller/Admin/ManufacturerInfoLongdesc.php b/Application/Controller/Admin/ManufacturerInfoLongdesc.php index 3e6349d..5e5ad9c 100644 --- a/Application/Controller/Admin/ManufacturerInfoLongdesc.php +++ b/Application/Controller/Admin/ManufacturerInfoLongdesc.php @@ -4,18 +4,25 @@ declare(strict_types=1); namespace D3\ManufacturerInformation\Application\Controller\Admin; +use D3\ManufacturerInformation\Application\Model\Constants; +use D3\ManufacturerInformation\Modules\Application\Model\D3ManufacturerLongDesc; use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController; +use OxidEsales\Eshop\Application\Model\Manufacturer; +use OxidEsales\Eshop\Core\Registry; class ManufacturerInfoLongdesc extends AdminDetailsController { + /** + * @return string + */ public function render() { parent::render(); $this->_aViewData['edit'] = $oManufacturer = oxNew(\OxidEsales\Eshop\Application\Model\Manufacturer::class); - $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId(); - if (isset($soxId) && $soxId != "-1") { + $sOXID = $this->_aViewData["oxid"] = $this->getEditObjectId(); + if (isset($sOXID) && $sOXID != "-1") { // load object $d3manufacturerlang = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("d3manufacturerlang"); @@ -25,7 +32,7 @@ class ManufacturerInfoLongdesc extends AdminDetailsController $this->_aViewData["d3manufacturerlang"] = $d3manufacturerlang; - $oManufacturer->loadInLang($d3manufacturerlang, $soxId); + $oManufacturer->loadInLang($d3manufacturerlang, $sOXID); @@ -42,13 +49,68 @@ class ManufacturerInfoLongdesc extends AdminDetailsController } } - $this->_aViewData["editor"] = $this->generateTextEditor("100%", 280, $oManufacturer, "D3DESCRIPTION", "list.tpl.css"); + $this->_aViewData["editor"] = $this->generateTextEditor("100%", 280, $oManufacturer, "oxmanufacturers__D3DESCRIPTION", "list.tpl.css"); return "d3manufacturerlongdesc.tpl"; } + /** + * @return void + * @throws \Exception + */ public function save() { parent::save(); + + $sOXID = $this->getEditObjectId(); + $this->setEditObjectId($sOXID); + + if ($sOXID == "-1") { + return; + } + + /** @var Manufacturer|D3ManufacturerLongDesc $oManufacturer */ + $oManufacturer = oxNew(Manufacturer::class); + $oManufacturer->setLanguage($this->_iEditLang); + + if (!$oManufacturer->load($sOXID)) { + return; + } + + $aParams = Registry::getRequest()->getRequestEscapedParameter("editval"); + $oManufacturer->assign($aParams); + + // default longdesc can parsed only, if longtext #1 is selected, all other longtext selections don't contains its value + if (false === is_null($this->d3GetLongdescParamValue())) { + $oManufacturer->d3SetLongdesc($this->d3GetLongdescParamValue()); + $oManufacturer->save(); + } + } + + /** + * Returns string which must be edited by editor + * + * @param \OxidEsales\Eshop\Core\Model\BaseModel $oObject object with field will be used for editing + * @param string $sField name of editable field + * + * @return string + * @deprecated underscore prefix violates PSR12, will be renamed to "getEditValue" in next major + */ + protected function _getEditValue($oObject, $sField) // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + { + $sEditObjectValue = ''; + if ($oObject) { + $sEditObjectValue = $this->_processEditValue($oObject->getFieldData(Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME)); + } + + return $sEditObjectValue; + } + + /** + * @return string + */ + public function d3GetLongdescParamValue() :string + { + return $aParams = Registry::getRequest()->getRequestEscapedParameter("editval")['oxmanufacturers__D3DESCRIPTION']; } } \ No newline at end of file