From 5beb8d8782b4214c5c73be971157fa8c402562ae Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 3 Aug 2022 22:53:54 +0200 Subject: [PATCH] initial --- composer.json | 2 +- .../d3linkmobility_ordermanager_action.php | 187 ++++++++++++++++++ .../de/d3_linkmobility_ordermanager_lang.php | 49 +++++ .../d3linkmobility_ordermanager_action.tpl | 67 +++++++ src/IntelliSenseHelper.php | 21 ++ .../d3ordermanager_conf_linkmobility.php | 56 ++++++ src/metadata.php | 92 +-------- 7 files changed, 388 insertions(+), 86 deletions(-) create mode 100644 src/Application/Model/d3linkmobility_ordermanager_action.php create mode 100644 src/Application/views/admin/de/d3_linkmobility_ordermanager_lang.php create mode 100644 src/Application/views/admin/tpl/d3linkmobility_ordermanager_action.tpl create mode 100644 src/IntelliSenseHelper.php create mode 100644 src/Modules/Ordermanager/Application/Model/d3ordermanager_conf_linkmobility.php diff --git a/composer.json b/composer.json index bf085f1..27ef969 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "extra": { "oxideshop": { "source-directory": "/src", - "target-directory": "d3/extsearch" + "target-directory": "d3/linkmobility4ordermanager" } }, "require": { diff --git a/src/Application/Model/d3linkmobility_ordermanager_action.php b/src/Application/Model/d3linkmobility_ordermanager_action.php new file mode 100644 index 0000000..0f5e58b --- /dev/null +++ b/src/Application/Model/d3linkmobility_ordermanager_action.php @@ -0,0 +1,187 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\Linkmobility4Ordermanager\Application\Model; + +use D3\Ordermanager\Application\Model\Actions\d3ordermanager_action_abstract; +use D3\Ordermanager\Application\Model\d3ordermanager_conf; +use Doctrine\DBAL\DBALException; +use OxidEsales\Eshop\Application\Model\Content; +use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; +use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; + +class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract +{ + public $sTplName = 'd3linkmobility_ordermanager_action.tpl'; + CONST ACTIVE_SWITCH = 'blActionLinkmobility_status'; + public $sTitleIdent = 'D3_LINKMOBILITY_ORDERMANAGER_ACTION'; + + CONST SOURCE_TEMPLATE = 'template'; + CONST SOURCE_CMS = 'cms'; + + /** + * @return array + */ + public final function isAllowedInEditions(): array + { + return [ + d3ordermanager_conf::SERIAL_BIT_FREE_EDITION, + d3ordermanager_conf::SERIAL_BIT_STANDARD_EDITION, + d3ordermanager_conf::SERIAL_BIT_PREMIUM_EDITION + ]; + } + + /** + * @return string + */ + public function getUnvalidConfigurationMessageIdent() : string + { + if ($this->hasRequiredValuesNoSource(false)) { + return 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDSOURCE'; + } elseif ($this->hasRequiredValuesTplSource(false)) { + return 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDTPL'; + } else { + return 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDCMS'; + } + } + + /** + * @throws DBALException + * @throws DatabaseConnectionException + * @throws DatabaseErrorException + * @throws StandardException + * @throws d3ShopCompatibilityAdapterException + * @throws d3_cfg_mod_exception + */ + public function startAction() + { + if (false == $this->isExecutable()) { + return; + } + + $this->throwUnvalidConfigurationException(); + + startProfile(__METHOD__); + + /** @var Language $oLang */ + $oLang = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Language::class); + + $this->getManager()->getRemarkHandler()->addNote( + sprintf( + $oLang->translateString('D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE', null, true), + $this->getRecipientDescription() + ) + ); + + $this->startExecution(); + + stopProfile(__METHOD__); + } + + /** + * @return bool + */ + public function getRecipientDescription(): string + { + $aEditedValues = $this->getManager()->getEditedValues(); + + $aMailDesc = []; + $aEditedValues ? + ($aEditedValues['blSendMailToCustomer'] ? $aMailDesc[] = 'Customer' : '') : + ($this->getManager()->getValue('blSendMailToCustomer') ? $aMailDesc[] = 'Customer' : ''); + $aEditedValues ? + ($aEditedValues['blSendMailToOwner'] ? $aMailDesc[] = 'Owner' : '') : + ($this->getManager()->getValue('blSendMailToOwner') ? $aMailDesc[] = 'Owner' : ''); + $aEditedValues ? + ($aEditedValues['blSendMailToCustom'] ? $aMailDesc[] = 'Custom: ' . $aEditedValues['sSendMailToCustomAddress'] : '') : + ($this->getManager()->getValue('blSendMailToCustom') ? + $aMailDesc[] = 'Custom: ' . $this->getManager()->getValue('sSendMailToCustomAddress') : + '' + ); + } + + return implode(', ', $aMailDesc); + } + + /** + * @param bool $blExpected + * + * @return bool + */ + protected function hasRequiredValuesTplSource(bool $blExpected): bool + { + $source = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromSource' ); + + if (trim($source) !== self::SOURCE_TEMPLATE) { + return false; + } + + $template = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromTemplatename' ); + $theme = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromTheme' ); + + if ($blExpected === true) { + return (bool) strlen( trim( $template ) ) === true && + (bool) strlen( trim( $theme ) ) === true; + } else { + return (bool) strlen( trim( $template ) ) === false || + (bool) strlen( trim( $theme ) ) === false; + } + } + + /** + * @param bool $blExpected + * + * @return bool + */ + protected function hasRequiredValuesCmsSource(bool $blExpected): bool + { + $source = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromSource' ); + + if (trim($source) !== self::SOURCE_CMS) { + return false; + } + + /** @var Content $content */ + $content = oxNew(Content::class); + $contentname = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromContentname' ); + + if ($blExpected === true) { + return (bool) strlen( trim( $contentname ) ) === true && + $content->exists(trim( $contentname )) === true; + } else { + return (bool) strlen( trim( $contentname ) ) === false || + $content->exists(trim( $contentname )) === false; + } + } + + /** + * @return bool + * @throws DBALException + * @throws DatabaseConnectionException + * @throws DatabaseErrorException + */ + public function canExecuteMethod(): bool + { + return $this->getManager()->getExecMode(); + } + + /** + * @return string + */ + public function getActiveSwitchParameter() : string + { + return self::ACTIVE_SWITCH; + } +} \ No newline at end of file diff --git a/src/Application/views/admin/de/d3_linkmobility_ordermanager_lang.php b/src/Application/views/admin/de/d3_linkmobility_ordermanager_lang.php new file mode 100644 index 0000000..df72e5c --- /dev/null +++ b/src/Application/views/admin/de/d3_linkmobility_ordermanager_lang.php @@ -0,0 +1,49 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +// @codeCoverageIgnoreStart + +$sLangName = 'Deutsch'; + +$aLang = array( + 'charset' => 'UTF-8', + + 'D3_LINKMOBILITY_ORDERMANAGER_ACTION' => 'Mobile Messages (über LINK Mobility) senden', + + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ToUseLMSettings' => 'Der Nachrichtenempfänger wird aus den Kundendaten an den Bestellungen ermittelt.', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ToUseLMSettings_DESC' => 'Welche Daten der Bestellung hierfür verwendet werden, setzen Sie in den Einstellungen des LINK Mobility Moduls unter "Erweiterungen -> Module -> Einstell.".', + + 'D3_ORDERMANAGER_ACTION_MAILSEND' => 'E-Mail senden', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROM1' => '', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMSUBJECT' => 'Betreff-Template', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMCMS_SUBJECT' => 'Der CMS-Titel ist gleichzeitig der Mail-Betreff.', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTEMPLATE' => 'aus Templatedatei', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTEMPLATE_SOURCE'=> 'Template-Datei', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTPL_ADMIN' => 'aus Admin-Templateverzeichnis', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTPL_FRONTEND' => 'aus Frontent-Templateverzeichnis', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTPL_MODULE' => 'aus Modul-Verzeichnis', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTPL_DESC' => 'Neben den Templates werden auch die Sprachbausteine je nach Einstellung immer aus dem Admin- bzw. Frontend-Bereich übersetzt. Übertragen Sie daher ggf. die Einträge manuell. Laden Sie ein Template aus einem Modulverzeichnis, werden generell die Frontend-Sprachbausteine verwendet.', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTEMPLATE_DESC' => 'Geben Sie den vollständigen Templatenamen (inkl. Ordner ab tpl-Ordner und Dateiendung) an', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMCMS' => 'aus Kundeninformation', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMCMS_SOURCE' => 'CMS-Eintrag', + + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDSOURCE' => 'keine gültige Inhaltsquelle gesetzt', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDTPL' => 'keine gültigen Templatedaten gesetzt', + 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDCMS' => 'kein gültiger CMS-Eintrag gesetzt', + + 'D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE' => 'sende LinkMobility Nachricht an %s', +); + +// @codeCoverageIgnoreEnd diff --git a/src/Application/views/admin/tpl/d3linkmobility_ordermanager_action.tpl b/src/Application/views/admin/tpl/d3linkmobility_ordermanager_action.tpl new file mode 100644 index 0000000..2bd714e --- /dev/null +++ b/src/Application/views/admin/tpl/d3linkmobility_ordermanager_action.tpl @@ -0,0 +1,67 @@ +[{block name="ordermanager_admin_action_linkmobilitymessage"}] +
+ [{include file="d3ordermanager_activeswitch.tpl" oActionRequ=$oAction blActionRestriction=$blActionRestriction readonly=$readonly}] +
+ [{if $oView->isEditMode()}] + [{block name="ordermanager_admin_action_linkmobilitymessage_editor"}] + [{oxmultilang ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROM1"}]
+ getValue('sLinkMobilityMessageFromSource') == 'template'}]checked[{/if}] [{$blActionRestriction}] [{$readonly}]> + +
+ [{oxinputhelp ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTEMPLATE_DESC"}]
+ getValue('sLinkMobilityMessageFromTheme') == 'admin'}]checked[{/if}] [{$blActionRestriction}] [{$readonly}]>
+ getValue('sLinkMobilityMessageFromTheme') == 'frontend'}]checked[{/if}] [{$blActionRestriction}] [{$readonly}]>
+ getValue('sLinkMobilityMessageFromTheme') == 'module'}]checked[{/if}] [{$blActionRestriction}] [{$readonly}]> + + + [{oxinputhelp ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTPL_DESC"}]
+
+ getValue('sLinkMobilityMessageFromSource') == 'cms'}]checked[{/if}] [{$blActionRestriction}] [{$readonly}]> +
+ +
+ +
+ [{oxmultilang ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ToUseLMSettings"}] [{oxinputhelp ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ToUseLMSettings_DESC"}]
+ [{/block}] + [{else}] + [{block name="ordermanager_admin_action_sendmail_viewer"}] + [{oxmultilang ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROM1"}]
+ [{if $edit->getValue('sLinkMobilityMessageFromSource') == 'template'}] + [{oxmultilang ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTEMPLATE"}] +
+ [{oxmultilang ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTEMPLATE_SOURCE"}] [{$edit->getValue('sLinkMobilityMessageFromTemplatename')}] [{oxinputhelp ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTEMPLATE_DESC"}]
+ [{if $edit->getValue('sLinkMobilityMessageFromTheme') == 'admin'}] + [{oxmultilang ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTPL_ADMIN"}] ([{$oView->getManagerTemplateDirs(1)}]) + [{elseif $edit->getValue('sLinkMobilityMessageFromTheme') == 'frontend'}] + [{oxmultilang ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTPL_FRONTEND"}] ([{$oView->getManagerTemplateDirs(0)}]) + [{elseif $edit->getValue('sLinkMobilityMessageFromTheme') == 'module'}] + [{oxmultilang ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTPL_MODULE"}] [{$edit->getValue('sLinkMobilityMessageFromModulePath')}] [{oxinputhelp ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTPL_DESC"}] + [{/if}] + [{elseif $edit->getValue('sLinkMobilityMessageFromSource') == 'cms'}] + [{oxmultilang ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMCMS"}] +
+ [{oxmultilang ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMCMS_SOURCE"}] + [{foreach from=$oView->getContentList() item="oContent"}] + [{if $edit->getValue('sLinkMobilityMessageFromContentname') == $oContent->getId()}] + [{$oContent->getFieldData('oxtitle')}] ([{$oContent->getFieldData('oxloadid')}]) + [{/if}] + [{/foreach}] + [{/if}] +
+ [{oxmultilang ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ToUseLMSettings"}] [{oxinputhelp ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ToUseLMSettings_DESC"}]
+ [{/block}] + [{/if}] + [{oxinputhelp ident="D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_DESC"}] +
+
+
+[{/block}] \ No newline at end of file diff --git a/src/IntelliSenseHelper.php b/src/IntelliSenseHelper.php new file mode 100644 index 0000000..a826637 --- /dev/null +++ b/src/IntelliSenseHelper.php @@ -0,0 +1,21 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\Linkmobility4Ordermanager\Modules\Ordermanager\Application\Model +{ + use D3\Ordermanager\Application\Model\d3ordermanager_conf; + + class d3ordermanager_conf_linkmobility_parent extends d3ordermanager_conf {} +} \ No newline at end of file diff --git a/src/Modules/Ordermanager/Application/Model/d3ordermanager_conf_linkmobility.php b/src/Modules/Ordermanager/Application/Model/d3ordermanager_conf_linkmobility.php new file mode 100644 index 0000000..218f51b --- /dev/null +++ b/src/Modules/Ordermanager/Application/Model/d3ordermanager_conf_linkmobility.php @@ -0,0 +1,56 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\Linkmobility4Ordermanager\Modules\Ordermanager\Application\Model; + +use D3\Linkmobility4Ordermanager\Application\Model\d3linkmobility_ordermanager_action; +use OxidEsales\Eshop\Core\Registry; +use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; +use OxidEsales\EshopCommunity\Internal\Framework\Module\State\ModuleStateServiceInterface; + +class d3ordermanager_conf_linkmobility extends d3ordermanager_conf_linkmobility_parent +{ + /** + * @param array $actionIdList + * + * @return array + */ + public function addModuleDependendActions(array $actionIdList): array + { + $actionIdList = parent::addModuleDependendActions($actionIdList); + + if ($this->hasLinkMobilityPlugin()) { + $actionIdList = $this->addModuleDependendItem( + $actionIdList, + 'D3_ORDERMANAGER_ACTION_INFO', + 'linkmobility', + d3linkmobility_ordermanager_action::class + ); + } + + return $actionIdList; + } + + /** + * @return bool + */ + protected function hasLinkMobilityPlugin(): bool + { + $container = ContainerFactory::getInstance()->getContainer(); + $moduleStateService = $container->get(ModuleStateServiceInterface::class); + + return $moduleStateService->isActive('d3linkmobility', Registry::getConfig()->getShopId()); + } +} \ No newline at end of file diff --git a/src/metadata.php b/src/metadata.php index cffddda..7e3ba67 100644 --- a/src/metadata.php +++ b/src/metadata.php @@ -13,12 +13,8 @@ declare(strict_types=1); -use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder; -use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser; -use D3\Linkmobility4OXID\Modules\Application\Model\OrderModel; -use D3\Linkmobility4OXID\Modules\Core\EmailCore; -use OxidEsales\Eshop\Application\Model\Order; -use OxidEsales\Eshop\Core\Email; +use D3\Linkmobility4Ordermanager\Modules\Ordermanager\Application\Model\d3ordermanager_conf_linkmobility; +use D3\Ordermanager\Application\Model\d3ordermanager_conf; $sMetadataVersion = '2.1'; $sModuleId = 'd3linkmobility4ordermanager'; @@ -40,87 +36,13 @@ $aModule = [ 'email' => 'support@shopmodule.com', 'url' => 'https://www.oxidmodule.com/', 'extend' => [ - Email::class => EmailCore::class, - Order::class => OrderModel::class - ], - 'controllers' => [ - 'd3linkmobility_user' => AdminUser::class, - 'd3linkmobility_order' => AdminOrder::class + d3ordermanager_conf::class => d3ordermanager_conf_linkmobility::class ], + 'controllers' => [], 'templates' => [ - 'd3adminuser.tpl' => 'd3/linkmobility/Application/views/admin/tpl/adminuser.tpl', - 'd3adminorder.tpl' => 'd3/linkmobility/Application/views/admin/tpl/adminuser.tpl', - 'd3sms_ordercust.tpl' => 'd3/linkmobility/Application/views/tpl/SMS/order_cust.tpl', - 'd3sms_sendednow.tpl' => 'd3/linkmobility/Application/views/tpl/SMS/sendednow.tpl', - 'd3sms_ordercanceled.tpl' => 'd3/linkmobility/Application/views/tpl/SMS/ordercanceled.tpl', + 'd3linkmobility_ordermanager_action.tpl' => 'd3/linkmobility4ordermanager/Application/views/admin/tpl/d3linkmobility_ordermanager_action.tpl' ], 'events' => [], - 'blocks' => [ - [ - 'template' => 'order_remark.tpl', - 'block' => 'admin_order_remark_type', - 'file' => 'Application/views/blocks/admin/admin_user_remark_type.tpl', - ], - [ - 'template' => 'user_remark.tpl', - 'block' => 'admin_user_remark_type', - 'file' => 'Application/views/blocks/admin/admin_user_remark_type.tpl', - ] - ], - 'settings' => [ - [ - 'group' => $sModuleId.'_general', - 'name' => $sModuleId.'_debug', - 'type' => 'bool', - 'value' => false - ], - [ - 'group' => $sModuleId.'_general', - 'name' => $sModuleId.'_apitoken', - 'type' => 'str', - 'value' => false - ], - [ - 'group' => $sModuleId.'_sms', - 'name' => $sModuleId.'_smsSenderNumber', - 'type' => 'str', - 'value' => false - ], - [ - 'group' => $sModuleId.'_sms', - 'name' => $sModuleId.'_smsSenderCountry', - 'type' => 'str', - 'value' => 'DE' - ], - [ - 'group' => $sModuleId.'_sms', - 'name' => $sModuleId.'_smsUserRecipientsFields', - 'type' => 'arr', - 'value' => [], - ], - [ - 'group' => $sModuleId.'_sms', - 'name' => $sModuleId.'_smsOrderRecipientsFields', - 'type' => 'aarr', - 'value' => [], - ], - [ - 'group' => $sModuleId.'_trigger', - 'name' => $sModuleId.'_orderActive', - 'type' => 'bool', - 'value' => false - ], - [ - 'group' => $sModuleId.'_trigger', - 'name' => $sModuleId.'_sendedNowActive', - 'type' => 'bool', - 'value' => false - ], - [ - 'group' => $sModuleId.'_trigger', - 'name' => $sModuleId.'_cancelOrderActive', - 'type' => 'bool', - 'value' => false - ] - ] + 'blocks' => [], + 'settings' => [] ];