diff --git a/Application/Controller/Admin/ManufacturerInfoLongdesc.php b/Application/Controller/Admin/ManufacturerInfoLongdesc.php index 785795c..ea9cf4f 100644 --- a/Application/Controller/Admin/ManufacturerInfoLongdesc.php +++ b/Application/Controller/Admin/ManufacturerInfoLongdesc.php @@ -1,5 +1,5 @@ _aViewData['edit'] = $oManufacturer = oxNew(\OxidEsales\Eshop\Application\Model\Manufacturer::class); - - $sOXID = $this->_aViewData["oxid"] = $this->getEditObjectId(); - if (isset($sOXID) && $sOXID != "-1") { - // load object - $d3manufacturerlang = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("catlang"); - - if (!isset($d3manufacturerlang)) { - $d3manufacturerlang = $this->_iEditLang; - } - - $this->_aViewData["catlang"] = $d3manufacturerlang; - - $oManufacturer->loadInLang($d3manufacturerlang, $sOXID); - - //Disable editing for derived items - if ($oManufacturer->isDerived()) { - $this->_aViewData['readonly'] = true; - } - - foreach (\OxidEsales\Eshop\Core\Registry::getLang()->getLanguageNames() as $id => $language) { - $oLang = new \stdClass(); - $oLang->sLangDesc = $language; - $oLang->selected = ($id == $this->_iEditLang); - $this->_aViewData["otherlang"][$id] = clone $oLang; - } - } - - $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(); - - $iManufacturerLang = intval(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("catlang")); - $sOXID = $this->getEditObjectId(); - $this->setEditObjectId($sOXID); - - if ($sOXID == "-1") { - return; - } - - /** @var Manufacturer|D3ManufacturerLongDesc $oManufacturer */ - $oManufacturer = oxNew(Manufacturer::class); - $oManufacturer->loadInLang($iManufacturerLang, $sOXID); - - if (!$oManufacturer->load($sOXID)) { - return; - } - - $aParams = Registry::getRequest()->getRequestEscapedParameter("editval"); - $oManufacturer->assign($aParams); - - 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($oManufacturer, $sField) // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore - { - $sEditObjectValue = ''; - - if ($oManufacturer and $oManufacturer->getId()) { - $sEditObjectValue = $this->_processEditValue($oManufacturer->getFieldData(Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME)); - } - - return $sEditObjectValue; - } - - /** - * @return string - */ - public function d3GetLongdescParamValue() :string - { - return (string) $aParams = Registry::getRequest()->getRequestEscapedParameter("editval")['oxmanufacturers__d3description']; - } - - /** - * inhaltliche Uebernahme analog Article_Main - * wird genutzt zum Abspeichern der Artikel-Langbeschreibung - * - * @param $sValue - * - * @return mixed - */ - protected function _processLongDesc($sValue) - { - $aSearch = [' ', '&', '"', '&lang=', '
', '
']; - $aReplace = [' ', '&', '"', '&lang=', '', '']; - - return str_replace($aSearch, $aReplace, $sValue); - } + /** + * @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") { + // load object + $d3manufacturerlang = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("catlang"); + + if (!isset($d3manufacturerlang)) { + $d3manufacturerlang = $this->_iEditLang; + } + + $this->_aViewData["catlang"] = $d3manufacturerlang; + + $oManufacturer->loadInLang($d3manufacturerlang, $sOXID); + + //Disable editing for derived items + if ($oManufacturer->isDerived()) { + $this->_aViewData['readonly'] = true; + } + + foreach (\OxidEsales\Eshop\Core\Registry::getLang()->getLanguageNames() as $id => $language) { + $oLang = new \stdClass(); + $oLang->sLangDesc = $language; + $oLang->selected = ($id == $this->_iEditLang); + $this->_aViewData["otherlang"][$id] = clone $oLang; + } + } + + $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(); + + $iManufacturerLang = intval(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("catlang")); + $sOXID = $this->getEditObjectId(); + $this->setEditObjectId($sOXID); + + if ($sOXID == "-1") { + return; + } + + /** @var Manufacturer|D3ManufacturerLongDesc $oManufacturer */ + $oManufacturer = oxNew(Manufacturer::class); + $oManufacturer->loadInLang($iManufacturerLang, $sOXID); + + if (!$oManufacturer->load($sOXID)) { + return; + } + + $aParams = Registry::getRequest()->getRequestEscapedParameter("editval"); + $oManufacturer->assign($aParams); + + 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($oManufacturer, $sField) // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + { + $sEditObjectValue = ''; + + if ($oManufacturer and $oManufacturer->getId()) { + $sEditObjectValue = $this->_processEditValue($oManufacturer->getFieldData(Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME)); + } + + return $sEditObjectValue; + } + + /** + * @return string + */ + public function d3GetLongdescParamValue() :string + { + return (string) $aParams = Registry::getRequest()->getRequestEscapedParameter("editval")['oxmanufacturers__d3description']; + } + + /** + * inhaltliche Uebernahme analog Article_Main + * wird genutzt zum Abspeichern der Artikel-Langbeschreibung + * + * @param $sValue + * + * @return mixed + */ + protected function _processLongDesc($sValue) + { + $aSearch = [' ', '&', '"', '&lang=', '
', '
']; + $aReplace = [' ', '&', '"', '&lang=', '', '']; + + return str_replace($aSearch, $aReplace, $sValue); + } } \ No newline at end of file diff --git a/Application/Model/Constants.php b/Application/Model/Constants.php index 26e85ab..32162ba 100644 --- a/Application/Model/Constants.php +++ b/Application/Model/Constants.php @@ -1,5 +1,5 @@ 'UTF-8', - + 'mxd3manufacturerinfolongdesc' => 'Langtext', 'SHOP_MODULE_GROUP_d3manufacturerinformation_main' => 'Einstellungen', 'SHOP_MODULE_d3manufacturerinformation_showManufacturertextOnDetailsPage' => 'vorhandene Herstellertexte auf Artikeldetails als Tab anzeigen' diff --git a/Application/views/admin/en/d3manufacturerinformation_lang.php b/Application/views/admin/en/d3manufacturerinformation_lang.php index 22225ce..e15933f 100644 --- a/Application/views/admin/en/d3manufacturerinformation_lang.php +++ b/Application/views/admin/en/d3manufacturerinformation_lang.php @@ -5,9 +5,9 @@ $sLangName = "Deutsch"; // RESOURCE IDENTITFIER = STRING // ------------------------------- $aLang = array( - 'charset' => 'UTF-8', - - 'mxd3manufacturerinfolongdesc' => 'Text', + 'charset' => 'UTF-8', + + 'mxd3manufacturerinfolongdesc' => 'Text', 'SHOP_MODULE_GROUP_d3manufacturerinformation_main' => 'Settings', 'SHOP_MODULE_d3manufacturerinformation_showManufacturertextOnDetailsPage' => 'display existing manufacturer texts on item details as a tab' ); \ No newline at end of file diff --git a/IntelliSenseHelper.php b/IntelliSenseHelper.php index 8e530b4..66574fa 100644 --- a/IntelliSenseHelper.php +++ b/IntelliSenseHelper.php @@ -14,8 +14,8 @@ */ namespace D3\ManufacturerInformation\Modules\Application\Model{ - - use OxidEsales\Eshop\Application\Model\Manufacturer; - - class D3ManufacturerLongDesc_parent extends Manufacturer {} + + use OxidEsales\Eshop\Application\Model\Manufacturer; + + class D3ManufacturerLongDesc_parent extends Manufacturer {} } \ No newline at end of file diff --git a/Modules/Application/Model/D3ManufacturerLongDesc.php b/Modules/Application/Model/D3ManufacturerLongDesc.php index de7beee..27056e1 100644 --- a/Modules/Application/Model/D3ManufacturerLongDesc.php +++ b/Modules/Application/Model/D3ManufacturerLongDesc.php @@ -1,5 +1,5 @@ getId() and $this->isLoaded()){ - try { - $this->assign([Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME => $sValue]); - $this->save(); - }catch (\Exception $exception){ - Registry::getLogger()->error($exception->getMessage()); - } - } - - return true; - } - - /** - * @return Field - */ - public function d3GetLongdesc(): Field - { + /** + * @param string $sValue + * @return void + */ + public function d3SetLongdesc(string $sValue) :bool + { + if ($this->getId() and $this->isLoaded()){ + try { + $this->assign([Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME => $sValue]); + $this->save(); + }catch (\Exception $exception){ + Registry::getLogger()->error($exception->getMessage()); + } + } + + return true; + } + + /** + * @return Field + */ + public function d3GetLongdesc(): Field + { $longName = $this->getCoreTableName().'__'.strtolower(Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME); - return $this->$longName; - } + return $this->$longName; + } } \ No newline at end of file diff --git a/Modules/Application/Model/ManufacturerInfoList.php b/Modules/Application/Model/ManufacturerInfoList.php index 3ed159f..1de07c1 100644 --- a/Modules/Application/Model/ManufacturerInfoList.php +++ b/Modules/Application/Model/ManufacturerInfoList.php @@ -1,5 +1,5 @@ oxcategories__oxlongdesc = new Field($oManufacturer->getFieldData(Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME), Field::T_RAW); - } + /** + * @param Manufacturer|D3ManufacturerLongDesc $oManufacturer + * @return void + */ + protected function _addCategoryFields($oManufacturer) + { + parent::_addCategoryFields($oManufacturer); + + $oManufacturer->oxcategories__oxlongdesc = new Field($oManufacturer->getFieldData(Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME), Field::T_RAW); + } } \ No newline at end of file diff --git a/metadata.php b/metadata.php index 3adc8e3..4d391f5 100644 --- a/metadata.php +++ b/metadata.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); - + use D3\ManufacturerInformation\Application\Controller\Admin\ManufacturerInfoLongdesc; use D3\ManufacturerInformation\Application\Model\Constants; use D3\ManufacturerInformation\Modules\Application\Model\D3ManufacturerLongDesc; @@ -41,14 +41,14 @@ $aModule = [ 'email' => 'support@shopmodule.com', 'url' => 'https://www.oxidmodule.com/', 'controllers' => [ - "d3manufacturerinfolongdesc" => ManufacturerInfoLongdesc::class + "d3manufacturerinfolongdesc" => ManufacturerInfoLongdesc::class ], 'extend' => [ - OEManufacturer::class => D3ManufacturerLongDesc::class, - OEManufacturerList::class => ManufacturerInfoList::class + OEManufacturer::class => D3ManufacturerLongDesc::class, + OEManufacturerList::class => ManufacturerInfoList::class ], 'templates' => [ - 'd3manufacturerlongdesc.tpl' => 'd3/manufacturerinformation/Application/views/admin/tpl/d3manufacturer_longdesc.tpl', + 'd3manufacturerlongdesc.tpl' => 'd3/manufacturerinformation/Application/views/admin/tpl/d3manufacturer_longdesc.tpl', ], 'settings' => [ [ diff --git a/migration/data/Version20241023154223.php b/migration/data/Version20241023154223.php index 18af8f6..db292e9 100644 --- a/migration/data/Version20241023154223.php +++ b/migration/data/Version20241023154223.php @@ -17,32 +17,32 @@ final class Version20241023154223 extends AbstractMigration { return 'Adds the D3 manufacturer longdesc column'; } - - public function up(Schema $schema) : void - { - $this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); - - $this->d3AddLongdescColumnToOxmanufacturers($schema); - } + + public function up(Schema $schema) : void + { + $this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); + + $this->d3AddLongdescColumnToOxmanufacturers($schema); + } public function down(Schema $schema) : void {} - - /** - * @param Schema $schema - * @return void - * @throws \Doctrine\DBAL\Schema\SchemaException - */ - public function d3AddLongdescColumnToOxmanufacturers(Schema $schema){ - $table = !$schema->hasTable('oxmanufacturers') ? - $schema->createTable('oxmanufacturers') : - $schema->getTable('oxmanufacturers'); - - // Beschreibung - if (!$table->hasColumn('D3DESCRIPTION')) { - $table->addColumn('D3DESCRIPTION', (new TextType())->getName()) - ->setLength($this->connection->getDatabasePlatform()::LENGTH_LIMIT_TEXT) - ->setNotnull(true); - } - } + + /** + * @param Schema $schema + * @return void + * @throws \Doctrine\DBAL\Schema\SchemaException + */ + public function d3AddLongdescColumnToOxmanufacturers(Schema $schema){ + $table = !$schema->hasTable('oxmanufacturers') ? + $schema->createTable('oxmanufacturers') : + $schema->getTable('oxmanufacturers'); + + // Beschreibung + if (!$table->hasColumn('D3DESCRIPTION')) { + $table->addColumn('D3DESCRIPTION', (new TextType())->getName()) + ->setLength($this->connection->getDatabasePlatform()::LENGTH_LIMIT_TEXT) + ->setNotnull(true); + } + } } diff --git a/migration/data/Version20241028172608.php b/migration/data/Version20241028172608.php index 11b7b93..be9b858 100644 --- a/migration/data/Version20241028172608.php +++ b/migration/data/Version20241028172608.php @@ -15,48 +15,48 @@ final class Version20241028172608 extends AbstractMigration { public function getDescription() : string { - return 'Adds multilang tables for the D3 manufacturer longdesc'; + return 'Adds multilang tables for the D3 manufacturer longdesc'; + } + + public function up(Schema $schema) : void + { + $this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); + + $this->d3AddLongdescMultilangColumnsToOxmanufacturers($schema); } - - public function up(Schema $schema) : void - { - $this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); - - $this->d3AddLongdescMultilangColumnsToOxmanufacturers($schema); - } public function down(Schema $schema) : void {} - - /** - * @param Schema $schema - * @return void - * @throws \Doctrine\DBAL\Schema\SchemaException - */ - public function d3AddLongdescMultilangColumnsToOxmanufacturers(Schema $schema){ - $table = !$schema->hasTable('oxmanufacturers') ? - $schema->createTable('oxmanufacturers') : - $schema->getTable('oxmanufacturers'); - - // lang 1 - if (!$table->hasColumn('D3DESCRIPTION_1')) { - $table->addColumn('D3DESCRIPTION_1', (new TextType())->getName()) - ->setLength($this->connection->getDatabasePlatform()::LENGTH_LIMIT_TEXT) - ->setNotnull(true); - } - - // lang 2 - if (!$table->hasColumn('D3DESCRIPTION_2')) { - $table->addColumn('D3DESCRIPTION_2', (new TextType())->getName()) - ->setLength($this->connection->getDatabasePlatform()::LENGTH_LIMIT_TEXT) - ->setNotnull(true); - } - - // lang 3 - if (!$table->hasColumn('D3DESCRIPTION_3')) { - $table->addColumn('D3DESCRIPTION_3', (new TextType())->getName()) - ->setLength($this->connection->getDatabasePlatform()::LENGTH_LIMIT_TEXT) - ->setNotnull(true); - } - } + + /** + * @param Schema $schema + * @return void + * @throws \Doctrine\DBAL\Schema\SchemaException + */ + public function d3AddLongdescMultilangColumnsToOxmanufacturers(Schema $schema){ + $table = !$schema->hasTable('oxmanufacturers') ? + $schema->createTable('oxmanufacturers') : + $schema->getTable('oxmanufacturers'); + + // lang 1 + if (!$table->hasColumn('D3DESCRIPTION_1')) { + $table->addColumn('D3DESCRIPTION_1', (new TextType())->getName()) + ->setLength($this->connection->getDatabasePlatform()::LENGTH_LIMIT_TEXT) + ->setNotnull(true); + } + + // lang 2 + if (!$table->hasColumn('D3DESCRIPTION_2')) { + $table->addColumn('D3DESCRIPTION_2', (new TextType())->getName()) + ->setLength($this->connection->getDatabasePlatform()::LENGTH_LIMIT_TEXT) + ->setNotnull(true); + } + + // lang 3 + if (!$table->hasColumn('D3DESCRIPTION_3')) { + $table->addColumn('D3DESCRIPTION_3', (new TextType())->getName()) + ->setLength($this->connection->getDatabasePlatform()::LENGTH_LIMIT_TEXT) + ->setNotnull(true); + } + } }