From 3dedd7dee85da1effecddf57b8721a3eba1fa4ee Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Tue, 27 Jul 2021 15:10:11 +0200 Subject: [PATCH] move tasks from Data Wizard core --- .../Model/Actions/FixArtextendsItems.php | 87 +++++++++++++++++ .../Model/Exports/InactiveCategories.php | 75 +++++++++++++++ Application/Model/Exports/KeyFigures.php | 96 +++++++++++++++++++ .../views/admin/de/d3DataWizard_lang.php | 38 ++++++++ .../views/admin/en/d3DataWizard_lang.php | 38 ++++++++ CHANGELOG.md | 5 + IntelliSenseHelper.php | 19 ++++ .../Application/Model/Configuration.php | 32 +++++++ README.en.md | 30 ++++++ README.md | 30 ++++++ metadata.php | 8 +- 11 files changed, 457 insertions(+), 1 deletion(-) create mode 100644 Application/Model/Actions/FixArtextendsItems.php create mode 100644 Application/Model/Exports/InactiveCategories.php create mode 100644 Application/Model/Exports/KeyFigures.php create mode 100644 Application/views/admin/de/d3DataWizard_lang.php create mode 100644 Application/views/admin/en/d3DataWizard_lang.php create mode 100644 CHANGELOG.md create mode 100644 IntelliSenseHelper.php create mode 100644 Modules/DataWizard/Application/Model/Configuration.php create mode 100644 README.en.md create mode 100644 README.md diff --git a/Application/Model/Actions/FixArtextendsItems.php b/Application/Model/Actions/FixArtextendsItems.php new file mode 100644 index 0000000..2aebf9f --- /dev/null +++ b/Application/Model/Actions/FixArtextendsItems.php @@ -0,0 +1,87 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\DataWizardTasks\Application\Model\Actions; + +use D3\DataWizard\Application\Model\ActionBase; +use OxidEsales\Eshop\Core\Model\BaseModel; +use OxidEsales\Eshop\Core\Model\MultiLanguageModel; +use OxidEsales\Eshop\Core\Registry; + +class FixArtextendsItems extends ActionBase +{ + /** + * fehlende oxartextends-Einträge nachtragen + */ + + /** + * @return string + */ + public function getTitle() : string + { + return Registry::getLang()->translateString('D3_DATAWIZARDTASKS_ACTIONS_FIXARTEXTENDSITEMS'); + } + + /** + * @return array + */ + public function getQuery() : array + { + $aDefaultValueFields = array( + 'oxtimestamp' => "''", + ); + + $aNonArtExtendsFields = array( + 'oxid' => 'oxarticles.oxid', + ); + + $aArtExtendsFields = array_fill_keys($this->getArtExtendsFields(), "''"); + $aMergedFields = array_merge($aNonArtExtendsFields, $aArtExtendsFields); + $aQueryFields = array_diff_key($aMergedFields, $aDefaultValueFields); + + $sArtExtendsFields = implode(', ', array_keys($aQueryFields)); + + $select = "SELECT ".implode(', ', $aQueryFields). + " FROM oxarticles". + " LEFT JOIN oxartextends AS arx ON oxarticles.oxid = arx.oxid". + " WHERE arx.oxid IS NULL"; + + $query = "INSERT INTO oxartextends ($sArtExtendsFields) ". + $select; + + return [$query, []]; + } + + /** + * @return array + */ + public function getArtExtendsFields(): array + { + /** @var $oArtExtends MultiLanguageModel */ + $oArtExtends = oxNew(BaseModel::class); + $oArtExtends->init('oxartextends', false); + + $aFieldNames = $oArtExtends->getFieldNames(); + + if (false == $aFieldNames) { + $oArtExtends->disableLazyLoading(); + $aFieldNames = $oArtExtends->getFieldNames(); + } + + unset($aFieldNames[array_search('oxid', $aFieldNames)]); + + return $aFieldNames; + } +} \ No newline at end of file diff --git a/Application/Model/Exports/InactiveCategories.php b/Application/Model/Exports/InactiveCategories.php new file mode 100644 index 0000000..34e4a73 --- /dev/null +++ b/Application/Model/Exports/InactiveCategories.php @@ -0,0 +1,75 @@ + + * @link https://www.oxidmodule.com + */ + +namespace D3\DataWizardTasks\Application\Model\Exports; + +use D3\DataWizard\Application\Model\ExportBase; +use OxidEsales\Eshop\Application\Model\Article; +use OxidEsales\Eshop\Application\Model\Category; +use OxidEsales\Eshop\Application\Model\Object2Category; +use OxidEsales\Eshop\Core\Registry; + +class InactiveCategories extends ExportBase +{ + /** + * Kategorien -deaktiviert, mit aktiven Artikeln + */ + + /** + * @return string + */ + public function getTitle() : string + { + return Registry::getLang()->translateString('D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES'); + } + + /** + * @return array + */ + public function getQuery() : array + { + $categoryTableName = oxNew(Category::class)->getCoreTableName(); + $object2categoryTableName = oxNew(Object2Category::class)->getCoreTableName(); + $articleTableName = oxNew(Article::class)->getCoreTableName(); + + $treeTitle = Registry::getLang()->translateString('D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES_TREE'); + $titleTitle = Registry::getLang()->translateString('D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES_TITLE'); + $countTitle = Registry::getLang()->translateString('D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES_COUNT'); + + return [ + "SELECT + oc.OXID, + oc.OXSHOPID, + oc.oxtitle as :titleTitle, + ( + SELECT GROUP_CONCAT(oxtitle ORDER BY oxleft ASC SEPARATOR ' > ') + from ".$categoryTableName." + WHERE OXLEFT < oc.oxleft AND OXRIGHT > oc.oxright AND OXROOTID = oc.OXROOTID AND OXSHOPID = oc.OXSHOPID + ) as :treeTitle, + COUNT(oa.oxid) as :countTitle + FROM ".$categoryTableName." oc + LEFT JOIN ".$object2categoryTableName." o2c ON oc.OXID = o2c.OXCATNID + LEFT JOIN ".$articleTableName." oa ON o2c.OXOBJECTID = oa.OXID + WHERE oc.OXACTIVE = :categoryActive AND oa.OXACTIVE = :articleActive + GROUP BY oc.oxid + ORDER BY oc.oxleft ASC", + [ + 'categoryActive' => 0, + 'articleActive' => 1, + 'titleTitle' => $titleTitle, + 'treeTitle' => $treeTitle, + 'countTitle' => $countTitle + ] + ]; + } +} \ No newline at end of file diff --git a/Application/Model/Exports/KeyFigures.php b/Application/Model/Exports/KeyFigures.php new file mode 100644 index 0000000..d1010d4 --- /dev/null +++ b/Application/Model/Exports/KeyFigures.php @@ -0,0 +1,96 @@ + + * @link https://www.oxidmodule.com + */ + +namespace D3\DataWizardTasks\Application\Model\Exports; + +use D3\DataWizard\Application\Model\ExportBase; +use FormManager\Inputs\Date; +use OxidEsales\Eshop\Application\Model\Order; +use OxidEsales\Eshop\Core\Registry; +use FormManager\Factory as FormFactory; + +class KeyFigures extends ExportBase +{ + const STARTDATE_NAME = 'startdate'; + const ENDDATE_NAME = 'enddate'; + + /** + * Shopkennzahlen + */ + + public function __construct() + { + /** @var Date $startDate */ + $startDateValue = Registry::getRequest()->getRequestEscapedParameter(self::STARTDATE_NAME); + $startDate = FormFactory::date( + Registry::getLang()->translateString('D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_FIELD_STARTDATE'), + [ + 'name' => self::STARTDATE_NAME, + 'value' => $startDateValue + ] + ); + $this->registerFormElement($startDate); + + /** @var Date $endDate */ + $endDateValue = Registry::getRequest()->getRequestEscapedParameter(self::ENDDATE_NAME); + $endDate = FormFactory::date( + Registry::getLang()->translateString('D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_FIELD_ENDDATE'), + [ + 'name' => self::ENDDATE_NAME, + 'value' => $endDateValue + ] + ); + $this->registerFormElement($endDate); + } + + /** + * @return string + */ + public function getTitle() : string + { + return Registry::getLang()->translateString('D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES'); + } + + /** + * @return array + */ + public function getQuery() : array + { + $orderTable = oxNew(Order::class)->getCoreTableName(); + $ordersTitle = Registry::getLang()->translateString('D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_ORDERSPERMONTH'); + $basketsTitle = Registry::getLang()->translateString('D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_BASKETSIZE'); + $monthTitle = Registry::getLang()->translateString('D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_MONTH'); + + $startDateValue = Registry::getRequest()->getRequestEscapedParameter(self::STARTDATE_NAME) ?: '1970-01-01'; + $endDateValue = Registry::getRequest()->getRequestEscapedParameter(self::ENDDATE_NAME) ?: date('Y-m-d'); + + return [ + 'SELECT + DATE_FORMAT(oo.oxorderdate, "%Y-%m") as :monthTitle, + FORMAT(COUNT(oo.oxid), 0) AS :ordersTitle, + FORMAT(SUM(oo.OXTOTALBRUTSUM / oo.oxcurrate) / COUNT(oo.oxid), 2) as :basketsTitle + FROM '.$orderTable.' AS oo + WHERE oo.oxorderdate >= :startDate AND oo.oxorderdate <= :endDate + GROUP BY DATE_FORMAT(oo.oxorderdate, "%Y-%m") + ORDER BY DATE_FORMAT(oo.oxorderdate, "%Y-%m") DESC + LIMIT 30', + [ + 'startDate' => $startDateValue, + 'endDate' => $endDateValue, + 'monthTitle' => $monthTitle, + 'ordersTitle' => $ordersTitle, + 'basketsTitle' => $basketsTitle + ] + ]; + } +} \ No newline at end of file diff --git a/Application/views/admin/de/d3DataWizard_lang.php b/Application/views/admin/de/d3DataWizard_lang.php new file mode 100644 index 0000000..94ab331 --- /dev/null +++ b/Application/views/admin/de/d3DataWizard_lang.php @@ -0,0 +1,38 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +$sLangName = "Deutsch"; +// ------------------------------- +// RESOURCE IDENTITFIER = STRING +// ------------------------------- +$aLang = array( + +//Navigation + 'charset' => 'UTF-8', + + 'D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES' => 'deaktivierte Kategorien, mit aktiven Artikeln', + 'D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES_TREE' => 'Baum', + 'D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES_TITLE' => 'Titel', + 'D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES_COUNT' => 'Anzahl', + + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES' => 'Bestellungskennzahlen nach Monat', + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_FIELD_STARTDATE'=> 'Startdatum (optional)', + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_FIELD_ENDDATE' => 'Enddatum (optional)', + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_ORDERSPERMONTH' => 'Bestellungen pro Monat', + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_BASKETSIZE' => 'Warenkorbhöhe', + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_MONTH' => 'Monat', + + 'D3_DATAWIZARDTASKS_ACTIONS_FIXARTEXTENDSITEMS' => 'fehlende oxartextends-Einträge nachtragen', +); diff --git a/Application/views/admin/en/d3DataWizard_lang.php b/Application/views/admin/en/d3DataWizard_lang.php new file mode 100644 index 0000000..e110b82 --- /dev/null +++ b/Application/views/admin/en/d3DataWizard_lang.php @@ -0,0 +1,38 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +$sLangName = "English"; +// ------------------------------- +// RESOURCE IDENTITFIER = STRING +// ------------------------------- +$aLang = array( + +//Navigation + 'charset' => 'UTF-8', + + 'D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES' => 'deactivated categories, with active articles', + 'D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES_TREE' => 'tree', + 'D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES_TITLE' => 'title', + 'D3_DATAWIZARDTASKS_EXPORTS_INACTIVECATEGORIES_COUNT' => 'count', + + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES' => 'Order key figures by month', + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_FIELD_STARTDATE'=> 'start date (optional)', + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_FIELD_ENDDATE' => 'end date (optional)', + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_ORDERSPERMONTH' => 'orders per month', + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_BASKETSIZE' => 'shopping cart value', + 'D3_DATAWIZARDTASKS_EXPORTS_KEYFIGURES_MONTH' => 'month', + + 'D3_DATAWIZARDTASKS_ACTIONS_FIXARTEXTENDSITEMS' => 'add missing oxartextends entries', +); diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..4dc2c43 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 1.0.0.0 (2021-07-27) + +- extract tasks (exports and action) from DataWizard Core \ No newline at end of file diff --git a/IntelliSenseHelper.php b/IntelliSenseHelper.php new file mode 100644 index 0000000..ce343dd --- /dev/null +++ b/IntelliSenseHelper.php @@ -0,0 +1,19 @@ + + * @link https://www.oxidmodule.com + */ + +namespace D3\DataWizardTasks\Modules\DataWizard\Application\Model { + + use D3\DataWizard\Application\Model\Configuration; + + class Configuration_parent extends Configuration{} +} \ No newline at end of file diff --git a/Modules/DataWizard/Application/Model/Configuration.php b/Modules/DataWizard/Application/Model/Configuration.php new file mode 100644 index 0000000..34d8883 --- /dev/null +++ b/Modules/DataWizard/Application/Model/Configuration.php @@ -0,0 +1,32 @@ + + * @link https://www.oxidmodule.com + */ + +namespace D3\DataWizardTasks\Modules\DataWizard\Application\Model; + +use D3\DataWizard\Application\Model\Configuration as ConfigurationParent; +use D3\DataWizardTasks\Application\Model\Actions\FixArtextendsItems; +use D3\DataWizardTasks\Application\Model\Exports\InactiveCategories; +use D3\DataWizardTasks\Application\Model\Exports\KeyFigures; + +class Configuration extends Configuration_parent +{ + public function configure() + { + parent::configure(); + + $this->registerAction( ConfigurationParent::GROUP_ARTICLES, oxNew( FixArtextendsItems::class)); + + $this->registerExport( ConfigurationParent::GROUP_CATEGORY, oxNew( InactiveCategories::class)); + $this->registerExport( ConfigurationParent::GROUP_SHOP, oxNew( KeyFigures::class)); + } +} \ No newline at end of file diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..e0247f7 --- /dev/null +++ b/README.en.md @@ -0,0 +1,30 @@ +> [deutsche Version](README.md) + +# D³ Data Wizard Tasks for OXID eShop + +This module contains useful sample tasks for the D3 `DataWizard` in the OXID eShop. + +## Installation + +In the console in the shop root (above source and vendor), execute the following command: + +```bash +php composer require d3/datawizardtasks +``` + +Activate the module in the admin area of the shop in "Extensions -> Modules". + +## Changelog + +See [CHANGELOG](CHANGELOG.md) for further informations. + +## Licence of this software (d3/datawizardtasks) +(status: 2021-07-27) + +``` +Copyright (c) D3 Data Development (Inh. Thomas Dartsch) + +This software is distributed under the GNU GENERAL PUBLIC LICENSE version 3. +``` + +For full copyright and licensing information, please see the [LICENSE](LICENSE.md) file distributed with this source code. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3ca567 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +> [english version](README.en.md) + +# D³ Data Wizard Aufgaben für OXID eShop + +Dieses Modul enthält nützliche Beispielaufgaben für den D3 `DataWizard` im OXID eShop. + +## Schnellinstallation + +Auf der Konsole im Shoproot (oberhalb von source und vendor) folgenden Befehl ausführen: + +```bash +php composer require d3/datawizardtasks +``` + +Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module". + +## Changelog + +Siehe [CHANGELOG](CHANGELOG.md) für weitere Informationen. + +## Lizenz dieser Software (d3/datawizardtasks) +(Stand: 27.07.2021) + +``` +Copyright (c) D3 Data Development (Inh. Thomas Dartsch) + +Diese Software wird unter der GNU GENERAL PUBLIC LICENSE Version 3 vertrieben. +``` + +Die vollständigen Copyright- und Lizenzinformationen entnehmen Sie bitte der [LICENSE](LICENSE.md)-Datei, die mit diesem Quellcode verteilt wurde. diff --git a/metadata.php b/metadata.php index 373521c..eb55d90 100644 --- a/metadata.php +++ b/metadata.php @@ -16,6 +16,10 @@ declare(strict_types=1); /** * Metadata version */ + +use D3\DataWizard\Application\Model\Configuration as ConfigurationParent; +use D3\DataWizardTasks\Modules\DataWizard\Application\Model\Configuration; + $sMetadataVersion = '2.1'; $sModuleId = 'd3datawizardtasks'; @@ -40,7 +44,9 @@ $aModule = [ 'email' => 'support@shopmodule.com', 'url' => 'https://www.oxidmodule.com/', 'controllers' => [], - 'extend' => [], + 'extend' => [ + ConfigurationParent::class => Configuration::class + ], 'events' => [], 'templates' => [], 'settings' => [],